
(FPCore (J l K U) :precision binary64 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
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(j, l, k, u)
use fmin_fmax_functions
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U): return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U) return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U) end
function tmp = code(J, l, K, U) tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U; end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (J l K U) :precision binary64 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
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(j, l, k, u)
use fmin_fmax_functions
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U): return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U) return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U) end
function tmp = code(J, l, K, U) tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U; end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}
(FPCore (J l K U) :precision binary64 (fma (* (cos (* K -0.5)) J) (* (sinh l) 2.0) U))
double code(double J, double l, double K, double U) {
return fma((cos((K * -0.5)) * J), (sinh(l) * 2.0), U);
}
function code(J, l, K, U) return fma(Float64(cos(Float64(K * -0.5)) * J), Float64(sinh(l) * 2.0), U) end
code[J_, l_, K_, U_] := N[(N[(N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision] * J), $MachinePrecision] * N[(N[Sinh[l], $MachinePrecision] * 2.0), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos \left(K \cdot -0.5\right) \cdot J, \sinh \ell \cdot 2, U\right)
\end{array}
Initial program 86.5%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (J l K U) :precision binary64 (fma (* (+ J J) (sinh l)) (cos (* 0.5 K)) U))
double code(double J, double l, double K, double U) {
return fma(((J + J) * sinh(l)), cos((0.5 * K)), U);
}
function code(J, l, K, U) return fma(Float64(Float64(J + J) * sinh(l)), cos(Float64(0.5 * K)), U) end
code[J_, l_, K_, U_] := N[(N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(J + J\right) \cdot \sinh \ell, \cos \left(0.5 \cdot K\right), U\right)
\end{array}
Initial program 86.5%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.02) (* (+ 1.0 (/ (* (cos (* 0.5 K)) (* (+ l l) J)) U)) U) (fma (+ J J) (sinh l) U)))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.02) {
tmp = (1.0 + ((cos((0.5 * K)) * ((l + l) * J)) / U)) * U;
} else {
tmp = fma((J + J), sinh(l), U);
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.02) tmp = Float64(Float64(1.0 + Float64(Float64(cos(Float64(0.5 * K)) * Float64(Float64(l + l) * J)) / U)) * U); else tmp = fma(Float64(J + J), sinh(l), U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.02], N[(N[(1.0 + N[(N[(N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] * N[(N[(l + l), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision] * U), $MachinePrecision], N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.02:\\
\;\;\;\;\left(1 + \frac{\cos \left(0.5 \cdot K\right) \cdot \left(\left(\ell + \ell\right) \cdot J\right)}{U}\right) \cdot U\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J + J, \sinh \ell, U\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.0200000000000000004Initial program 86.5%
Taylor expanded in l around 0
lower-*.f6463.3
Applied rewrites63.3%
lift-+.f64N/A
+-commutativeN/A
sum-to-multN/A
lower-*.f64N/A
Applied rewrites67.0%
if -0.0200000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
lift-sinh.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
count-2-revN/A
lower-+.f6481.1
Applied rewrites81.1%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.02) (fma (* (cos (* 0.5 K)) (+ l l)) J U) (fma (+ J J) (sinh l) U)))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.02) {
tmp = fma((cos((0.5 * K)) * (l + l)), J, U);
} else {
tmp = fma((J + J), sinh(l), U);
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.02) tmp = fma(Float64(cos(Float64(0.5 * K)) * Float64(l + l)), J, U); else tmp = fma(Float64(J + J), sinh(l), U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.02], N[(N[(N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] * N[(l + l), $MachinePrecision]), $MachinePrecision] * J + U), $MachinePrecision], N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.02:\\
\;\;\;\;\mathsf{fma}\left(\cos \left(0.5 \cdot K\right) \cdot \left(\ell + \ell\right), J, U\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J + J, \sinh \ell, U\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.0200000000000000004Initial program 86.5%
Taylor expanded in l around 0
lower-*.f6463.3
Applied rewrites63.3%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites63.3%
if -0.0200000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
lift-sinh.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
count-2-revN/A
lower-+.f6481.1
Applied rewrites81.1%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.02) (fma (* (+ l l) J) (cos (* 0.5 K)) U) (fma (+ J J) (sinh l) U)))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.02) {
tmp = fma(((l + l) * J), cos((0.5 * K)), U);
} else {
tmp = fma((J + J), sinh(l), U);
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.02) tmp = fma(Float64(Float64(l + l) * J), cos(Float64(0.5 * K)), U); else tmp = fma(Float64(J + J), sinh(l), U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.02], N[(N[(N[(l + l), $MachinePrecision] * J), $MachinePrecision] * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] + U), $MachinePrecision], N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.02:\\
\;\;\;\;\mathsf{fma}\left(\left(\ell + \ell\right) \cdot J, \cos \left(0.5 \cdot K\right), U\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J + J, \sinh \ell, U\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.0200000000000000004Initial program 86.5%
Taylor expanded in l around 0
lower-*.f6463.3
Applied rewrites63.3%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6463.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6463.3
lift-*.f64N/A
count-2-revN/A
lower-+.f6463.3
lower-+.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower-+.f64N/A
Applied rewrites63.3%
if -0.0200000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
lift-sinh.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
count-2-revN/A
lower-+.f6481.1
Applied rewrites81.1%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.02) (fma (* (+ J J) (sinh l)) (+ 1.0 (* -0.125 (pow K 2.0))) U) (fma (+ J J) (sinh l) U)))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.02) {
tmp = fma(((J + J) * sinh(l)), (1.0 + (-0.125 * pow(K, 2.0))), U);
} else {
tmp = fma((J + J), sinh(l), U);
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.02) tmp = fma(Float64(Float64(J + J) * sinh(l)), Float64(1.0 + Float64(-0.125 * (K ^ 2.0))), U); else tmp = fma(Float64(J + J), sinh(l), U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.02], N[(N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.125 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.02:\\
\;\;\;\;\mathsf{fma}\left(\left(J + J\right) \cdot \sinh \ell, 1 + -0.125 \cdot {K}^{2}, U\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J + J, \sinh \ell, U\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.0200000000000000004Initial program 86.5%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6468.9
Applied rewrites68.9%
if -0.0200000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
lift-sinh.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
count-2-revN/A
lower-+.f6481.1
Applied rewrites81.1%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.02) (fma (+ J J) (* (sinh l) (fma (* K K) -0.125 1.0)) U) (fma (+ J J) (sinh l) U)))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.02) {
tmp = fma((J + J), (sinh(l) * fma((K * K), -0.125, 1.0)), U);
} else {
tmp = fma((J + J), sinh(l), U);
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.02) tmp = fma(Float64(J + J), Float64(sinh(l) * fma(Float64(K * K), -0.125, 1.0)), U); else tmp = fma(Float64(J + J), sinh(l), U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.02], N[(N[(J + J), $MachinePrecision] * N[(N[Sinh[l], $MachinePrecision] * N[(N[(K * K), $MachinePrecision] * -0.125 + 1.0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.02:\\
\;\;\;\;\mathsf{fma}\left(J + J, \sinh \ell \cdot \mathsf{fma}\left(K \cdot K, -0.125, 1\right), U\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J + J, \sinh \ell, U\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.0200000000000000004Initial program 86.5%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6468.9
Applied rewrites68.9%
lift-fma.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f6468.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6468.7
lift-pow.f64N/A
unpow2N/A
lower-*.f6468.7
Applied rewrites68.7%
if -0.0200000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
lift-sinh.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
count-2-revN/A
lower-+.f6481.1
Applied rewrites81.1%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.02) (+ (* (+ J J) (fma (* (* K K) l) -0.125 l)) U) (fma (+ J J) (sinh l) U)))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.02) {
tmp = ((J + J) * fma(((K * K) * l), -0.125, l)) + U;
} else {
tmp = fma((J + J), sinh(l), U);
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.02) tmp = Float64(Float64(Float64(J + J) * fma(Float64(Float64(K * K) * l), -0.125, l)) + U); else tmp = fma(Float64(J + J), sinh(l), U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.02], N[(N[(N[(J + J), $MachinePrecision] * N[(N[(N[(K * K), $MachinePrecision] * l), $MachinePrecision] * -0.125 + l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.02:\\
\;\;\;\;\left(J + J\right) \cdot \mathsf{fma}\left(\left(K \cdot K\right) \cdot \ell, -0.125, \ell\right) + U\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J + J, \sinh \ell, U\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.0200000000000000004Initial program 86.5%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6463.3
Applied rewrites63.3%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6448.5
Applied rewrites48.5%
Applied rewrites48.5%
if -0.0200000000000000004 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
lift-sinh.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
count-2-revN/A
lower-+.f6481.1
Applied rewrites81.1%
(FPCore (J l K U)
:precision binary64
(if (<= l -0.00072)
(fma (- 1.0 (exp (- l))) J U)
(if (<= l 4.5e+53)
(+ (* 2.0 (* J l)) U)
(+ (* (+ J J) (fma (* (* K K) l) -0.125 l)) U))))
double code(double J, double l, double K, double U) {
double tmp;
if (l <= -0.00072) {
tmp = fma((1.0 - exp(-l)), J, U);
} else if (l <= 4.5e+53) {
tmp = (2.0 * (J * l)) + U;
} else {
tmp = ((J + J) * fma(((K * K) * l), -0.125, l)) + U;
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (l <= -0.00072) tmp = fma(Float64(1.0 - exp(Float64(-l))), J, U); elseif (l <= 4.5e+53) tmp = Float64(Float64(2.0 * Float64(J * l)) + U); else tmp = Float64(Float64(Float64(J + J) * fma(Float64(Float64(K * K) * l), -0.125, l)) + U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[l, -0.00072], N[(N[(1.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J + U), $MachinePrecision], If[LessEqual[l, 4.5e+53], N[(N[(2.0 * N[(J * l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(N[(J + J), $MachinePrecision] * N[(N[(N[(K * K), $MachinePrecision] * l), $MachinePrecision] * -0.125 + l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.00072:\\
\;\;\;\;\mathsf{fma}\left(1 - e^{-\ell}, J, U\right)\\
\mathbf{elif}\;\ell \leq 4.5 \cdot 10^{+53}:\\
\;\;\;\;2 \cdot \left(J \cdot \ell\right) + U\\
\mathbf{else}:\\
\;\;\;\;\left(J + J\right) \cdot \mathsf{fma}\left(\left(K \cdot K\right) \cdot \ell, -0.125, \ell\right) + U\\
\end{array}
\end{array}
if l < -7.20000000000000045e-4Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
Taylor expanded in l around 0
Applied rewrites55.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6455.6
Applied rewrites55.6%
if -7.20000000000000045e-4 < l < 4.5000000000000002e53Initial program 86.5%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6463.3
Applied rewrites63.3%
Taylor expanded in K around 0
lower-*.f6453.5
Applied rewrites53.5%
if 4.5000000000000002e53 < l Initial program 86.5%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6463.3
Applied rewrites63.3%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6448.5
Applied rewrites48.5%
Applied rewrites48.5%
(FPCore (J l K U) :precision binary64 (if (<= l -0.00072) (fma (- 1.0 (exp (- l))) J U) (+ (* 2.0 (* J l)) U)))
double code(double J, double l, double K, double U) {
double tmp;
if (l <= -0.00072) {
tmp = fma((1.0 - exp(-l)), J, U);
} else {
tmp = (2.0 * (J * l)) + U;
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (l <= -0.00072) tmp = fma(Float64(1.0 - exp(Float64(-l))), J, U); else tmp = Float64(Float64(2.0 * Float64(J * l)) + U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[l, -0.00072], N[(N[(1.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J + U), $MachinePrecision], N[(N[(2.0 * N[(J * l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.00072:\\
\;\;\;\;\mathsf{fma}\left(1 - e^{-\ell}, J, U\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(J \cdot \ell\right) + U\\
\end{array}
\end{array}
if l < -7.20000000000000045e-4Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
Taylor expanded in l around 0
Applied rewrites55.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6455.6
Applied rewrites55.6%
if -7.20000000000000045e-4 < l Initial program 86.5%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6463.3
Applied rewrites63.3%
Taylor expanded in K around 0
lower-*.f6453.5
Applied rewrites53.5%
(FPCore (J l K U) :precision binary64 (if (<= (* J (- (exp l) (exp (- l)))) (- INFINITY)) (* J (fma 2.0 l (/ U J))) (+ (* 2.0 (* J l)) U)))
double code(double J, double l, double K, double U) {
double tmp;
if ((J * (exp(l) - exp(-l))) <= -((double) INFINITY)) {
tmp = J * fma(2.0, l, (U / J));
} else {
tmp = (2.0 * (J * l)) + U;
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (Float64(J * Float64(exp(l) - exp(Float64(-l)))) <= Float64(-Inf)) tmp = Float64(J * fma(2.0, l, Float64(U / J))); else tmp = Float64(Float64(2.0 * Float64(J * l)) + U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-Infinity)], N[(J * N[(2.0 * l + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[(J * l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;J \cdot \left(e^{\ell} - e^{-\ell}\right) \leq -\infty:\\
\;\;\;\;J \cdot \mathsf{fma}\left(2, \ell, \frac{U}{J}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(J \cdot \ell\right) + U\\
\end{array}
\end{array}
if (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -inf.0Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
Taylor expanded in J around inf
lower-*.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-exp.f64N/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6457.2
Applied rewrites57.2%
Taylor expanded in l around 0
lower-fma.f64N/A
lower-/.f6450.9
Applied rewrites50.9%
if -inf.0 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) Initial program 86.5%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6463.3
Applied rewrites63.3%
Taylor expanded in K around 0
lower-*.f6453.5
Applied rewrites53.5%
(FPCore (J l K U) :precision binary64 (+ (* 2.0 (* J l)) U))
double code(double J, double l, double K, double U) {
return (2.0 * (J * l)) + U;
}
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(j, l, k, u)
use fmin_fmax_functions
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = (2.0d0 * (j * l)) + u
end function
public static double code(double J, double l, double K, double U) {
return (2.0 * (J * l)) + U;
}
def code(J, l, K, U): return (2.0 * (J * l)) + U
function code(J, l, K, U) return Float64(Float64(2.0 * Float64(J * l)) + U) end
function tmp = code(J, l, K, U) tmp = (2.0 * (J * l)) + U; end
code[J_, l_, K_, U_] := N[(N[(2.0 * N[(J * l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(J \cdot \ell\right) + U
\end{array}
Initial program 86.5%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6463.3
Applied rewrites63.3%
Taylor expanded in K around 0
lower-*.f6453.5
Applied rewrites53.5%
(FPCore (J l K U) :precision binary64 (fma (+ J J) l U))
double code(double J, double l, double K, double U) {
return fma((J + J), l, U);
}
function code(J, l, K, U) return fma(Float64(J + J), l, U) end
code[J_, l_, K_, U_] := N[(N[(J + J), $MachinePrecision] * l + U), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(J + J, \ell, U\right)
\end{array}
Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
lift-sinh.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
count-2-revN/A
lower-+.f6481.1
Applied rewrites81.1%
Taylor expanded in l around 0
Applied rewrites53.4%
(FPCore (J l K U) :precision binary64 (if (<= (* J (- (exp l) (exp (- l)))) (- INFINITY)) (* J (/ U J)) U))
double code(double J, double l, double K, double U) {
double tmp;
if ((J * (exp(l) - exp(-l))) <= -((double) INFINITY)) {
tmp = J * (U / J);
} else {
tmp = U;
}
return tmp;
}
public static double code(double J, double l, double K, double U) {
double tmp;
if ((J * (Math.exp(l) - Math.exp(-l))) <= -Double.POSITIVE_INFINITY) {
tmp = J * (U / J);
} else {
tmp = U;
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if (J * (math.exp(l) - math.exp(-l))) <= -math.inf: tmp = J * (U / J) else: tmp = U return tmp
function code(J, l, K, U) tmp = 0.0 if (Float64(J * Float64(exp(l) - exp(Float64(-l)))) <= Float64(-Inf)) tmp = Float64(J * Float64(U / J)); else tmp = U; end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if ((J * (exp(l) - exp(-l))) <= -Inf) tmp = J * (U / J); else tmp = U; end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-Infinity)], N[(J * N[(U / J), $MachinePrecision]), $MachinePrecision], U]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;J \cdot \left(e^{\ell} - e^{-\ell}\right) \leq -\infty:\\
\;\;\;\;J \cdot \frac{U}{J}\\
\mathbf{else}:\\
\;\;\;\;U\\
\end{array}
\end{array}
if (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -inf.0Initial program 86.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-exp.f64N/A
lower-neg.f6473.9
Applied rewrites73.9%
Taylor expanded in J around inf
lower-*.f64N/A
lower--.f64N/A
lower-+.f64N/A
lower-exp.f64N/A
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6457.2
Applied rewrites57.2%
Taylor expanded in J around 0
lower-/.f6433.6
Applied rewrites33.6%
if -inf.0 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) Initial program 86.5%
Taylor expanded in J around 0
Applied rewrites36.2%
(FPCore (J l K U) :precision binary64 U)
double code(double J, double l, double K, double U) {
return U;
}
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(j, l, k, u)
use fmin_fmax_functions
real(8), intent (in) :: j
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8), intent (in) :: u
code = u
end function
public static double code(double J, double l, double K, double U) {
return U;
}
def code(J, l, K, U): return U
function code(J, l, K, U) return U end
function tmp = code(J, l, K, U) tmp = U; end
code[J_, l_, K_, U_] := U
\begin{array}{l}
\\
U
\end{array}
Initial program 86.5%
Taylor expanded in J around 0
Applied rewrites36.2%
herbie shell --seed 2025148
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))