Maksimov and Kolovsky, Equation (3)

Percentage Accurate: 73.6% → 85.1%
Time: 5.3s
Alternatives: 10
Speedup: 1.0×

Specification

?
\[\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 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}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 73.6% accurate, 1.0× speedup?

\[\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 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}

Alternative 1: 85.1% accurate, 1.0× speedup?

\[\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} \]
(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}
Derivation
  1. Initial program 73.6%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
    2. *-commutativeN/A

      \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
    4. associate-*r*N/A

      \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    5. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
  3. Applied rewrites85.1%

    \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
  4. Add Preprocessing

Alternative 2: 85.1% accurate, 1.0× speedup?

\[\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} \]
(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}
Derivation
  1. Initial program 73.6%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
    2. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    3. associate-*l*N/A

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}\right)} \]
    4. *-commutativeN/A

      \[\leadsto \color{blue}{\left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}\right) \cdot \left(-2 \cdot J\right)} \]
    5. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(\cos \left(\frac{K}{2}\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}\right) \cdot \left(-2 \cdot J\right)} \]
  3. Applied rewrites85.1%

    \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \cos \left(K \cdot -0.5\right)\right) \cdot \left(J \cdot -2\right)} \]
  4. Add Preprocessing

Alternative 3: 71.7% accurate, 0.3× speedup?

