
(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]
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
Herbie found 11 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]
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
(FPCore (J l K U) :precision binary64 (fma (* (* (cos (* -0.5 K)) J) (sinh l)) 2.0 U))
double code(double J, double l, double K, double U) {
return fma(((cos((-0.5 * K)) * J) * sinh(l)), 2.0, U);
}
function code(J, l, K, U) return fma(Float64(Float64(cos(Float64(-0.5 * K)) * J) * sinh(l)), 2.0, U) end
code[J_, l_, K_, U_] := N[(N[(N[(N[Cos[N[(-0.5 * K), $MachinePrecision]], $MachinePrecision] * J), $MachinePrecision] * N[Sinh[l], $MachinePrecision]), $MachinePrecision] * 2.0 + U), $MachinePrecision]
\mathsf{fma}\left(\left(\cos \left(-0.5 \cdot K\right) \cdot J\right) \cdot \sinh \ell, 2, U\right)
Initial program 86.6%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites99.9%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.25) (+ (* (* J (- (exp l) (exp (- l)))) (+ 1.0 (* -0.125 (pow K 2.0)))) U) (+ U (* J (/ 1.0 (/ 2.0 (* (* 2.0 (sinh l)) 2.0)))))))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.25) {
tmp = ((J * (exp(l) - exp(-l))) * (1.0 + (-0.125 * pow(K, 2.0)))) + U;
} else {
tmp = U + (J * (1.0 / (2.0 / ((2.0 * sinh(l)) * 2.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(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
real(8) :: tmp
if (cos((k / 2.0d0)) <= (-0.25d0)) then
tmp = ((j * (exp(l) - exp(-l))) * (1.0d0 + ((-0.125d0) * (k ** 2.0d0)))) + u
else
tmp = u + (j * (1.0d0 / (2.0d0 / ((2.0d0 * sinh(l)) * 2.0d0))))
end if
code = tmp
end function
public static double code(double J, double l, double K, double U) {
double tmp;
if (Math.cos((K / 2.0)) <= -0.25) {
tmp = ((J * (Math.exp(l) - Math.exp(-l))) * (1.0 + (-0.125 * Math.pow(K, 2.0)))) + U;
} else {
tmp = U + (J * (1.0 / (2.0 / ((2.0 * Math.sinh(l)) * 2.0))));
}
return tmp;
}
def code(J, l, K, U): tmp = 0 if math.cos((K / 2.0)) <= -0.25: tmp = ((J * (math.exp(l) - math.exp(-l))) * (1.0 + (-0.125 * math.pow(K, 2.0)))) + U else: tmp = U + (J * (1.0 / (2.0 / ((2.0 * math.sinh(l)) * 2.0)))) return tmp
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.25) tmp = Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * Float64(1.0 + Float64(-0.125 * (K ^ 2.0)))) + U); else tmp = Float64(U + Float64(J * Float64(1.0 / Float64(2.0 / Float64(Float64(2.0 * sinh(l)) * 2.0))))); end return tmp end
function tmp_2 = code(J, l, K, U) tmp = 0.0; if (cos((K / 2.0)) <= -0.25) tmp = ((J * (exp(l) - exp(-l))) * (1.0 + (-0.125 * (K ^ 2.0)))) + U; else tmp = U + (J * (1.0 / (2.0 / ((2.0 * sinh(l)) * 2.0)))); end tmp_2 = tmp; end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.25], N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.125 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(1.0 / N[(2.0 / N[(N[(2.0 * N[Sinh[l], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.25:\\
\;\;\;\;\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \left(1 + -0.125 \cdot {K}^{2}\right) + U\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \frac{1}{\frac{2}{\left(2 \cdot \sinh \ell\right) \cdot 2}}\\
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.25Initial program 86.6%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6464.4%
Applied rewrites64.4%
if -0.25 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.6%
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
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
lift-sinh.f64N/A
*-commutativeN/A
lift-sinh.f64N/A
sinh-defN/A
lift-exp.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
associate-*l/N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f64N/A
lower-*.f6473.9%
Applied rewrites81.0%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.25) (fma (* (* (fma (* K K) -0.125 1.0) J) (sinh l)) 2.0 U) (+ U (* J (/ 1.0 (/ 2.0 (* (* 2.0 (sinh l)) 2.0)))))))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.25) {
tmp = fma(((fma((K * K), -0.125, 1.0) * J) * sinh(l)), 2.0, U);
} else {
tmp = U + (J * (1.0 / (2.0 / ((2.0 * sinh(l)) * 2.0))));
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.25) tmp = fma(Float64(Float64(fma(Float64(K * K), -0.125, 1.0) * J) * sinh(l)), 2.0, U); else tmp = Float64(U + Float64(J * Float64(1.0 / Float64(2.0 / Float64(Float64(2.0 * sinh(l)) * 2.0))))); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.25], N[(N[(N[(N[(N[(K * K), $MachinePrecision] * -0.125 + 1.0), $MachinePrecision] * J), $MachinePrecision] * N[Sinh[l], $MachinePrecision]), $MachinePrecision] * 2.0 + U), $MachinePrecision], N[(U + N[(J * N[(1.0 / N[(2.0 / N[(N[(2.0 * N[Sinh[l], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.25:\\
\;\;\;\;\mathsf{fma}\left(\left(\mathsf{fma}\left(K \cdot K, -0.125, 1\right) \cdot J\right) \cdot \sinh \ell, 2, U\right)\\
\mathbf{else}:\\
\;\;\;\;U + J \cdot \frac{1}{\frac{2}{\left(2 \cdot \sinh \ell\right) \cdot 2}}\\
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.25Initial program 86.6%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites99.9%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6468.5%
Applied rewrites68.5%
cos-fabs-rev68.5%
fabs-mul68.5%
metadata-eval68.5%
metadata-eval68.5%
fabs-mul68.5%
cos-fabs-rev68.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6468.5%
lift-pow.f64N/A
unpow2N/A
lower-*.f6468.5%
Applied rewrites68.5%
if -0.25 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.6%
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
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
lift-sinh.f64N/A
*-commutativeN/A
lift-sinh.f64N/A
sinh-defN/A
lift-exp.f64N/A
lift-neg.f64N/A
lift-exp.f64N/A
lift--.f64N/A
associate-*l/N/A
div-flipN/A
lower-unsound-/.f64N/A
lower-unsound-/.f64N/A
lower-*.f6473.9%
Applied rewrites81.0%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.25) (fma (* (* (fma (* K K) -0.125 1.0) J) (sinh l)) 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.25) {
tmp = fma(((fma((K * K), -0.125, 1.0) * J) * sinh(l)), 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.25) tmp = fma(Float64(Float64(fma(Float64(K * K), -0.125, 1.0) * J) * sinh(l)), 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.25], N[(N[(N[(N[(N[(K * K), $MachinePrecision] * -0.125 + 1.0), $MachinePrecision] * J), $MachinePrecision] * N[Sinh[l], $MachinePrecision]), $MachinePrecision] * 2.0 + U), $MachinePrecision], N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.25:\\
\;\;\;\;\mathsf{fma}\left(\left(\mathsf{fma}\left(K \cdot K, -0.125, 1\right) \cdot J\right) \cdot \sinh \ell, 2, U\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J + J, \sinh \ell, U\right)\\
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.25Initial program 86.6%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-undefN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites99.9%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6468.5%
Applied rewrites68.5%
cos-fabs-rev68.5%
fabs-mul68.5%
metadata-eval68.5%
metadata-eval68.5%
fabs-mul68.5%
cos-fabs-rev68.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6468.5%
lift-pow.f64N/A
unpow2N/A
lower-*.f6468.5%
Applied rewrites68.5%
if -0.25 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.6%
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.0%
Applied rewrites81.0%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.25) (+ (* 2.0 (* J (+ l (* -0.125 (* (* l K) 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.25) {
tmp = (2.0 * (J * (l + (-0.125 * ((l * K) * 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.25) tmp = Float64(Float64(2.0 * Float64(J * Float64(l + Float64(-0.125 * Float64(Float64(l * K) * 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.25], N[(N[(2.0 * N[(J * N[(l + N[(-0.125 * N[(N[(l * K), $MachinePrecision] * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(J + J), $MachinePrecision] * N[Sinh[l], $MachinePrecision] + U), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.25:\\
\;\;\;\;2 \cdot \left(J \cdot \left(\ell + -0.125 \cdot \left(\left(\ell \cdot K\right) \cdot K\right)\right)\right) + U\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(J + J, \sinh \ell, U\right)\\
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.25Initial program 86.6%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6464.5%
Applied rewrites64.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6449.0%
Applied rewrites49.0%
lift-*.f64N/A
*-commutativeN/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6450.3%
Applied rewrites50.3%
if -0.25 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.6%
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.0%
Applied rewrites81.0%
(FPCore (J l K U) :precision binary64 (if (<= l -2300.0) (fma (- 1.0 (exp (- l))) J U) (fma (/ (* (* l J) 2.0) U) U U)))
double code(double J, double l, double K, double U) {
double tmp;
if (l <= -2300.0) {
tmp = fma((1.0 - exp(-l)), J, U);
} else {
tmp = fma((((l * J) * 2.0) / U), U, U);
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (l <= -2300.0) tmp = fma(Float64(1.0 - exp(Float64(-l))), J, U); else tmp = fma(Float64(Float64(Float64(l * J) * 2.0) / U), U, U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[l, -2300.0], N[(N[(1.0 - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J + U), $MachinePrecision], N[(N[(N[(N[(l * J), $MachinePrecision] * 2.0), $MachinePrecision] / U), $MachinePrecision] * U + U), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\ell \leq -2300:\\
\;\;\;\;\mathsf{fma}\left(1 - e^{-\ell}, J, U\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\left(\ell \cdot J\right) \cdot 2}{U}, U, U\right)\\
\end{array}
if l < -2300Initial program 86.6%
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.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6455.0%
Applied rewrites55.0%
if -2300 < l Initial program 86.6%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6464.5%
Applied rewrites64.5%
Taylor expanded in K around 0
lower-*.f6454.4%
Applied rewrites54.4%
lift-+.f64N/A
+-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
Applied rewrites57.2%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6457.2%
Applied rewrites57.2%
(FPCore (J l K U)
:precision binary64
(if (<= l -8.5e+139)
(+ U (* J (- 1.0 (+ 1.0 (* l (- (* 0.5 l) 1.0))))))
(if (<= l -2.2e+31)
(+ (* (+ J J) (fma (* (* K K) l) -0.125 l)) U)
(fma (/ (* (* l J) 2.0) U) U U))))double code(double J, double l, double K, double U) {
double tmp;
if (l <= -8.5e+139) {
tmp = U + (J * (1.0 - (1.0 + (l * ((0.5 * l) - 1.0)))));
} else if (l <= -2.2e+31) {
tmp = ((J + J) * fma(((K * K) * l), -0.125, l)) + U;
} else {
tmp = fma((((l * J) * 2.0) / U), U, U);
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (l <= -8.5e+139) tmp = Float64(U + Float64(J * Float64(1.0 - Float64(1.0 + Float64(l * Float64(Float64(0.5 * l) - 1.0)))))); elseif (l <= -2.2e+31) tmp = Float64(Float64(Float64(J + J) * fma(Float64(Float64(K * K) * l), -0.125, l)) + U); else tmp = fma(Float64(Float64(Float64(l * J) * 2.0) / U), U, U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[l, -8.5e+139], N[(U + N[(J * N[(1.0 - N[(1.0 + N[(l * N[(N[(0.5 * l), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -2.2e+31], N[(N[(N[(J + J), $MachinePrecision] * N[(N[(N[(K * K), $MachinePrecision] * l), $MachinePrecision] * -0.125 + l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(N[(N[(l * J), $MachinePrecision] * 2.0), $MachinePrecision] / U), $MachinePrecision] * U + U), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;\ell \leq -8.5 \cdot 10^{+139}:\\
\;\;\;\;U + J \cdot \left(1 - \left(1 + \ell \cdot \left(0.5 \cdot \ell - 1\right)\right)\right)\\
\mathbf{elif}\;\ell \leq -2.2 \cdot 10^{+31}:\\
\;\;\;\;\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(\frac{\left(\ell \cdot J\right) \cdot 2}{U}, U, U\right)\\
\end{array}
if l < -8.4999999999999996e139Initial program 86.6%
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.0%
Taylor expanded in l around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f6451.9%
Applied rewrites51.9%
if -8.4999999999999996e139 < l < -2.2000000000000001e31Initial program 86.6%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6464.5%
Applied rewrites64.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6449.0%
Applied rewrites49.0%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
count-2N/A
lift-+.f64N/A
lower-*.f6448.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6448.9%
lift-pow.f64N/A
unpow2N/A
lower-*.f6448.9%
Applied rewrites48.9%
if -2.2000000000000001e31 < l Initial program 86.6%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6464.5%
Applied rewrites64.5%
Taylor expanded in K around 0
lower-*.f6454.4%
Applied rewrites54.4%
lift-+.f64N/A
+-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
Applied rewrites57.2%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6457.2%
Applied rewrites57.2%
(FPCore (J l K U) :precision binary64 (if (<= (cos (/ K 2.0)) -0.26) (+ (* (+ J J) (fma (* (* K K) l) -0.125 l)) U) (fma (/ (* (* l J) 2.0) U) U U)))
double code(double J, double l, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= -0.26) {
tmp = ((J + J) * fma(((K * K) * l), -0.125, l)) + U;
} else {
tmp = fma((((l * J) * 2.0) / U), U, U);
}
return tmp;
}
function code(J, l, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= -0.26) tmp = Float64(Float64(Float64(J + J) * fma(Float64(Float64(K * K) * l), -0.125, l)) + U); else tmp = fma(Float64(Float64(Float64(l * J) * 2.0) / U), U, U); end return tmp end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.26], N[(N[(N[(J + J), $MachinePrecision] * N[(N[(N[(K * K), $MachinePrecision] * l), $MachinePrecision] * -0.125 + l), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(N[(N[(N[(l * J), $MachinePrecision] * 2.0), $MachinePrecision] / U), $MachinePrecision] * U + U), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.26:\\
\;\;\;\;\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(\frac{\left(\ell \cdot J\right) \cdot 2}{U}, U, U\right)\\
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.26000000000000001Initial program 86.6%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6464.5%
Applied rewrites64.5%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6449.0%
Applied rewrites49.0%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
count-2N/A
lift-+.f64N/A
lower-*.f6448.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6448.9%
lift-pow.f64N/A
unpow2N/A
lower-*.f6448.9%
Applied rewrites48.9%
if -0.26000000000000001 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 86.6%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6464.5%
Applied rewrites64.5%
Taylor expanded in K around 0
lower-*.f6454.4%
Applied rewrites54.4%
lift-+.f64N/A
+-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
Applied rewrites57.2%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6457.2%
Applied rewrites57.2%
(FPCore (J l K U) :precision binary64 (fma (/ (* (* l J) 2.0) U) U U))
double code(double J, double l, double K, double U) {
return fma((((l * J) * 2.0) / U), U, U);
}
function code(J, l, K, U) return fma(Float64(Float64(Float64(l * J) * 2.0) / U), U, U) end
code[J_, l_, K_, U_] := N[(N[(N[(N[(l * J), $MachinePrecision] * 2.0), $MachinePrecision] / U), $MachinePrecision] * U + U), $MachinePrecision]
\mathsf{fma}\left(\frac{\left(\ell \cdot J\right) \cdot 2}{U}, U, U\right)
Initial program 86.6%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6464.5%
Applied rewrites64.5%
Taylor expanded in K around 0
lower-*.f6454.4%
Applied rewrites54.4%
lift-+.f64N/A
+-commutativeN/A
sum-to-multN/A
lower-unsound-*.f64N/A
Applied rewrites57.2%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6457.2%
Applied rewrites57.2%
(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]
2 \cdot \left(J \cdot \ell\right) + U
Initial program 86.6%
Taylor expanded in l around 0
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6464.5%
Applied rewrites64.5%
Taylor expanded in K around 0
lower-*.f6454.4%
Applied rewrites54.4%
(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
U
Initial program 86.6%
Taylor expanded in J around 0
Applied rewrites36.8%
herbie shell --seed 2025212
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))