
(FPCore (J K U) :precision binary64 (let* ((t_0 (cos (/ K 2.0)))) (* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0))))))
double code(double J, double K, double U) {
double t_0 = cos((K / 2.0));
return ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(j, k, u)
use fmin_fmax_functions
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
t_0 = cos((k / 2.0d0))
code = (((-2.0d0) * j) * t_0) * sqrt((1.0d0 + ((u / ((2.0d0 * j) * t_0)) ** 2.0d0)))
end function
public static double code(double J, double K, double U) {
double t_0 = Math.cos((K / 2.0));
return ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_0)), 2.0)));
}
def code(J, K, U): t_0 = math.cos((K / 2.0)) return ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_0)), 2.0)))
function code(J, K, U) t_0 = cos(Float64(K / 2.0)) return Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0)))) end
function tmp = code(J, K, U) t_0 = cos((K / 2.0)); tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / ((2.0 * J) * t_0)) ^ 2.0))); end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_0}\right)}^{2}}
\end{array}
\end{array}
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (J K U) :precision binary64 (let* ((t_0 (cos (/ K 2.0)))) (* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0))))))
double code(double J, double K, double U) {
double t_0 = cos((K / 2.0));
return ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(j, k, u)
use fmin_fmax_functions
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: t_0
t_0 = cos((k / 2.0d0))
code = (((-2.0d0) * j) * t_0) * sqrt((1.0d0 + ((u / ((2.0d0 * j) * t_0)) ** 2.0d0)))
end function
public static double code(double J, double K, double U) {
double t_0 = Math.cos((K / 2.0));
return ((-2.0 * J) * t_0) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_0)), 2.0)));
}
def code(J, K, U): t_0 = math.cos((K / 2.0)) return ((-2.0 * J) * t_0) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_0)), 2.0)))
function code(J, K, U) t_0 = cos(Float64(K / 2.0)) return Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0)))) end
function tmp = code(J, K, U) t_0 = cos((K / 2.0)); tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + ((U / ((2.0 * J) * t_0)) ^ 2.0))); end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
\left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_0}\right)}^{2}}
\end{array}
\end{array}
(FPCore (J K U) :precision binary64 (let* ((t_0 (cos (* K -0.5)))) (* (* (cosh (asinh (/ U (* (+ J J) t_0)))) (* J -2.0)) t_0)))
double code(double J, double K, double U) {
double t_0 = cos((K * -0.5));
return (cosh(asinh((U / ((J + J) * t_0)))) * (J * -2.0)) * t_0;
}
def code(J, K, U): t_0 = math.cos((K * -0.5)) return (math.cosh(math.asinh((U / ((J + J) * t_0)))) * (J * -2.0)) * t_0
function code(J, K, U) t_0 = cos(Float64(K * -0.5)) return Float64(Float64(cosh(asinh(Float64(U / Float64(Float64(J + J) * t_0)))) * Float64(J * -2.0)) * t_0) end
function tmp = code(J, K, U) t_0 = cos((K * -0.5)); tmp = (cosh(asinh((U / ((J + J) * t_0)))) * (J * -2.0)) * t_0; end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Cosh[N[ArcSinh[N[(U / N[(N[(J + J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(J * -2.0), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot -0.5\right)\\
\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot t\_0}\right) \cdot \left(J \cdot -2\right)\right) \cdot t\_0
\end{array}
\end{array}
Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
(FPCore (J K U) :precision binary64 (let* ((t_0 (cos (* K -0.5)))) (* (* (cosh (asinh (/ U (* (+ J J) t_0)))) t_0) (* J -2.0))))
double code(double J, double K, double U) {
double t_0 = cos((K * -0.5));
return (cosh(asinh((U / ((J + J) * t_0)))) * t_0) * (J * -2.0);
}
def code(J, K, U): t_0 = math.cos((K * -0.5)) return (math.cosh(math.asinh((U / ((J + J) * t_0)))) * t_0) * (J * -2.0)
function code(J, K, U) t_0 = cos(Float64(K * -0.5)) return Float64(Float64(cosh(asinh(Float64(U / Float64(Float64(J + J) * t_0)))) * t_0) * Float64(J * -2.0)) end
function tmp = code(J, K, U) t_0 = cos((K * -0.5)); tmp = (cosh(asinh((U / ((J + J) * t_0)))) * t_0) * (J * -2.0); end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Cosh[N[ArcSinh[N[(U / N[(N[(J + J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] * N[(J * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot -0.5\right)\\
\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot t\_0}\right) \cdot t\_0\right) \cdot \left(J \cdot -2\right)
\end{array}
\end{array}
Initial program 73.6%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.1%
(FPCore (J K U)
:precision binary64
(let* ((t_0 (cos (* 0.5 K)))
(t_1 (sqrt (/ 0.25 (pow t_0 2.0))))
(t_2 (cos (/ K 2.0)))
(t_3
(*
(* (* -2.0 J) t_2)
(sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_2)) 2.0)))))
(t_4 (* (/ U J) 0.5)))
(if (<= t_3 -5e+295)
(* (* t_0 (* -2.0 J)) (/ (* U t_1) J))
(if (<= t_3 INFINITY)
(* (* (* (sqrt (fma t_4 t_4 1.0)) J) -2.0) (cos (* K -0.5)))
(* (* -2.0 J) (* t_0 (* (/ t_1 J) U)))))))
double code(double J, double K, double U) {
double t_0 = cos((0.5 * K));
double t_1 = sqrt((0.25 / pow(t_0, 2.0)));
double t_2 = cos((K / 2.0));
double t_3 = ((-2.0 * J) * t_2) * sqrt((1.0 + pow((U / ((2.0 * J) * t_2)), 2.0)));
double t_4 = (U / J) * 0.5;
double tmp;
if (t_3 <= -5e+295) {
tmp = (t_0 * (-2.0 * J)) * ((U * t_1) / J);
} else if (t_3 <= ((double) INFINITY)) {
tmp = ((sqrt(fma(t_4, t_4, 1.0)) * J) * -2.0) * cos((K * -0.5));
} else {
tmp = (-2.0 * J) * (t_0 * ((t_1 / J) * U));
}
return tmp;
}
function code(J, K, U) t_0 = cos(Float64(0.5 * K)) t_1 = sqrt(Float64(0.25 / (t_0 ^ 2.0))) t_2 = cos(Float64(K / 2.0)) t_3 = Float64(Float64(Float64(-2.0 * J) * t_2) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_2)) ^ 2.0)))) t_4 = Float64(Float64(U / J) * 0.5) tmp = 0.0 if (t_3 <= -5e+295) tmp = Float64(Float64(t_0 * Float64(-2.0 * J)) * Float64(Float64(U * t_1) / J)); elseif (t_3 <= Inf) tmp = Float64(Float64(Float64(sqrt(fma(t_4, t_4, 1.0)) * J) * -2.0) * cos(Float64(K * -0.5))); else tmp = Float64(Float64(-2.0 * J) * Float64(t_0 * Float64(Float64(t_1 / J) * U))); end return tmp end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(0.25 / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$2), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(U / J), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[t$95$3, -5e+295], N[(N[(t$95$0 * N[(-2.0 * J), $MachinePrecision]), $MachinePrecision] * N[(N[(U * t$95$1), $MachinePrecision] / J), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, Infinity], N[(N[(N[(N[Sqrt[N[(t$95$4 * t$95$4 + 1.0), $MachinePrecision]], $MachinePrecision] * J), $MachinePrecision] * -2.0), $MachinePrecision] * N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * J), $MachinePrecision] * N[(t$95$0 * N[(N[(t$95$1 / J), $MachinePrecision] * U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot K\right)\\
t_1 := \sqrt{\frac{0.25}{{t\_0}^{2}}}\\
t_2 := \cos \left(\frac{K}{2}\right)\\
t_3 := \left(\left(-2 \cdot J\right) \cdot t\_2\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_2}\right)}^{2}}\\
t_4 := \frac{U}{J} \cdot 0.5\\
\mathbf{if}\;t\_3 \leq -5 \cdot 10^{+295}:\\
\;\;\;\;\left(t\_0 \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot t\_1}{J}\\
\mathbf{elif}\;t\_3 \leq \infty:\\
\;\;\;\;\left(\left(\sqrt{\mathsf{fma}\left(t\_4, t\_4, 1\right)} \cdot J\right) \cdot -2\right) \cdot \cos \left(K \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot J\right) \cdot \left(t\_0 \cdot \left(\frac{t\_1}{J} \cdot U\right)\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < -4.99999999999999991e295Initial program 73.6%
Taylor expanded in U around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f6412.5
Applied rewrites12.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6412.5
lift-/.f64N/A
mult-flipN/A
metadata-evalN/A
*-commutativeN/A
lift-*.f6412.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6412.5
Applied rewrites12.6%
Taylor expanded in J around 0
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f6420.6
Applied rewrites20.6%
if -4.99999999999999991e295 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < +inf.0Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
Taylor expanded in K around 0
lower-*.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites64.6%
if +inf.0 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) Initial program 73.6%
Taylor expanded in U around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f6412.5
Applied rewrites12.5%
Taylor expanded in J around -inf
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f6420.7
Applied rewrites20.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites20.7%
Taylor expanded in J around 0
lower-/.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f6420.5
Applied rewrites20.5%
(FPCore (J K U)
:precision binary64
(let* ((t_0 (cos (* 0.5 K)))
(t_1 (* (* -2.0 J) (* t_0 (* (/ (sqrt (/ 0.25 (pow t_0 2.0))) J) U))))
(t_2 (cos (/ K 2.0)))
(t_3
(*
(* (* -2.0 J) t_2)
(sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_2)) 2.0)))))
(t_4 (* (/ U J) 0.5)))
(if (<= t_3 -5e+295)
t_1
(if (<= t_3 INFINITY)
(* (* (* (sqrt (fma t_4 t_4 1.0)) J) -2.0) (cos (* K -0.5)))
t_1))))
double code(double J, double K, double U) {
double t_0 = cos((0.5 * K));
double t_1 = (-2.0 * J) * (t_0 * ((sqrt((0.25 / pow(t_0, 2.0))) / J) * U));
double t_2 = cos((K / 2.0));
double t_3 = ((-2.0 * J) * t_2) * sqrt((1.0 + pow((U / ((2.0 * J) * t_2)), 2.0)));
double t_4 = (U / J) * 0.5;
double tmp;
if (t_3 <= -5e+295) {
tmp = t_1;
} else if (t_3 <= ((double) INFINITY)) {
tmp = ((sqrt(fma(t_4, t_4, 1.0)) * J) * -2.0) * cos((K * -0.5));
} else {
tmp = t_1;
}
return tmp;
}
function code(J, K, U) t_0 = cos(Float64(0.5 * K)) t_1 = Float64(Float64(-2.0 * J) * Float64(t_0 * Float64(Float64(sqrt(Float64(0.25 / (t_0 ^ 2.0))) / J) * U))) t_2 = cos(Float64(K / 2.0)) t_3 = Float64(Float64(Float64(-2.0 * J) * t_2) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_2)) ^ 2.0)))) t_4 = Float64(Float64(U / J) * 0.5) tmp = 0.0 if (t_3 <= -5e+295) tmp = t_1; elseif (t_3 <= Inf) tmp = Float64(Float64(Float64(sqrt(fma(t_4, t_4, 1.0)) * J) * -2.0) * cos(Float64(K * -0.5))); else tmp = t_1; end return tmp end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(-2.0 * J), $MachinePrecision] * N[(t$95$0 * N[(N[(N[Sqrt[N[(0.25 / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / J), $MachinePrecision] * U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$2), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(U / J), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[t$95$3, -5e+295], t$95$1, If[LessEqual[t$95$3, Infinity], N[(N[(N[(N[Sqrt[N[(t$95$4 * t$95$4 + 1.0), $MachinePrecision]], $MachinePrecision] * J), $MachinePrecision] * -2.0), $MachinePrecision] * N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot K\right)\\
t_1 := \left(-2 \cdot J\right) \cdot \left(t\_0 \cdot \left(\frac{\sqrt{\frac{0.25}{{t\_0}^{2}}}}{J} \cdot U\right)\right)\\
t_2 := \cos \left(\frac{K}{2}\right)\\
t_3 := \left(\left(-2 \cdot J\right) \cdot t\_2\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_2}\right)}^{2}}\\
t_4 := \frac{U}{J} \cdot 0.5\\
\mathbf{if}\;t\_3 \leq -5 \cdot 10^{+295}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_3 \leq \infty:\\
\;\;\;\;\left(\left(\sqrt{\mathsf{fma}\left(t\_4, t\_4, 1\right)} \cdot J\right) \cdot -2\right) \cdot \cos \left(K \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < -4.99999999999999991e295 or +inf.0 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) Initial program 73.6%
Taylor expanded in U around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f6412.5
Applied rewrites12.5%
Taylor expanded in J around -inf
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f6420.7
Applied rewrites20.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites20.7%
Taylor expanded in J around 0
lower-/.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f6420.5
Applied rewrites20.5%
if -4.99999999999999991e295 < (*.f64 (*.f64 (*.f64 #s(literal -2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64)))) (sqrt.f64 (+.f64 #s(literal 1 binary64) (pow.f64 (/.f64 U (*.f64 (*.f64 #s(literal 2 binary64) J) (cos.f64 (/.f64 K #s(literal 2 binary64))))) #s(literal 2 binary64))))) < +inf.0Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
Taylor expanded in K around 0
lower-*.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites64.6%
(FPCore (J K U) :precision binary64 (* (* (cosh (asinh (* 0.5 (/ U J)))) (* J -2.0)) (cos (* K -0.5))))
double code(double J, double K, double U) {
return (cosh(asinh((0.5 * (U / J)))) * (J * -2.0)) * cos((K * -0.5));
}
def code(J, K, U): return (math.cosh(math.asinh((0.5 * (U / J)))) * (J * -2.0)) * math.cos((K * -0.5))
function code(J, K, U) return Float64(Float64(cosh(asinh(Float64(0.5 * Float64(U / J)))) * Float64(J * -2.0)) * cos(Float64(K * -0.5))) end
function tmp = code(J, K, U) tmp = (cosh(asinh((0.5 * (U / J)))) * (J * -2.0)) * cos((K * -0.5)); end
code[J_, K_, U_] := N[(N[(N[Cosh[N[ArcSinh[N[(0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(J * -2.0), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)
\end{array}
Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
Taylor expanded in K around 0
lower-*.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
(FPCore (J K U)
:precision binary64
(let* ((t_0 (* (/ U J) 0.5)))
(if (<= K 3.4e-12)
(*
(* (cosh (asinh (* 0.5 (/ U J)))) (* J -2.0))
(+ 1.0 (* -0.125 (pow K 2.0))))
(* (* (* (sqrt (fma t_0 t_0 1.0)) J) -2.0) (cos (* K -0.5))))))
double code(double J, double K, double U) {
double t_0 = (U / J) * 0.5;
double tmp;
if (K <= 3.4e-12) {
tmp = (cosh(asinh((0.5 * (U / J)))) * (J * -2.0)) * (1.0 + (-0.125 * pow(K, 2.0)));
} else {
tmp = ((sqrt(fma(t_0, t_0, 1.0)) * J) * -2.0) * cos((K * -0.5));
}
return tmp;
}
function code(J, K, U) t_0 = Float64(Float64(U / J) * 0.5) tmp = 0.0 if (K <= 3.4e-12) tmp = Float64(Float64(cosh(asinh(Float64(0.5 * Float64(U / J)))) * Float64(J * -2.0)) * Float64(1.0 + Float64(-0.125 * (K ^ 2.0)))); else tmp = Float64(Float64(Float64(sqrt(fma(t_0, t_0, 1.0)) * J) * -2.0) * cos(Float64(K * -0.5))); end return tmp end
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(U / J), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[K, 3.4e-12], N[(N[(N[Cosh[N[ArcSinh[N[(0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(J * -2.0), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.125 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sqrt[N[(t$95$0 * t$95$0 + 1.0), $MachinePrecision]], $MachinePrecision] * J), $MachinePrecision] * -2.0), $MachinePrecision] * N[Cos[N[(K * -0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{U}{J} \cdot 0.5\\
\mathbf{if}\;K \leq 3.4 \cdot 10^{-12}:\\
\;\;\;\;\left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \left(1 + -0.125 \cdot {K}^{2}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\sqrt{\mathsf{fma}\left(t\_0, t\_0, 1\right)} \cdot J\right) \cdot -2\right) \cdot \cos \left(K \cdot -0.5\right)\\
\end{array}
\end{array}
if K < 3.4000000000000001e-12Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
Taylor expanded in K around 0
lower-*.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6443.3
Applied rewrites43.3%
if 3.4000000000000001e-12 < K Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
Taylor expanded in K around 0
lower-*.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites64.6%
(FPCore (J K U)
:precision binary64
(if (<= (cos (/ K 2.0)) 0.9999)
(* -2.0 (* J (cos (* -0.5 K))))
(*
(* (cosh (asinh (* 0.5 (/ U J)))) (* J -2.0))
(+ 1.0 (* -0.125 (pow K 2.0))))))
double code(double J, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= 0.9999) {
tmp = -2.0 * (J * cos((-0.5 * K)));
} else {
tmp = (cosh(asinh((0.5 * (U / J)))) * (J * -2.0)) * (1.0 + (-0.125 * pow(K, 2.0)));
}
return tmp;
}
def code(J, K, U): tmp = 0 if math.cos((K / 2.0)) <= 0.9999: tmp = -2.0 * (J * math.cos((-0.5 * K))) else: tmp = (math.cosh(math.asinh((0.5 * (U / J)))) * (J * -2.0)) * (1.0 + (-0.125 * math.pow(K, 2.0))) return tmp
function code(J, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= 0.9999) tmp = Float64(-2.0 * Float64(J * cos(Float64(-0.5 * K)))); else tmp = Float64(Float64(cosh(asinh(Float64(0.5 * Float64(U / J)))) * Float64(J * -2.0)) * Float64(1.0 + Float64(-0.125 * (K ^ 2.0)))); end return tmp end
function tmp_2 = code(J, K, U) tmp = 0.0; if (cos((K / 2.0)) <= 0.9999) tmp = -2.0 * (J * cos((-0.5 * K))); else tmp = (cosh(asinh((0.5 * (U / J)))) * (J * -2.0)) * (1.0 + (-0.125 * (K ^ 2.0))); end tmp_2 = tmp; end
code[J_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.9999], N[(-2.0 * N[(J * N[Cos[N[(-0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cosh[N[ArcSinh[N[(0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(J * -2.0), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.125 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.9999:\\
\;\;\;\;-2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \left(1 + -0.125 \cdot {K}^{2}\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.99990000000000001Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
Taylor expanded in J around inf
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6452.6
Applied rewrites52.6%
if 0.99990000000000001 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
Taylor expanded in K around 0
lower-*.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
Taylor expanded in K around 0
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6443.3
Applied rewrites43.3%
(FPCore (J K U)
:precision binary64
(if (<= (cos (/ K 2.0)) 0.9999)
(* -2.0 (* J (cos (* -0.5 K))))
(*
(sqrt (+ (pow (* 0.5 (/ U J)) 2.0) 1.0))
(fma (* (* K K) J) 0.25 (* -2.0 J)))))
double code(double J, double K, double U) {
double tmp;
if (cos((K / 2.0)) <= 0.9999) {
tmp = -2.0 * (J * cos((-0.5 * K)));
} else {
tmp = sqrt((pow((0.5 * (U / J)), 2.0) + 1.0)) * fma(((K * K) * J), 0.25, (-2.0 * J));
}
return tmp;
}
function code(J, K, U) tmp = 0.0 if (cos(Float64(K / 2.0)) <= 0.9999) tmp = Float64(-2.0 * Float64(J * cos(Float64(-0.5 * K)))); else tmp = Float64(sqrt(Float64((Float64(0.5 * Float64(U / J)) ^ 2.0) + 1.0)) * fma(Float64(Float64(K * K) * J), 0.25, Float64(-2.0 * J))); end return tmp end
code[J_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.9999], N[(-2.0 * N[(J * N[Cos[N[(-0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(N[Power[N[(0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * N[(N[(N[(K * K), $MachinePrecision] * J), $MachinePrecision] * 0.25 + N[(-2.0 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.9999:\\
\;\;\;\;-2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{\left(0.5 \cdot \frac{U}{J}\right)}^{2} + 1} \cdot \mathsf{fma}\left(\left(K \cdot K\right) \cdot J, 0.25, -2 \cdot J\right)\\
\end{array}
\end{array}
if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.99990000000000001Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
Taylor expanded in J around inf
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6452.6
Applied rewrites52.6%
if 0.99990000000000001 < (cos.f64 (/.f64 K #s(literal 2 binary64))) Initial program 73.6%
Taylor expanded in K around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6437.6
Applied rewrites37.6%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6437.6
Applied rewrites37.5%
Taylor expanded in K around 0
lower-*.f64N/A
lower-/.f6437.5
Applied rewrites37.5%
(FPCore (J K U) :precision binary64 (* -2.0 (* J (cos (* -0.5 K)))))
double code(double J, double K, double U) {
return -2.0 * (J * cos((-0.5 * K)));
}
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, k, u)
use fmin_fmax_functions
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u
code = (-2.0d0) * (j * cos(((-0.5d0) * k)))
end function
public static double code(double J, double K, double U) {
return -2.0 * (J * Math.cos((-0.5 * K)));
}
def code(J, K, U): return -2.0 * (J * math.cos((-0.5 * K)))
function code(J, K, U) return Float64(-2.0 * Float64(J * cos(Float64(-0.5 * K)))) end
function tmp = code(J, K, U) tmp = -2.0 * (J * cos((-0.5 * K))); end
code[J_, K_, U_] := N[(-2.0 * N[(J * N[Cos[N[(-0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right)
\end{array}
Initial program 73.6%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites85.1%
Taylor expanded in J around inf
lower-*.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6452.6
Applied rewrites52.6%
(FPCore (J K U) :precision binary64 (* (fma J -2.0 (* (* K (* K J)) 0.25)) 1.0))
double code(double J, double K, double U) {
return fma(J, -2.0, ((K * (K * J)) * 0.25)) * 1.0;
}
function code(J, K, U) return Float64(fma(J, -2.0, Float64(Float64(K * Float64(K * J)) * 0.25)) * 1.0) end
code[J_, K_, U_] := N[(N[(J * -2.0 + N[(N[(K * N[(K * J), $MachinePrecision]), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(J, -2, \left(K \cdot \left(K \cdot J\right)\right) \cdot 0.25\right) \cdot 1
\end{array}
Initial program 73.6%
Taylor expanded in J around inf
Applied rewrites52.5%
Taylor expanded in K around 0
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6427.4
Applied rewrites27.4%
lift-fma.f64N/A
*-commutativeN/A
lower-fma.f6427.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6427.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6427.4
lift-pow.f64N/A
unpow2N/A
lower-*.f6427.4
Applied rewrites27.4%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6427.4
Applied rewrites27.4%
herbie shell --seed 2025151
(FPCore (J K U)
:name "Maksimov and Kolovsky, Equation (3)"
:precision binary64
(* (* (* -2.0 J) (cos (/ K 2.0))) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) (cos (/ K 2.0)))) 2.0)))))