\[\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} \]
(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}
Derivation
  1. Split input into 3 regimes
  2. 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

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in U around inf

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \color{blue}{\sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}\right) \]
      2. lower-sqrt.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      3. lower-/.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      5. lower-pow.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      6. lower-pow.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      7. lower-cos.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      8. lower-*.f6412.5

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{0.25}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}\right) \]
    4. Applied rewrites12.5%

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(U \cdot \sqrt{\frac{0.25}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}\right)} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\right)\right)} \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      3. lower-*.f6412.5

        \[\leadsto \color{blue}{\left(\cos \left(\frac{K}{2}\right) \cdot \left(-2 \cdot J\right)\right)} \cdot \left(U \cdot \sqrt{\frac{0.25}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}\right) \]
      4. lift-/.f64N/A

        \[\leadsto \left(\cos \color{blue}{\left(\frac{K}{2}\right)} \cdot \left(-2 \cdot J\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      5. mult-flipN/A

        \[\leadsto \left(\cos \color{blue}{\left(K \cdot \frac{1}{2}\right)} \cdot \left(-2 \cdot J\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      6. metadata-evalN/A

        \[\leadsto \left(\cos \left(K \cdot \color{blue}{\frac{1}{2}}\right) \cdot \left(-2 \cdot J\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      7. *-commutativeN/A

        \[\leadsto \left(\cos \color{blue}{\left(\frac{1}{2} \cdot K\right)} \cdot \left(-2 \cdot J\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      8. lift-*.f6412.5

        \[\leadsto \left(\cos \color{blue}{\left(0.5 \cdot K\right)} \cdot \left(-2 \cdot J\right)\right) \cdot \left(U \cdot \sqrt{\frac{0.25}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}\right) \]
      9. lift-*.f64N/A

        \[\leadsto \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \left(U \cdot \color{blue}{\sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}\right) \]
      10. *-commutativeN/A

        \[\leadsto \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \left(\sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}} \cdot \color{blue}{U}\right) \]
      11. lower-*.f6412.5

        \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \left(\sqrt{\frac{0.25}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}} \cdot \color{blue}{U}\right) \]
    6. Applied rewrites12.6%

      \[\leadsto \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \left(\sqrt{\frac{0.25}{{\left(J \cdot \cos \left(0.5 \cdot K\right)\right)}^{2}}} \cdot U\right)} \]
    7. Taylor expanded in J around 0

      \[\leadsto \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot \sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{\color{blue}{J}} \]
    8. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot \sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \]
      2. lower-*.f64N/A

        \[\leadsto \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot \sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \]
      3. lower-sqrt.f64N/A

        \[\leadsto \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot \sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \]
      4. lower-/.f64N/A

        \[\leadsto \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot \sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \]
      5. lower-pow.f64N/A

        \[\leadsto \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot \sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \]
      6. lower-cos.f64N/A

        \[\leadsto \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot \sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \]
      7. lower-*.f6420.6

        \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot \sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J} \]
    9. Applied rewrites20.6%

      \[\leadsto \left(\cos \left(0.5 \cdot K\right) \cdot \left(-2 \cdot J\right)\right) \cdot \frac{U \cdot \sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{\color{blue}{J}} \]

    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.0

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    3. Applied rewrites85.1%

      \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
    4. Taylor expanded in K around 0

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(\frac{1}{2} \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \color{blue}{\frac{U}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      2. lower-/.f6471.7

        \[\leadsto \left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{\color{blue}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    6. Applied rewrites71.7%

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(0.5 \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right)} \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      2. lift-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \color{blue}{\left(J \cdot -2\right)}\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      3. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot J\right) \cdot -2\right)} \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot J\right) \cdot -2\right)} \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
    8. Applied rewrites64.6%

      \[\leadsto \color{blue}{\left(\left(\sqrt{\mathsf{fma}\left(\frac{U}{J} \cdot 0.5, \frac{U}{J} \cdot 0.5, 1\right)} \cdot J\right) \cdot -2\right)} \cdot \cos \left(K \cdot -0.5\right) \]

    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)))))

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in U around inf

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \color{blue}{\sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}\right) \]
      2. lower-sqrt.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      3. lower-/.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      5. lower-pow.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      6. lower-pow.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      7. lower-cos.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      8. lower-*.f6412.5

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{0.25}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}\right) \]
    4. Applied rewrites12.5%

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(U \cdot \sqrt{\frac{0.25}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}\right)} \]
    5. Taylor expanded in J around -inf

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \color{blue}{\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}}\right)\right) \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{\color{blue}{J}}\right)\right) \]
      2. lower-/.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      3. lower-sqrt.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      4. lower-/.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      5. lower-pow.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      6. lower-cos.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      7. lower-*.f6420.7

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J}\right)\right) \]
    7. Applied rewrites20.7%

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \color{blue}{\frac{\sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J}}\right)\right) \]
    8. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      3. associate-*l*N/A

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right)\right)} \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right)\right)} \]
    9. Applied rewrites20.7%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\left(-\frac{\frac{0.5}{\sqrt{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J}\right) \cdot U\right)\right)} \]
    10. Taylor expanded in J around 0

      \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
    11. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      2. lower-sqrt.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      3. lower-/.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      4. lower-pow.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      5. lower-cos.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      6. lower-*.f6420.5

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\frac{\sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
    12. Applied rewrites20.5%

      \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\frac{\sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 68.4% accurate, 0.3× speedup?

\[\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} \]
(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}
Derivation
  1. Split input into 2 regimes
  2. 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)))))

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in U around inf

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \color{blue}{\sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}\right) \]
      2. lower-sqrt.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      3. lower-/.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      5. lower-pow.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      6. lower-pow.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      7. lower-cos.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{\frac{1}{4}}{{J}^{2} \cdot {\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}\right) \]
      8. lower-*.f6412.5

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \sqrt{\frac{0.25}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}\right) \]
    4. Applied rewrites12.5%

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{\left(U \cdot \sqrt{\frac{0.25}{{J}^{2} \cdot {\cos \left(0.5 \cdot K\right)}^{2}}}\right)} \]
    5. Taylor expanded in J around -inf

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \color{blue}{\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}}\right)\right) \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{\color{blue}{J}}\right)\right) \]
      2. lower-/.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      3. lower-sqrt.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      4. lower-/.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      5. lower-pow.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      6. lower-cos.f64N/A

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      7. lower-*.f6420.7

        \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J}\right)\right) \]
    7. Applied rewrites20.7%

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \color{blue}{\frac{\sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J}}\right)\right) \]
    8. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right) \]
      3. associate-*l*N/A

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right)\right)} \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{K}{2}\right) \cdot \left(U \cdot \left(-1 \cdot \frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J}\right)\right)\right)} \]
    9. Applied rewrites20.7%

      \[\leadsto \color{blue}{\left(-2 \cdot J\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\left(-\frac{\frac{0.5}{\sqrt{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J}\right) \cdot U\right)\right)} \]
    10. Taylor expanded in J around 0

      \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
    11. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      2. lower-sqrt.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      3. lower-/.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      4. lower-pow.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      5. lower-cos.f64N/A

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(\frac{1}{2} \cdot K\right) \cdot \left(\frac{\sqrt{\frac{\frac{1}{4}}{{\cos \left(\frac{1}{2} \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
      6. lower-*.f6420.5

        \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\frac{\sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]
    12. Applied rewrites20.5%

      \[\leadsto \left(-2 \cdot J\right) \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\frac{\sqrt{\frac{0.25}{{\cos \left(0.5 \cdot K\right)}^{2}}}}{J} \cdot U\right)\right) \]

    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.0

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    3. Applied rewrites85.1%

      \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
    4. Taylor expanded in K around 0

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(\frac{1}{2} \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \color{blue}{\frac{U}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      2. lower-/.f6471.7

        \[\leadsto \left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{\color{blue}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    6. Applied rewrites71.7%

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(0.5 \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right)} \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      2. lift-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \color{blue}{\left(J \cdot -2\right)}\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      3. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot J\right) \cdot -2\right)} \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot J\right) \cdot -2\right)} \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
    8. Applied rewrites64.6%

      \[\leadsto \color{blue}{\left(\left(\sqrt{\mathsf{fma}\left(\frac{U}{J} \cdot 0.5, \frac{U}{J} \cdot 0.5, 1\right)} \cdot J\right) \cdot -2\right)} \cdot \cos \left(K \cdot -0.5\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 67.4% accurate, 1.6× speedup?

\[\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} \]
(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}
Derivation
  1. Initial program 73.6%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
    2. *-commutativeN/A

      \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
    4. associate-*r*N/A

      \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    5. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
  3. Applied rewrites85.1%

    \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
  4. Taylor expanded in K around 0

    \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(\frac{1}{2} \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
  5. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \color{blue}{\frac{U}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
    2. lower-/.f6471.7

      \[\leadsto \left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{\color{blue}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
  6. Applied rewrites71.7%

    \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(0.5 \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
  7. Add Preprocessing

Alternative 6: 67.4% accurate, 1.6× speedup?

\[\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} \]
(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}
Derivation
  1. Split input into 2 regimes
  2. if K < 3.4000000000000001e-12

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    3. Applied rewrites85.1%

      \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
    4. Taylor expanded in K around 0

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(\frac{1}{2} \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \color{blue}{\frac{U}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      2. lower-/.f6471.7

        \[\leadsto \left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{\color{blue}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    6. Applied rewrites71.7%

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(0.5 \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    7. Taylor expanded in K around 0

      \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \color{blue}{\left(1 + \frac{-1}{8} \cdot {K}^{2}\right)} \]
    8. Step-by-step derivation
      1. lower-+.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \left(1 + \color{blue}{\frac{-1}{8} \cdot {K}^{2}}\right) \]
      2. lower-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \left(1 + \frac{-1}{8} \cdot \color{blue}{{K}^{2}}\right) \]
      3. lower-pow.f6443.3

        \[\leadsto \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}^{\color{blue}{2}}\right) \]
    9. Applied rewrites43.3%

      \[\leadsto \left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \color{blue}{\left(1 + -0.125 \cdot {K}^{2}\right)} \]

    if 3.4000000000000001e-12 < K

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    3. Applied rewrites85.1%

      \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
    4. Taylor expanded in K around 0

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(\frac{1}{2} \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \color{blue}{\frac{U}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      2. lower-/.f6471.7

        \[\leadsto \left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{\color{blue}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    6. Applied rewrites71.7%

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(0.5 \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right)} \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      2. lift-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \color{blue}{\left(J \cdot -2\right)}\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      3. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot J\right) \cdot -2\right)} \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot J\right) \cdot -2\right)} \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
    8. Applied rewrites64.6%

      \[\leadsto \color{blue}{\left(\left(\sqrt{\mathsf{fma}\left(\frac{U}{J} \cdot 0.5, \frac{U}{J} \cdot 0.5, 1\right)} \cdot J\right) \cdot -2\right)} \cdot \cos \left(K \cdot -0.5\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 62.6% accurate, 1.1× speedup?

\[\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} \]
(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}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.99990000000000001

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    3. Applied rewrites85.1%

      \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
    4. Taylor expanded in J around inf

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(\frac{-1}{2} \cdot K\right)\right)} \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \cos \left(\frac{-1}{2} \cdot K\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\cos \left(\frac{-1}{2} \cdot K\right)}\right) \]
      3. lower-cos.f64N/A

        \[\leadsto -2 \cdot \left(J \cdot \cos \left(\frac{-1}{2} \cdot K\right)\right) \]
      4. lower-*.f6452.6

        \[\leadsto -2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right) \]
    6. Applied rewrites52.6%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right)} \]

    if 0.99990000000000001 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    3. Applied rewrites85.1%

      \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
    4. Taylor expanded in K around 0

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(\frac{1}{2} \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \color{blue}{\frac{U}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot \frac{-1}{2}\right) \]
      2. lower-/.f6471.7

        \[\leadsto \left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{\color{blue}{J}}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    6. Applied rewrites71.7%

      \[\leadsto \left(\cosh \sinh^{-1} \color{blue}{\left(0.5 \cdot \frac{U}{J}\right)} \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right) \]
    7. Taylor expanded in K around 0

      \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \color{blue}{\left(1 + \frac{-1}{8} \cdot {K}^{2}\right)} \]
    8. Step-by-step derivation
      1. lower-+.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \left(1 + \color{blue}{\frac{-1}{8} \cdot {K}^{2}}\right) \]
      2. lower-*.f64N/A

        \[\leadsto \left(\cosh \sinh^{-1} \left(\frac{1}{2} \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \left(1 + \frac{-1}{8} \cdot \color{blue}{{K}^{2}}\right) \]
      3. lower-pow.f6443.3

        \[\leadsto \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}^{\color{blue}{2}}\right) \]
    9. Applied rewrites43.3%

      \[\leadsto \left(\cosh \sinh^{-1} \left(0.5 \cdot \frac{U}{J}\right) \cdot \left(J \cdot -2\right)\right) \cdot \color{blue}{\left(1 + -0.125 \cdot {K}^{2}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 57.1% accurate, 1.3× speedup?

\[\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} \]
(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}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.99990000000000001

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    3. Applied rewrites85.1%

      \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
    4. Taylor expanded in J around inf

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(\frac{-1}{2} \cdot K\right)\right)} \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \cos \left(\frac{-1}{2} \cdot K\right)\right)} \]
      2. lower-*.f64N/A

        \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\cos \left(\frac{-1}{2} \cdot K\right)}\right) \]
      3. lower-cos.f64N/A

        \[\leadsto -2 \cdot \left(J \cdot \cos \left(\frac{-1}{2} \cdot K\right)\right) \]
      4. lower-*.f6452.6

        \[\leadsto -2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right) \]
    6. Applied rewrites52.6%

      \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right)} \]

    if 0.99990000000000001 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 73.6%

      \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    2. Taylor expanded in K around 0

      \[\leadsto \color{blue}{\left(-2 \cdot J + \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right)} \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    3. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(-2, \color{blue}{J}, \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(-2, J, \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(-2, J, \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
      4. lower-pow.f6437.6

        \[\leadsto \mathsf{fma}\left(-2, J, 0.25 \cdot \left(J \cdot {K}^{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    4. Applied rewrites37.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-2, J, 0.25 \cdot \left(J \cdot {K}^{2}\right)\right)} \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(-2, J, \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \mathsf{fma}\left(-2, J, \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right)} \]
      3. lower-*.f6437.6

        \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \mathsf{fma}\left(-2, J, 0.25 \cdot \left(J \cdot {K}^{2}\right)\right)} \]
    6. Applied rewrites37.5%

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{U}{\left(J + J\right) \cdot \cos \left(0.5 \cdot K\right)}\right)}^{2} + 1} \cdot \mathsf{fma}\left(\left(K \cdot K\right) \cdot J, 0.25, -2 \cdot J\right)} \]
    7. Taylor expanded in K around 0

      \[\leadsto \sqrt{{\color{blue}{\left(\frac{1}{2} \cdot \frac{U}{J}\right)}}^{2} + 1} \cdot \mathsf{fma}\left(\left(K \cdot K\right) \cdot J, \frac{1}{4}, -2 \cdot J\right) \]
    8. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \sqrt{{\left(\frac{1}{2} \cdot \color{blue}{\frac{U}{J}}\right)}^{2} + 1} \cdot \mathsf{fma}\left(\left(K \cdot K\right) \cdot J, \frac{1}{4}, -2 \cdot J\right) \]
      2. lower-/.f6437.5

        \[\leadsto \sqrt{{\left(0.5 \cdot \frac{U}{\color{blue}{J}}\right)}^{2} + 1} \cdot \mathsf{fma}\left(\left(K \cdot K\right) \cdot J, 0.25, -2 \cdot J\right) \]
    9. Applied rewrites37.5%

      \[\leadsto \sqrt{{\color{blue}{\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) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 52.6% accurate, 2.6× speedup?

\[\begin{array}{l} \\ -2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right) \end{array} \]
(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}
Derivation
  1. Initial program 73.6%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}}} \]
    2. *-commutativeN/A

      \[\leadsto \color{blue}{\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \color{blue}{\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right)} \]
    4. associate-*r*N/A

      \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
    5. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(\sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \cdot \left(-2 \cdot J\right)\right) \cdot \cos \left(\frac{K}{2}\right)} \]
  3. Applied rewrites85.1%

    \[\leadsto \color{blue}{\left(\cosh \sinh^{-1} \left(\frac{U}{\left(J + J\right) \cdot \cos \left(K \cdot -0.5\right)}\right) \cdot \left(J \cdot -2\right)\right) \cdot \cos \left(K \cdot -0.5\right)} \]
  4. Taylor expanded in J around inf

    \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(\frac{-1}{2} \cdot K\right)\right)} \]
  5. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto -2 \cdot \color{blue}{\left(J \cdot \cos \left(\frac{-1}{2} \cdot K\right)\right)} \]
    2. lower-*.f64N/A

      \[\leadsto -2 \cdot \left(J \cdot \color{blue}{\cos \left(\frac{-1}{2} \cdot K\right)}\right) \]
    3. lower-cos.f64N/A

      \[\leadsto -2 \cdot \left(J \cdot \cos \left(\frac{-1}{2} \cdot K\right)\right) \]
    4. lower-*.f6452.6

      \[\leadsto -2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right) \]
  6. Applied rewrites52.6%

    \[\leadsto \color{blue}{-2 \cdot \left(J \cdot \cos \left(-0.5 \cdot K\right)\right)} \]
  7. Add Preprocessing

