
(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}
Herbie found 8 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 (exp (- x)))
(t_2 (* (fmod (exp x) t_0) t_1)))
(if (<= t_2 2e-9)
(*
(fmod
(* (+ 1.0 (/ (/ (- 0.25 (* 0.5 0.5)) (sinh x)) (sinh x))) (sinh x))
t_0)
t_1)
(if (<= t_2 2.0)
(/ (fmod (exp x) (sqrt (sin (fma PI 0.5 x)))) (exp x))
(* (fmod 1.0 t_0) t_1)))))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = exp(-x);
double t_2 = fmod(exp(x), t_0) * t_1;
double tmp;
if (t_2 <= 2e-9) {
tmp = fmod(((1.0 + (((0.25 - (0.5 * 0.5)) / sinh(x)) / sinh(x))) * sinh(x)), t_0) * t_1;
} else if (t_2 <= 2.0) {
tmp = fmod(exp(x), sqrt(sin(fma(((double) M_PI), 0.5, x)))) / exp(x);
} else {
tmp = fmod(1.0, t_0) * t_1;
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = exp(Float64(-x)) t_2 = Float64(rem(exp(x), t_0) * t_1) tmp = 0.0 if (t_2 <= 2e-9) tmp = Float64(rem(Float64(Float64(1.0 + Float64(Float64(Float64(0.25 - Float64(0.5 * 0.5)) / sinh(x)) / sinh(x))) * sinh(x)), t_0) * t_1); elseif (t_2 <= 2.0) tmp = Float64(rem(exp(x), sqrt(sin(fma(pi, 0.5, x)))) / exp(x)); else tmp = Float64(rem(1.0, t_0) * t_1); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$2 = N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, 2e-9], N[(N[With[{TMP1 = N[(N[(1.0 + N[(N[(N[(0.25 - N[(0.5 * 0.5), $MachinePrecision]), $MachinePrecision] / N[Sinh[x], $MachinePrecision]), $MachinePrecision] / N[Sinh[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sinh[x], $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[t$95$2, 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Sin[N[(Pi * 0.5 + x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := e^{-x}\\
t_2 := \left(\left(e^{x}\right) \bmod t\_0\right) \cdot t\_1\\
\mathbf{if}\;t\_2 \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\left(\left(\left(1 + \frac{\frac{0.25 - 0.5 \cdot 0.5}{\sinh x}}{\sinh x}\right) \cdot \sinh x\right) \bmod t\_0\right) \cdot t\_1\\
\mathbf{elif}\;t\_2 \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\sin \left(\mathsf{fma}\left(\pi, 0.5, x\right)\right)}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod t\_0\right) \cdot t\_1\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2.00000000000000012e-9Initial program 9.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
+-commutativeN/A
sum-to-multN/A
lower-special-*.f64N/A
lower-special-+.f64N/A
lower-special-/.f64N/A
lower-cosh.f64N/A
lower-sinh.f64N/A
lower-sinh.f648.9
Applied rewrites8.9%
Applied rewrites63.6%
Taylor expanded in x around 0
Applied rewrites61.5%
Taylor expanded in x around 0
Applied rewrites61.4%
Taylor expanded in x around 0
Applied rewrites62.6%
if 2.00000000000000012e-9 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.0%
lift-*.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
mult-flip-revN/A
lower-/.f649.1
Applied rewrites9.1%
lift-cos.f64N/A
sin-+PI/2-revN/A
sum-to-multN/A
lift-PI.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
sum-to-multN/A
+-commutativeN/A
lift-fma.f64N/A
lift-sin.f649.1
lift-fma.f64N/A
add-flipN/A
lift-neg.f64N/A
sub-flipN/A
*-commutativeN/A
lift-neg.f64N/A
remove-double-negN/A
lower-fma.f649.1
Applied rewrites9.1%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 9.0%
Taylor expanded in x around 0
Applied rewrites34.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x)))
(t_1 (exp (- x)))
(t_2 (* (fmod (exp x) t_0) t_1)))
(if (<= t_2 1e-18)
(/
(fmod (+ (/ (fma (exp (- (- x) x)) -0.25 0.25) (sinh x)) (sinh x)) t_0)
(exp x))
(if (<= t_2 2.0)
(/ (fmod (exp x) (sqrt (sin (fma PI 0.5 x)))) (exp x))
(* (fmod 1.0 t_0) t_1)))))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = exp(-x);
double t_2 = fmod(exp(x), t_0) * t_1;
double tmp;
if (t_2 <= 1e-18) {
tmp = fmod(((fma(exp((-x - x)), -0.25, 0.25) / sinh(x)) + sinh(x)), t_0) / exp(x);
} else if (t_2 <= 2.0) {
tmp = fmod(exp(x), sqrt(sin(fma(((double) M_PI), 0.5, x)))) / exp(x);
} else {
tmp = fmod(1.0, t_0) * t_1;
}
return tmp;
}
function code(x) t_0 = sqrt(cos(x)) t_1 = exp(Float64(-x)) t_2 = Float64(rem(exp(x), t_0) * t_1) tmp = 0.0 if (t_2 <= 1e-18) tmp = Float64(rem(Float64(Float64(fma(exp(Float64(Float64(-x) - x)), -0.25, 0.25) / sinh(x)) + sinh(x)), t_0) / exp(x)); elseif (t_2 <= 2.0) tmp = Float64(rem(exp(x), sqrt(sin(fma(pi, 0.5, x)))) / exp(x)); else tmp = Float64(rem(1.0, t_0) * t_1); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$2 = N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, 1e-18], N[(N[With[{TMP1 = N[(N[(N[(N[Exp[N[((-x) - x), $MachinePrecision]], $MachinePrecision] * -0.25 + 0.25), $MachinePrecision] / N[Sinh[x], $MachinePrecision]), $MachinePrecision] + N[Sinh[x], $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2.0], N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[Sqrt[N[Sin[N[(Pi * 0.5 + x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := e^{-x}\\
t_2 := \left(\left(e^{x}\right) \bmod t\_0\right) \cdot t\_1\\
\mathbf{if}\;t\_2 \leq 10^{-18}:\\
\;\;\;\;\frac{\left(\left(\frac{\mathsf{fma}\left(e^{\left(-x\right) - x}, -0.25, 0.25\right)}{\sinh x} + \sinh x\right) \bmod t\_0\right)}{e^{x}}\\
\mathbf{elif}\;t\_2 \leq 2:\\
\;\;\;\;\frac{\left(\left(e^{x}\right) \bmod \left(\sqrt{\sin \left(\mathsf{fma}\left(\pi, 0.5, x\right)\right)}\right)\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod t\_0\right) \cdot t\_1\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 1.0000000000000001e-18Initial program 9.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
+-commutativeN/A
sum-to-multN/A
lower-special-*.f64N/A
lower-special-+.f64N/A
lower-special-/.f64N/A
lower-cosh.f64N/A
lower-sinh.f64N/A
lower-sinh.f648.9
Applied rewrites8.9%
Applied rewrites63.6%
Taylor expanded in x around 0
Applied rewrites61.5%
lift-*.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
mult-flip-revN/A
lower-/.f6461.5
Applied rewrites61.5%
if 1.0000000000000001e-18 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.0%
lift-*.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
mult-flip-revN/A
lower-/.f649.1
Applied rewrites9.1%
lift-cos.f64N/A
sin-+PI/2-revN/A
sum-to-multN/A
lift-PI.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
sum-to-multN/A
+-commutativeN/A
lift-fma.f64N/A
lift-sin.f649.1
lift-fma.f64N/A
add-flipN/A
lift-neg.f64N/A
sub-flipN/A
*-commutativeN/A
lift-neg.f64N/A
remove-double-negN/A
lower-fma.f649.1
Applied rewrites9.1%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 9.0%
Taylor expanded in x around 0
Applied rewrites34.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (cos x))) (t_1 (exp (- x))))
(if (<= (* (fmod (exp x) t_0) t_1) 2.0)
(* (fmod (/ (- (exp x)) (* (/ -1.0 (sinh x)) (sinh x))) t_0) t_1)
(* (fmod 1.0 t_0) t_1))))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = exp(-x);
double tmp;
if ((fmod(exp(x), t_0) * t_1) <= 2.0) {
tmp = fmod((-exp(x) / ((-1.0 / sinh(x)) * sinh(x))), t_0) * t_1;
} else {
tmp = fmod(1.0, t_0) * t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = sqrt(cos(x))
t_1 = exp(-x)
if ((mod(exp(x), t_0) * t_1) <= 2.0d0) then
tmp = mod((-exp(x) / (((-1.0d0) / sinh(x)) * sinh(x))), t_0) * t_1
else
tmp = mod(1.0d0, t_0) * t_1
end if
code = tmp
end function
def code(x): t_0 = math.sqrt(math.cos(x)) t_1 = math.exp(-x) tmp = 0 if (math.fmod(math.exp(x), t_0) * t_1) <= 2.0: tmp = math.fmod((-math.exp(x) / ((-1.0 / math.sinh(x)) * math.sinh(x))), t_0) * t_1 else: tmp = math.fmod(1.0, t_0) * t_1 return tmp
function code(x) t_0 = sqrt(cos(x)) t_1 = exp(Float64(-x)) tmp = 0.0 if (Float64(rem(exp(x), t_0) * t_1) <= 2.0) tmp = Float64(rem(Float64(Float64(-exp(x)) / Float64(Float64(-1.0 / sinh(x)) * sinh(x))), t_0) * t_1); else tmp = Float64(rem(1.0, t_0) * t_1); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision], 2.0], N[(N[With[{TMP1 = N[((-N[Exp[x], $MachinePrecision]) / N[(N[(-1.0 / N[Sinh[x], $MachinePrecision]), $MachinePrecision] * N[Sinh[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$1), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := e^{-x}\\
\mathbf{if}\;\left(\left(e^{x}\right) \bmod t\_0\right) \cdot t\_1 \leq 2:\\
\;\;\;\;\left(\left(\frac{-e^{x}}{\frac{-1}{\sinh x} \cdot \sinh x}\right) \bmod t\_0\right) \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod t\_0\right) \cdot t\_1\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.0%
lift-exp.f64N/A
sinh-+-cosh-revN/A
+-commutativeN/A
sum-to-multN/A
lower-special-*.f64N/A
lower-special-+.f64N/A
lower-special-/.f64N/A
lower-cosh.f64N/A
lower-sinh.f64N/A
lower-sinh.f648.9
Applied rewrites8.9%
Applied rewrites63.6%
Applied rewrites9.0%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 9.0%
Taylor expanded in x around 0
Applied rewrites34.8%
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (cos x))) (t_1 (fmod (exp x) t_0)) (t_2 (exp (- x)))) (if (<= (* t_1 t_2) 2.0) (/ t_1 (exp x)) (* (fmod 1.0 t_0) t_2))))
double code(double x) {
double t_0 = sqrt(cos(x));
double t_1 = fmod(exp(x), t_0);
double t_2 = exp(-x);
double tmp;
if ((t_1 * t_2) <= 2.0) {
tmp = t_1 / exp(x);
} else {
tmp = fmod(1.0, t_0) * t_2;
}
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) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = sqrt(cos(x))
t_1 = mod(exp(x), t_0)
t_2 = exp(-x)
if ((t_1 * t_2) <= 2.0d0) then
tmp = t_1 / exp(x)
else
tmp = mod(1.0d0, t_0) * t_2
end if
code = tmp
end function
def code(x): t_0 = math.sqrt(math.cos(x)) t_1 = math.fmod(math.exp(x), t_0) t_2 = math.exp(-x) tmp = 0 if (t_1 * t_2) <= 2.0: tmp = t_1 / math.exp(x) else: tmp = math.fmod(1.0, t_0) * t_2 return tmp
function code(x) t_0 = sqrt(cos(x)) t_1 = rem(exp(x), t_0) t_2 = exp(Float64(-x)) tmp = 0.0 if (Float64(t_1 * t_2) <= 2.0) tmp = Float64(t_1 / exp(x)); else tmp = Float64(rem(1.0, t_0) * t_2); end return tmp end
code[x_] := Block[{t$95$0 = N[Sqrt[N[Cos[x], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(t$95$1 * t$95$2), $MachinePrecision], 2.0], N[(t$95$1 / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[With[{TMP1 = 1.0, TMP2 = t$95$0}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] * t$95$2), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\cos x}\\
t_1 := \left(\left(e^{x}\right) \bmod t\_0\right)\\
t_2 := e^{-x}\\
\mathbf{if}\;t\_1 \cdot t\_2 \leq 2:\\
\;\;\;\;\frac{t\_1}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(1 \bmod t\_0\right) \cdot t\_2\\
\end{array}
\end{array}
if (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) < 2Initial program 9.0%
lift-*.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
mult-flip-revN/A
lower-/.f649.1
Applied rewrites9.1%
if 2 < (*.f64 (fmod.f64 (exp.f64 x) (sqrt.f64 (cos.f64 x))) (exp.f64 (neg.f64 x))) Initial program 9.0%
Taylor expanded in x around 0
Applied rewrites34.8%
(FPCore (x) :precision binary64 (/ (fmod (- x -1.0) (sqrt (cos x))) (exp x)))
double code(double x) {
return fmod((x - -1.0), 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((x - (-1.0d0)), sqrt(cos(x))) / exp(x)
end function
def code(x): return math.fmod((x - -1.0), math.sqrt(math.cos(x))) / math.exp(x)
function code(x) return Float64(rem(Float64(x - -1.0), sqrt(cos(x))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[(x - -1.0), $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}
\\
\frac{\left(\left(x - -1\right) \bmod \left(\sqrt{\cos x}\right)\right)}{e^{x}}
\end{array}
Initial program 9.0%
Taylor expanded in x around 0
lower-+.f6438.2
Applied rewrites38.2%
lift-*.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
mult-flip-revN/A
lower-/.f6438.2
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
metadata-evalN/A
lower--.f6438.2
Applied rewrites38.2%
(FPCore (x) :precision binary64 (/ (fmod (- x -1.0) (+ 1.0 (* -0.25 (pow x 2.0)))) (exp x)))
double code(double x) {
return fmod((x - -1.0), (1.0 + (-0.25 * pow(x, 2.0)))) / 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((x - (-1.0d0)), (1.0d0 + ((-0.25d0) * (x ** 2.0d0)))) / exp(x)
end function
def code(x): return math.fmod((x - -1.0), (1.0 + (-0.25 * math.pow(x, 2.0)))) / math.exp(x)
function code(x) return Float64(rem(Float64(x - -1.0), Float64(1.0 + Float64(-0.25 * (x ^ 2.0)))) / exp(x)) end
code[x_] := N[(N[With[{TMP1 = N[(x - -1.0), $MachinePrecision], TMP2 = N[(1.0 + N[(-0.25 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x - -1\right) \bmod \left(1 + -0.25 \cdot {x}^{2}\right)\right)}{e^{x}}
\end{array}
Initial program 9.0%
Taylor expanded in x around 0
lower-+.f6438.2
Applied rewrites38.2%
lift-*.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift-exp.f64N/A
mult-flip-revN/A
lower-/.f6438.2
lift-+.f64N/A
+-commutativeN/A
add-flipN/A
metadata-evalN/A
lower--.f6438.2
Applied rewrites38.2%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6438.2
Applied rewrites38.2%
(FPCore (x) :precision binary64 (fmod (/ 1.0 (exp (- x))) (fma (* x x) -0.25 1.0)))
double code(double x) {
return fmod((1.0 / exp(-x)), fma((x * x), -0.25, 1.0));
}
function code(x) return rem(Float64(1.0 / exp(Float64(-x))), fma(Float64(x * x), -0.25, 1.0)) end
code[x_] := N[With[{TMP1 = N[(1.0 / N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], TMP2 = N[(N[(x * x), $MachinePrecision] * -0.25 + 1.0), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(\left(\frac{1}{e^{-x}}\right) \bmod \left(\mathsf{fma}\left(x \cdot x, -0.25, 1\right)\right)\right)
\end{array}
Initial program 9.0%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f646.7
Applied rewrites6.7%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f646.7
Applied rewrites6.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lower-*.f32N/A
lower-special-*.f32N/A
lower-fma.f64N/A
lower-special-*.f646.7
Applied rewrites6.7%
*-rgt-identityN/A
metadata-evalN/A
mult-flip-revN/A
div-flipN/A
lower-special-/.f32N/A
lower-/.f32N/A
lift-exp.f64N/A
exp-negN/A
lift-neg.f64N/A
lift-exp.f64N/A
lower-special-/.f646.6
Applied rewrites6.6%
(FPCore (x) :precision binary64 (fmod (exp x) (fma (* x x) -0.25 1.0)))
double code(double x) {
return fmod(exp(x), fma((x * x), -0.25, 1.0));
}
function code(x) return rem(exp(x), fma(Float64(x * x), -0.25, 1.0)) end
code[x_] := N[With[{TMP1 = N[Exp[x], $MachinePrecision], TMP2 = N[(N[(x * x), $MachinePrecision] * -0.25 + 1.0), $MachinePrecision]}, Mod[Abs[TMP1], Abs[TMP2]] * Sign[TMP1]], $MachinePrecision]
\begin{array}{l}
\\
\left(\left(e^{x}\right) \bmod \left(\mathsf{fma}\left(x \cdot x, -0.25, 1\right)\right)\right)
\end{array}
Initial program 9.0%
Taylor expanded in x around 0
lower-fmod.f64N/A
lower-exp.f64N/A
lower-sqrt.f64N/A
lower-cos.f646.7
Applied rewrites6.7%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f646.7
Applied rewrites6.7%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lower-*.f32N/A
lower-special-*.f32N/A
lower-fma.f64N/A
lower-special-*.f646.7
Applied rewrites6.7%
herbie shell --seed 2025151
(FPCore (x)
:name "expfmod (used to be hard to sample)"
:precision binary64
(* (fmod (exp x) (sqrt (cos x))) (exp (- x))))