
(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 12 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)))) (* (* (hypot (/ U (* (+ J J) t_0)) 1.0) -2.0) (* t_0 J))))
double code(double J, double K, double U) {
double t_0 = cos((K * 0.5));
return (hypot((U / ((J + J) * t_0)), 1.0) * -2.0) * (t_0 * J);
}
public static double code(double J, double K, double U) {
double t_0 = Math.cos((K * 0.5));
return (Math.hypot((U / ((J + J) * t_0)), 1.0) * -2.0) * (t_0 * J);
}
def code(J, K, U): t_0 = math.cos((K * 0.5)) return (math.hypot((U / ((J + J) * t_0)), 1.0) * -2.0) * (t_0 * J)
function code(J, K, U) t_0 = cos(Float64(K * 0.5)) return Float64(Float64(hypot(Float64(U / Float64(Float64(J + J) * t_0)), 1.0) * -2.0) * Float64(t_0 * J)) end
function tmp = code(J, K, U) t_0 = cos((K * 0.5)); tmp = (hypot((U / ((J + J) * t_0)), 1.0) * -2.0) * (t_0 * J); end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[Sqrt[N[(U / N[(N[(J + J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2 + 1.0 ^ 2], $MachinePrecision] * -2.0), $MachinePrecision] * N[(t$95$0 * J), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
\left(\mathsf{hypot}\left(\frac{U}{\left(J + J\right) \cdot t\_0}, 1\right) \cdot -2\right) \cdot \left(t\_0 \cdot J\right)
\end{array}
\end{array}
Initial program 73.3%
Applied rewrites73.3%
Applied rewrites88.3%
Applied rewrites88.3%
(FPCore (J K U)
:precision binary64
(let* ((t_0 (* (* -2.0 J) (cos (* K 0.5))))
(t_1 (* t_0 (/ (* U (sqrt (/ 0.25 (+ 0.5 (* 0.5 (cos K)))))) J)))
(t_2 (cos (/ K 2.0)))
(t_3 (* (* -2.0 J) t_2))
(t_4 (* t_3 (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_2)) 2.0))))))
(if (<= t_4 (- INFINITY))
t_1
(if (<= t_4 2e-87)
(* t_3 (sqrt (+ 1.0 (* (/ (* U 0.25) J) (/ U J)))))
(if (<= t_4 5e+307)
(* t_0 (sqrt (fma (/ U (* J (* J (* (- (cos K) -1.0) 2.0)))) U 1.0)))
t_1)))))
double code(double J, double K, double U) {
double t_0 = (-2.0 * J) * cos((K * 0.5));
double t_1 = t_0 * ((U * sqrt((0.25 / (0.5 + (0.5 * cos(K)))))) / J);
double t_2 = cos((K / 2.0));
double t_3 = (-2.0 * J) * t_2;
double t_4 = t_3 * sqrt((1.0 + pow((U / ((2.0 * J) * t_2)), 2.0)));
double tmp;
if (t_4 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_4 <= 2e-87) {
tmp = t_3 * sqrt((1.0 + (((U * 0.25) / J) * (U / J))));
} else if (t_4 <= 5e+307) {
tmp = t_0 * sqrt(fma((U / (J * (J * ((cos(K) - -1.0) * 2.0)))), U, 1.0));
} else {
tmp = t_1;
}
return tmp;
}
function code(J, K, U) t_0 = Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5))) t_1 = Float64(t_0 * Float64(Float64(U * sqrt(Float64(0.25 / Float64(0.5 + Float64(0.5 * cos(K)))))) / J)) t_2 = cos(Float64(K / 2.0)) t_3 = Float64(Float64(-2.0 * J) * t_2) t_4 = Float64(t_3 * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_2)) ^ 2.0)))) tmp = 0.0 if (t_4 <= Float64(-Inf)) tmp = t_1; elseif (t_4 <= 2e-87) tmp = Float64(t_3 * sqrt(Float64(1.0 + Float64(Float64(Float64(U * 0.25) / J) * Float64(U / J))))); elseif (t_4 <= 5e+307) tmp = Float64(t_0 * sqrt(fma(Float64(U / Float64(J * Float64(J * Float64(Float64(cos(K) - -1.0) * 2.0)))), U, 1.0))); else tmp = t_1; end return tmp end
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[(U * N[Sqrt[N[(0.25 / N[(0.5 + N[(0.5 * N[Cos[K], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / J), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[(-2.0 * J), $MachinePrecision] * t$95$2), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 * 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]}, If[LessEqual[t$95$4, (-Infinity)], t$95$1, If[LessEqual[t$95$4, 2e-87], N[(t$95$3 * N[Sqrt[N[(1.0 + N[(N[(N[(U * 0.25), $MachinePrecision] / J), $MachinePrecision] * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 5e+307], N[(t$95$0 * N[Sqrt[N[(N[(U / N[(J * N[(J * N[(N[(N[Cos[K], $MachinePrecision] - -1.0), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * U + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\\
t_1 := t\_0 \cdot \frac{U \cdot \sqrt{\frac{0.25}{0.5 + 0.5 \cdot \cos K}}}{J}\\
t_2 := \cos \left(\frac{K}{2}\right)\\
t_3 := \left(-2 \cdot J\right) \cdot t\_2\\
t_4 := t\_3 \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_2}\right)}^{2}}\\
\mathbf{if}\;t\_4 \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_4 \leq 2 \cdot 10^{-87}:\\
\;\;\;\;t\_3 \cdot \sqrt{1 + \frac{U \cdot 0.25}{J} \cdot \frac{U}{J}}\\
\mathbf{elif}\;t\_4 \leq 5 \cdot 10^{+307}:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(\frac{U}{J \cdot \left(J \cdot \left(\left(\cos K - -1\right) \cdot 2\right)\right)}, U, 1\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))))) < -inf.0 or 5e307 < (*.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.3%
Taylor expanded in U around -inf
Applied rewrites13.3%
Applied rewrites13.3%
Taylor expanded in J around -inf
Applied rewrites20.7%
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))))) < 2.00000000000000004e-87Initial program 73.3%
Taylor expanded in K around 0
Applied rewrites51.9%
Applied rewrites64.8%
if 2.00000000000000004e-87 < (*.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))))) < 5e307Initial program 73.3%
Applied rewrites73.3%
Applied rewrites61.7%
Applied rewrites61.7%
(FPCore (J K U)
:precision binary64
(let* ((t_0 (cos (/ K 2.0)))
(t_1 (* (* -2.0 J) t_0))
(t_2 (* t_1 (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_0)) 2.0)))))
(t_3 (cos (* K 0.5)))
(t_4
(*
(* (* -2.0 J) t_3)
(/ (* U (sqrt (/ 0.25 (+ 0.5 (* 0.5 (cos K)))))) J))))
(if (<= t_2 (- INFINITY))
t_4
(if (<= t_2 2e-87)
(* t_1 (sqrt (+ 1.0 (* (/ (* U 0.25) J) (/ U J)))))
(if (<= t_2 5e+307)
(*
(* (sqrt (fma (/ U (* (* (- (cos K) -1.0) 2.0) (* J J))) U 1.0)) t_3)
(* -2.0 J))
t_4)))))
double code(double J, double K, double U) {
double t_0 = cos((K / 2.0));
double t_1 = (-2.0 * J) * t_0;
double t_2 = t_1 * sqrt((1.0 + pow((U / ((2.0 * J) * t_0)), 2.0)));
double t_3 = cos((K * 0.5));
double t_4 = ((-2.0 * J) * t_3) * ((U * sqrt((0.25 / (0.5 + (0.5 * cos(K)))))) / J);
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = t_4;
} else if (t_2 <= 2e-87) {
tmp = t_1 * sqrt((1.0 + (((U * 0.25) / J) * (U / J))));
} else if (t_2 <= 5e+307) {
tmp = (sqrt(fma((U / (((cos(K) - -1.0) * 2.0) * (J * J))), U, 1.0)) * t_3) * (-2.0 * J);
} else {
tmp = t_4;
}
return tmp;
}
function code(J, K, U) t_0 = cos(Float64(K / 2.0)) t_1 = Float64(Float64(-2.0 * J) * t_0) t_2 = Float64(t_1 * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_0)) ^ 2.0)))) t_3 = cos(Float64(K * 0.5)) t_4 = Float64(Float64(Float64(-2.0 * J) * t_3) * Float64(Float64(U * sqrt(Float64(0.25 / Float64(0.5 + Float64(0.5 * cos(K)))))) / J)) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = t_4; elseif (t_2 <= 2e-87) tmp = Float64(t_1 * sqrt(Float64(1.0 + Float64(Float64(Float64(U * 0.25) / J) * Float64(U / J))))); elseif (t_2 <= 5e+307) tmp = Float64(Float64(sqrt(fma(Float64(U / Float64(Float64(Float64(cos(K) - -1.0) * 2.0) * Float64(J * J))), U, 1.0)) * t_3) * Float64(-2.0 * J)); else tmp = t_4; end return tmp end
code[J_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * 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]}, Block[{t$95$3 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$3), $MachinePrecision] * N[(N[(U * N[Sqrt[N[(0.25 / N[(0.5 + N[(0.5 * N[Cos[K], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / J), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$4, If[LessEqual[t$95$2, 2e-87], N[(t$95$1 * N[Sqrt[N[(1.0 + N[(N[(N[(U * 0.25), $MachinePrecision] / J), $MachinePrecision] * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 5e+307], N[(N[(N[Sqrt[N[(N[(U / N[(N[(N[(N[Cos[K], $MachinePrecision] - -1.0), $MachinePrecision] * 2.0), $MachinePrecision] * N[(J * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * U + 1.0), $MachinePrecision]], $MachinePrecision] * t$95$3), $MachinePrecision] * N[(-2.0 * J), $MachinePrecision]), $MachinePrecision], t$95$4]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\frac{K}{2}\right)\\
t_1 := \left(-2 \cdot J\right) \cdot t\_0\\
t_2 := t\_1 \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_0}\right)}^{2}}\\
t_3 := \cos \left(K \cdot 0.5\right)\\
t_4 := \left(\left(-2 \cdot J\right) \cdot t\_3\right) \cdot \frac{U \cdot \sqrt{\frac{0.25}{0.5 + 0.5 \cdot \cos K}}}{J}\\
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;t\_4\\
\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{-87}:\\
\;\;\;\;t\_1 \cdot \sqrt{1 + \frac{U \cdot 0.25}{J} \cdot \frac{U}{J}}\\
\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{+307}:\\
\;\;\;\;\left(\sqrt{\mathsf{fma}\left(\frac{U}{\left(\left(\cos K - -1\right) \cdot 2\right) \cdot \left(J \cdot J\right)}, U, 1\right)} \cdot t\_3\right) \cdot \left(-2 \cdot J\right)\\
\mathbf{else}:\\
\;\;\;\;t\_4\\
\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))))) < -inf.0 or 5e307 < (*.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.3%
Taylor expanded in U around -inf
Applied rewrites13.3%
Applied rewrites13.3%
Taylor expanded in J around -inf
Applied rewrites20.7%
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))))) < 2.00000000000000004e-87Initial program 73.3%
Taylor expanded in K around 0
Applied rewrites51.9%
Applied rewrites64.8%
if 2.00000000000000004e-87 < (*.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))))) < 5e307Initial program 73.3%
Applied rewrites73.3%
Applied rewrites61.7%
Applied rewrites61.7%
(FPCore (J K U)
:precision binary64
(let* ((t_0
(*
(* (* -2.0 J) (cos (* K 0.5)))
(/ (* U (sqrt (/ 0.25 (+ 0.5 (* 0.5 (cos K)))))) J)))
(t_1 (cos (/ K 2.0)))
(t_2 (* (* -2.0 J) t_1))
(t_3 (* t_2 (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_1)) 2.0))))))
(if (<= t_3 (- INFINITY))
t_0
(if (<= t_3 5e+307)
(* t_2 (sqrt (+ 1.0 (* (/ (* U 0.25) J) (/ U J)))))
t_0))))
double code(double J, double K, double U) {
double t_0 = ((-2.0 * J) * cos((K * 0.5))) * ((U * sqrt((0.25 / (0.5 + (0.5 * cos(K)))))) / J);
double t_1 = cos((K / 2.0));
double t_2 = (-2.0 * J) * t_1;
double t_3 = t_2 * sqrt((1.0 + pow((U / ((2.0 * J) * t_1)), 2.0)));
double tmp;
if (t_3 <= -((double) INFINITY)) {
tmp = t_0;
} else if (t_3 <= 5e+307) {
tmp = t_2 * sqrt((1.0 + (((U * 0.25) / J) * (U / J))));
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double J, double K, double U) {
double t_0 = ((-2.0 * J) * Math.cos((K * 0.5))) * ((U * Math.sqrt((0.25 / (0.5 + (0.5 * Math.cos(K)))))) / J);
double t_1 = Math.cos((K / 2.0));
double t_2 = (-2.0 * J) * t_1;
double t_3 = t_2 * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_1)), 2.0)));
double tmp;
if (t_3 <= -Double.POSITIVE_INFINITY) {
tmp = t_0;
} else if (t_3 <= 5e+307) {
tmp = t_2 * Math.sqrt((1.0 + (((U * 0.25) / J) * (U / J))));
} else {
tmp = t_0;
}
return tmp;
}
def code(J, K, U): t_0 = ((-2.0 * J) * math.cos((K * 0.5))) * ((U * math.sqrt((0.25 / (0.5 + (0.5 * math.cos(K)))))) / J) t_1 = math.cos((K / 2.0)) t_2 = (-2.0 * J) * t_1 t_3 = t_2 * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_1)), 2.0))) tmp = 0 if t_3 <= -math.inf: tmp = t_0 elif t_3 <= 5e+307: tmp = t_2 * math.sqrt((1.0 + (((U * 0.25) / J) * (U / J)))) else: tmp = t_0 return tmp
function code(J, K, U) t_0 = Float64(Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5))) * Float64(Float64(U * sqrt(Float64(0.25 / Float64(0.5 + Float64(0.5 * cos(K)))))) / J)) t_1 = cos(Float64(K / 2.0)) t_2 = Float64(Float64(-2.0 * J) * t_1) t_3 = Float64(t_2 * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_1)) ^ 2.0)))) tmp = 0.0 if (t_3 <= Float64(-Inf)) tmp = t_0; elseif (t_3 <= 5e+307) tmp = Float64(t_2 * sqrt(Float64(1.0 + Float64(Float64(Float64(U * 0.25) / J) * Float64(U / J))))); else tmp = t_0; end return tmp end
function tmp_2 = code(J, K, U) t_0 = ((-2.0 * J) * cos((K * 0.5))) * ((U * sqrt((0.25 / (0.5 + (0.5 * cos(K)))))) / J); t_1 = cos((K / 2.0)); t_2 = (-2.0 * J) * t_1; t_3 = t_2 * sqrt((1.0 + ((U / ((2.0 * J) * t_1)) ^ 2.0))); tmp = 0.0; if (t_3 <= -Inf) tmp = t_0; elseif (t_3 <= 5e+307) tmp = t_2 * sqrt((1.0 + (((U * 0.25) / J) * (U / J)))); else tmp = t_0; end tmp_2 = tmp; end
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(U * N[Sqrt[N[(0.25 / N[(0.5 + N[(0.5 * N[Cos[K], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / J), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(-2.0 * J), $MachinePrecision] * t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, (-Infinity)], t$95$0, If[LessEqual[t$95$3, 5e+307], N[(t$95$2 * N[Sqrt[N[(1.0 + N[(N[(N[(U * 0.25), $MachinePrecision] / J), $MachinePrecision] * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \frac{U \cdot \sqrt{\frac{0.25}{0.5 + 0.5 \cdot \cos K}}}{J}\\
t_1 := \cos \left(\frac{K}{2}\right)\\
t_2 := \left(-2 \cdot J\right) \cdot t\_1\\
t_3 := t\_2 \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_1}\right)}^{2}}\\
\mathbf{if}\;t\_3 \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{+307}:\\
\;\;\;\;t\_2 \cdot \sqrt{1 + \frac{U \cdot 0.25}{J} \cdot \frac{U}{J}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\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))))) < -inf.0 or 5e307 < (*.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.3%
Taylor expanded in U around -inf
Applied rewrites13.3%
Applied rewrites13.3%
Taylor expanded in J around -inf
Applied rewrites20.7%
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))))) < 5e307Initial program 73.3%
Taylor expanded in K around 0
Applied rewrites51.9%
Applied rewrites64.8%
(FPCore (J K U)
:precision binary64
(let* ((t_0 (+ 1.0 (* -0.125 (pow K 2.0)))) (t_1 (cos (/ K 2.0))))
(if (<=
(* (* (* -2.0 J) t_1) (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_1)) 2.0))))
5e+307)
(* (* (* -2.0 J) (cos (* K 0.5))) (hypot (* 0.5 (/ U J)) 1.0))
(* (* (hypot (/ U (* (+ J J) t_0)) 1.0) -2.0) (* t_0 J)))))
double code(double J, double K, double U) {
double t_0 = 1.0 + (-0.125 * pow(K, 2.0));
double t_1 = cos((K / 2.0));
double tmp;
if ((((-2.0 * J) * t_1) * sqrt((1.0 + pow((U / ((2.0 * J) * t_1)), 2.0)))) <= 5e+307) {
tmp = ((-2.0 * J) * cos((K * 0.5))) * hypot((0.5 * (U / J)), 1.0);
} else {
tmp = (hypot((U / ((J + J) * t_0)), 1.0) * -2.0) * (t_0 * J);
}
return tmp;
}
public static double code(double J, double K, double U) {
double t_0 = 1.0 + (-0.125 * Math.pow(K, 2.0));
double t_1 = Math.cos((K / 2.0));
double tmp;
if ((((-2.0 * J) * t_1) * Math.sqrt((1.0 + Math.pow((U / ((2.0 * J) * t_1)), 2.0)))) <= 5e+307) {
tmp = ((-2.0 * J) * Math.cos((K * 0.5))) * Math.hypot((0.5 * (U / J)), 1.0);
} else {
tmp = (Math.hypot((U / ((J + J) * t_0)), 1.0) * -2.0) * (t_0 * J);
}
return tmp;
}
def code(J, K, U): t_0 = 1.0 + (-0.125 * math.pow(K, 2.0)) t_1 = math.cos((K / 2.0)) tmp = 0 if (((-2.0 * J) * t_1) * math.sqrt((1.0 + math.pow((U / ((2.0 * J) * t_1)), 2.0)))) <= 5e+307: tmp = ((-2.0 * J) * math.cos((K * 0.5))) * math.hypot((0.5 * (U / J)), 1.0) else: tmp = (math.hypot((U / ((J + J) * t_0)), 1.0) * -2.0) * (t_0 * J) return tmp
function code(J, K, U) t_0 = Float64(1.0 + Float64(-0.125 * (K ^ 2.0))) t_1 = cos(Float64(K / 2.0)) tmp = 0.0 if (Float64(Float64(Float64(-2.0 * J) * t_1) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_1)) ^ 2.0)))) <= 5e+307) tmp = Float64(Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5))) * hypot(Float64(0.5 * Float64(U / J)), 1.0)); else tmp = Float64(Float64(hypot(Float64(U / Float64(Float64(J + J) * t_0)), 1.0) * -2.0) * Float64(t_0 * J)); end return tmp end
function tmp_2 = code(J, K, U) t_0 = 1.0 + (-0.125 * (K ^ 2.0)); t_1 = cos((K / 2.0)); tmp = 0.0; if ((((-2.0 * J) * t_1) * sqrt((1.0 + ((U / ((2.0 * J) * t_1)) ^ 2.0)))) <= 5e+307) tmp = ((-2.0 * J) * cos((K * 0.5))) * hypot((0.5 * (U / J)), 1.0); else tmp = (hypot((U / ((J + J) * t_0)), 1.0) * -2.0) * (t_0 * J); end tmp_2 = tmp; end
code[J_, K_, U_] := Block[{t$95$0 = N[(1.0 + N[(-0.125 * N[Power[K, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$1), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e+307], N[(N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision] ^ 2 + 1.0 ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(U / N[(N[(J + J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] ^ 2 + 1.0 ^ 2], $MachinePrecision] * -2.0), $MachinePrecision] * N[(t$95$0 * J), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + -0.125 \cdot {K}^{2}\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\left(\left(-2 \cdot J\right) \cdot t\_1\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_1}\right)}^{2}} \leq 5 \cdot 10^{+307}:\\
\;\;\;\;\left(\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \mathsf{hypot}\left(0.5 \cdot \frac{U}{J}, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\mathsf{hypot}\left(\frac{U}{\left(J + J\right) \cdot t\_0}, 1\right) \cdot -2\right) \cdot \left(t\_0 \cdot J\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))))) < 5e307Initial program 73.3%
Applied rewrites73.3%
Applied rewrites88.3%
Taylor expanded in K around 0
Applied rewrites73.7%
if 5e307 < (*.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.3%
Applied rewrites73.3%
Applied rewrites88.3%
Applied rewrites88.3%
Taylor expanded in K around 0
Applied rewrites70.9%
Taylor expanded in K around 0
Applied rewrites49.9%
(FPCore (J K U) :precision binary64 (* (* (* -2.0 J) (cos (* K 0.5))) (hypot (* 0.5 (/ U J)) 1.0)))
double code(double J, double K, double U) {
return ((-2.0 * J) * cos((K * 0.5))) * hypot((0.5 * (U / J)), 1.0);
}
public static double code(double J, double K, double U) {
return ((-2.0 * J) * Math.cos((K * 0.5))) * Math.hypot((0.5 * (U / J)), 1.0);
}
def code(J, K, U): return ((-2.0 * J) * math.cos((K * 0.5))) * math.hypot((0.5 * (U / J)), 1.0)
function code(J, K, U) return Float64(Float64(Float64(-2.0 * J) * cos(Float64(K * 0.5))) * hypot(Float64(0.5 * Float64(U / J)), 1.0)) end
function tmp = code(J, K, U) tmp = ((-2.0 * J) * cos((K * 0.5))) * hypot((0.5 * (U / J)), 1.0); end
code[J_, K_, U_] := N[(N[(N[(-2.0 * J), $MachinePrecision] * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(0.5 * N[(U / J), $MachinePrecision]), $MachinePrecision] ^ 2 + 1.0 ^ 2], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(-2 \cdot J\right) \cdot \cos \left(K \cdot 0.5\right)\right) \cdot \mathsf{hypot}\left(0.5 \cdot \frac{U}{J}, 1\right)
\end{array}
Initial program 73.3%
Applied rewrites73.3%
Applied rewrites88.3%
Taylor expanded in K around 0
Applied rewrites73.7%
(FPCore (J K U)
:precision binary64
(let* ((t_0 (fma (* K K) -0.125 1.0))
(t_1 (cos (/ K 2.0)))
(t_2 (* (* -2.0 J) t_1)))
(if (<= (* t_2 (sqrt (+ 1.0 (pow (/ U (* (* 2.0 J) t_1)) 2.0)))) 5e+307)
(* t_2 (sqrt (+ 1.0 (* (/ (* U 0.25) J) (/ U J)))))
(* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (+ J J) t_0)) 2.0)))))))
double code(double J, double K, double U) {
double t_0 = fma((K * K), -0.125, 1.0);
double t_1 = cos((K / 2.0));
double t_2 = (-2.0 * J) * t_1;
double tmp;
if ((t_2 * sqrt((1.0 + pow((U / ((2.0 * J) * t_1)), 2.0)))) <= 5e+307) {
tmp = t_2 * sqrt((1.0 + (((U * 0.25) / J) * (U / J))));
} else {
tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((J + J) * t_0)), 2.0)));
}
return tmp;
}
function code(J, K, U) t_0 = fma(Float64(K * K), -0.125, 1.0) t_1 = cos(Float64(K / 2.0)) t_2 = Float64(Float64(-2.0 * J) * t_1) tmp = 0.0 if (Float64(t_2 * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(2.0 * J) * t_1)) ^ 2.0)))) <= 5e+307) tmp = Float64(t_2 * sqrt(Float64(1.0 + Float64(Float64(Float64(U * 0.25) / J) * Float64(U / J))))); else tmp = Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(J + J) * t_0)) ^ 2.0)))); end return tmp end
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(K * K), $MachinePrecision] * -0.125 + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(-2.0 * J), $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[N[(t$95$2 * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(2.0 * J), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e+307], N[(t$95$2 * N[Sqrt[N[(1.0 + N[(N[(N[(U * 0.25), $MachinePrecision] / J), $MachinePrecision] * N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(J + J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(K \cdot K, -0.125, 1\right)\\
t_1 := \cos \left(\frac{K}{2}\right)\\
t_2 := \left(-2 \cdot J\right) \cdot t\_1\\
\mathbf{if}\;t\_2 \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot t\_1}\right)}^{2}} \leq 5 \cdot 10^{+307}:\\
\;\;\;\;t\_2 \cdot \sqrt{1 + \frac{U \cdot 0.25}{J} \cdot \frac{U}{J}}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(J + J\right) \cdot t\_0}\right)}^{2}}\\
\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))))) < 5e307Initial program 73.3%
Taylor expanded in K around 0
Applied rewrites51.9%
Applied rewrites64.8%
if 5e307 < (*.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.3%
Applied rewrites73.3%
Taylor expanded in K around 0
Applied rewrites39.2%
Taylor expanded in K around 0
Applied rewrites41.2%
Applied rewrites41.2%
Applied rewrites41.2%
(FPCore (J K U)
:precision binary64
(let* ((t_0 (fma (* K K) -0.125 1.0)))
(if (<= K 0.0128)
(* (* (* -2.0 J) t_0) (sqrt (+ 1.0 (pow (/ U (* (+ J J) t_0)) 2.0))))
(* -2.0 (* (cos (* K 0.5)) J)))))
double code(double J, double K, double U) {
double t_0 = fma((K * K), -0.125, 1.0);
double tmp;
if (K <= 0.0128) {
tmp = ((-2.0 * J) * t_0) * sqrt((1.0 + pow((U / ((J + J) * t_0)), 2.0)));
} else {
tmp = -2.0 * (cos((K * 0.5)) * J);
}
return tmp;
}
function code(J, K, U) t_0 = fma(Float64(K * K), -0.125, 1.0) tmp = 0.0 if (K <= 0.0128) tmp = Float64(Float64(Float64(-2.0 * J) * t_0) * sqrt(Float64(1.0 + (Float64(U / Float64(Float64(J + J) * t_0)) ^ 2.0)))); else tmp = Float64(-2.0 * Float64(cos(Float64(K * 0.5)) * J)); end return tmp end
code[J_, K_, U_] := Block[{t$95$0 = N[(N[(K * K), $MachinePrecision] * -0.125 + 1.0), $MachinePrecision]}, If[LessEqual[K, 0.0128], N[(N[(N[(-2.0 * J), $MachinePrecision] * t$95$0), $MachinePrecision] * N[Sqrt[N[(1.0 + N[Power[N[(U / N[(N[(J + J), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(K \cdot K, -0.125, 1\right)\\
\mathbf{if}\;K \leq 0.0128:\\
\;\;\;\;\left(\left(-2 \cdot J\right) \cdot t\_0\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(J + J\right) \cdot t\_0}\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot J\right)\\
\end{array}
\end{array}
if K < 0.0128000000000000006Initial program 73.3%
Applied rewrites73.3%
Taylor expanded in K around 0
Applied rewrites39.2%
Taylor expanded in K around 0
Applied rewrites41.2%
Applied rewrites41.2%
Applied rewrites41.2%
if 0.0128000000000000006 < K Initial program 73.3%
Applied rewrites73.3%
Applied rewrites88.3%
Applied rewrites88.3%
Taylor expanded in J around inf
Applied rewrites52.4%
(FPCore (J K U) :precision binary64 (if (<= K 6.6e-20) (* -2.0 (* J (sqrt (+ 1.0 (* 0.25 (/ (pow U 2.0) (pow J 2.0))))))) (* -2.0 (* (cos (* K 0.5)) J))))
double code(double J, double K, double U) {
double tmp;
if (K <= 6.6e-20) {
tmp = -2.0 * (J * sqrt((1.0 + (0.25 * (pow(U, 2.0) / pow(J, 2.0))))));
} else {
tmp = -2.0 * (cos((K * 0.5)) * J);
}
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, k, u)
use fmin_fmax_functions
real(8), intent (in) :: j
real(8), intent (in) :: k
real(8), intent (in) :: u
real(8) :: tmp
if (k <= 6.6d-20) then
tmp = (-2.0d0) * (j * sqrt((1.0d0 + (0.25d0 * ((u ** 2.0d0) / (j ** 2.0d0))))))
else
tmp = (-2.0d0) * (cos((k * 0.5d0)) * j)
end if
code = tmp
end function
public static double code(double J, double K, double U) {
double tmp;
if (K <= 6.6e-20) {
tmp = -2.0 * (J * Math.sqrt((1.0 + (0.25 * (Math.pow(U, 2.0) / Math.pow(J, 2.0))))));
} else {
tmp = -2.0 * (Math.cos((K * 0.5)) * J);
}
return tmp;
}
def code(J, K, U): tmp = 0 if K <= 6.6e-20: tmp = -2.0 * (J * math.sqrt((1.0 + (0.25 * (math.pow(U, 2.0) / math.pow(J, 2.0)))))) else: tmp = -2.0 * (math.cos((K * 0.5)) * J) return tmp
function code(J, K, U) tmp = 0.0 if (K <= 6.6e-20) tmp = Float64(-2.0 * Float64(J * sqrt(Float64(1.0 + Float64(0.25 * Float64((U ^ 2.0) / (J ^ 2.0))))))); else tmp = Float64(-2.0 * Float64(cos(Float64(K * 0.5)) * J)); end return tmp end
function tmp_2 = code(J, K, U) tmp = 0.0; if (K <= 6.6e-20) tmp = -2.0 * (J * sqrt((1.0 + (0.25 * ((U ^ 2.0) / (J ^ 2.0)))))); else tmp = -2.0 * (cos((K * 0.5)) * J); end tmp_2 = tmp; end
code[J_, K_, U_] := If[LessEqual[K, 6.6e-20], N[(-2.0 * N[(J * N[Sqrt[N[(1.0 + N[(0.25 * N[(N[Power[U, 2.0], $MachinePrecision] / N[Power[J, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;K \leq 6.6 \cdot 10^{-20}:\\
\;\;\;\;-2 \cdot \left(J \cdot \sqrt{1 + 0.25 \cdot \frac{{U}^{2}}{{J}^{2}}}\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot J\right)\\
\end{array}
\end{array}
if K < 6.6e-20Initial program 73.3%
Taylor expanded in K around 0
Applied rewrites33.6%
if 6.6e-20 < K Initial program 73.3%
Applied rewrites73.3%
Applied rewrites88.3%
Applied rewrites88.3%
Taylor expanded in J around inf
Applied rewrites52.4%
(FPCore (J K U) :precision binary64 (* -2.0 (* (cos (* K 0.5)) J)))
double code(double J, double K, double U) {
return -2.0 * (cos((K * 0.5)) * J);
}
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) * (cos((k * 0.5d0)) * j)
end function
public static double code(double J, double K, double U) {
return -2.0 * (Math.cos((K * 0.5)) * J);
}
def code(J, K, U): return -2.0 * (math.cos((K * 0.5)) * J)
function code(J, K, U) return Float64(-2.0 * Float64(cos(Float64(K * 0.5)) * J)) end
function tmp = code(J, K, U) tmp = -2.0 * (cos((K * 0.5)) * J); end
code[J_, K_, U_] := N[(-2.0 * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \left(\cos \left(K \cdot 0.5\right) \cdot J\right)
\end{array}
Initial program 73.3%
Applied rewrites73.3%
Applied rewrites88.3%
Applied rewrites88.3%
Taylor expanded in J around inf
Applied rewrites52.4%
(FPCore (J K U) :precision binary64 (* (fma (* (* J 0.25) K) K (* -2.0 J)) 1.0))
double code(double J, double K, double U) {
return fma(((J * 0.25) * K), K, (-2.0 * J)) * 1.0;
}
function code(J, K, U) return Float64(fma(Float64(Float64(J * 0.25) * K), K, Float64(-2.0 * J)) * 1.0) end
code[J_, K_, U_] := N[(N[(N[(N[(J * 0.25), $MachinePrecision] * K), $MachinePrecision] * K + N[(-2.0 * J), $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(J \cdot 0.25\right) \cdot K, K, -2 \cdot J\right) \cdot 1
\end{array}
Initial program 73.3%
Applied rewrites73.3%
Taylor expanded in J around inf
Applied rewrites52.3%
Taylor expanded in K around 0
Applied rewrites28.6%
Applied rewrites28.6%
(FPCore (J K U) :precision binary64 (* (fma (* K K) (* J 0.25) (* -2.0 J)) 1.0))
double code(double J, double K, double U) {
return fma((K * K), (J * 0.25), (-2.0 * J)) * 1.0;
}
function code(J, K, U) return Float64(fma(Float64(K * K), Float64(J * 0.25), Float64(-2.0 * J)) * 1.0) end
code[J_, K_, U_] := N[(N[(N[(K * K), $MachinePrecision] * N[(J * 0.25), $MachinePrecision] + N[(-2.0 * J), $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(K \cdot K, J \cdot 0.25, -2 \cdot J\right) \cdot 1
\end{array}
Initial program 73.3%
Applied rewrites73.3%
Taylor expanded in J around inf
Applied rewrites52.3%
Taylor expanded in K around 0
Applied rewrites28.6%
Applied rewrites28.5%
herbie shell --seed 2025161
(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)))))