Alternative 10: 27.4% accurate, 6.2× speedup?

\[\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} \]
(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}
Derivation
  1. Initial program 73.6%

    \[\left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \sqrt{1 + {\left(\frac{U}{\left(2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)}\right)}^{2}} \]
  2. Taylor expanded in J around inf

    \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{1} \]
  3. Step-by-step derivation
    1. Applied rewrites52.5%

      \[\leadsto \left(\left(-2 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right)\right) \cdot \color{blue}{1} \]
    2. Taylor expanded in K around 0

      \[\leadsto \color{blue}{\left(-2 \cdot J + \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right)} \cdot 1 \]
    3. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(-2, \color{blue}{J}, \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right) \cdot 1 \]
      2. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(-2, J, \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right) \cdot 1 \]
      3. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(-2, J, \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right) \cdot 1 \]
      4. lower-pow.f6427.4

        \[\leadsto \mathsf{fma}\left(-2, J, 0.25 \cdot \left(J \cdot {K}^{2}\right)\right) \cdot 1 \]
    4. Applied rewrites27.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-2, J, 0.25 \cdot \left(J \cdot {K}^{2}\right)\right)} \cdot 1 \]
    5. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \left(-2 \cdot J + \color{blue}{\frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)}\right) \cdot 1 \]
      2. *-commutativeN/A

        \[\leadsto \left(J \cdot -2 + \color{blue}{\frac{1}{4}} \cdot \left(J \cdot {K}^{2}\right)\right) \cdot 1 \]
      3. lower-fma.f6427.4

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{-2}, 0.25 \cdot \left(J \cdot {K}^{2}\right)\right) \cdot 1 \]
      4. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, -2, \frac{1}{4} \cdot \left(J \cdot {K}^{2}\right)\right) \cdot 1 \]
      5. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, -2, \left(J \cdot {K}^{2}\right) \cdot \frac{1}{4}\right) \cdot 1 \]
      6. lower-*.f6427.4

        \[\leadsto \mathsf{fma}\left(J, -2, \left(J \cdot {K}^{2}\right) \cdot 0.25\right) \cdot 1 \]
      7. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, -2, \left(J \cdot {K}^{2}\right) \cdot \frac{1}{4}\right) \cdot 1 \]
      8. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(J, -2, \left({K}^{2} \cdot J\right) \cdot \frac{1}{4}\right) \cdot 1 \]
      9. lower-*.f6427.4

        \[\leadsto \mathsf{fma}\left(J, -2, \left({K}^{2} \cdot J\right) \cdot 0.25\right) \cdot 1 \]
      10. lift-pow.f64N/A

        \[\leadsto \mathsf{fma}\left(J, -2, \left({K}^{2} \cdot J\right) \cdot \frac{1}{4}\right) \cdot 1 \]
      11. unpow2N/A

        \[\leadsto \mathsf{fma}\left(J, -2, \left(\left(K \cdot K\right) \cdot J\right) \cdot \frac{1}{4}\right) \cdot 1 \]
      12. lower-*.f6427.4

        \[\leadsto \mathsf{fma}\left(J, -2, \left(\left(K \cdot K\right) \cdot J\right) \cdot 0.25\right) \cdot 1 \]
    6. Applied rewrites27.4%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{-2}, \left(\left(K \cdot K\right) \cdot J\right) \cdot 0.25\right) \cdot 1 \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, -2, \left(\left(K \cdot K\right) \cdot J\right) \cdot \frac{1}{4}\right) \cdot 1 \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, -2, \left(\left(K \cdot K\right) \cdot J\right) \cdot \frac{1}{4}\right) \cdot 1 \]
      3. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(J, -2, \left(K \cdot \left(K \cdot J\right)\right) \cdot \frac{1}{4}\right) \cdot 1 \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(J, -2, \left(K \cdot \left(K \cdot J\right)\right) \cdot \frac{1}{4}\right) \cdot 1 \]
      5. lower-*.f6427.4

        \[\leadsto \mathsf{fma}\left(J, -2, \left(K \cdot \left(K \cdot J\right)\right) \cdot 0.25\right) \cdot 1 \]
    8. Applied rewrites27.4%

      \[\leadsto \mathsf{fma}\left(J, -2, \left(K \cdot \left(K \cdot J\right)\right) \cdot 0.25\right) \cdot 1 \]
    9. Add Preprocessing

    Reproduce

    ?
    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)))))