Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.3% → 99.4%
Time: 12.4s
Alternatives: 13
Speedup: 1.4×

Specification

?
\[\begin{array}{l} \\ \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
	return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
	return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U):
	return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U)
	return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U)
end
function tmp = code(J, l, K, U)
	tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}

Sampling outcomes in binary64 precision:

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 13 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: 86.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
	return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
	return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U):
	return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U)
	return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U)
end
function tmp = code(J, l, K, U)
	tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}

Alternative 1: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* 2.0 (* J (log1p (expm1 (* l (cos (* K 0.5))))))) U))
double code(double J, double l, double K, double U) {
	return (2.0 * (J * log1p(expm1((l * cos((K * 0.5))))))) + U;
}
public static double code(double J, double l, double K, double U) {
	return (2.0 * (J * Math.log1p(Math.expm1((l * Math.cos((K * 0.5))))))) + U;
}
def code(J, l, K, U):
	return (2.0 * (J * math.log1p(math.expm1((l * math.cos((K * 0.5))))))) + U
function code(J, l, K, U)
	return Float64(Float64(2.0 * Float64(J * log1p(expm1(Float64(l * cos(Float64(K * 0.5))))))) + U)
end
code[J_, l_, K_, U_] := N[(N[(2.0 * N[(J * N[Log[1 + N[(Exp[N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right) + U
\end{array}
Derivation
  1. Initial program 86.8%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 63.3%

    \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  4. Step-by-step derivation
    1. log1p-expm1-u99.8%

      \[\leadsto 2 \cdot \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)}\right) + U \]
    2. *-commutative99.8%

      \[\leadsto 2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right)\right)\right) + U \]
  5. Applied egg-rr99.8%

    \[\leadsto 2 \cdot \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)}\right) + U \]
  6. Final simplification99.8%

    \[\leadsto 2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right) + U \]
  7. Add Preprocessing

Alternative 2: 96.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -4:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 3400:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 6.8 \cdot 10^{+43}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+
          U
          (* (* J (* (pow l 7.0) 0.0003968253968253968)) (cos (/ K 2.0))))))
   (if (<= l -4.0)
     t_0
     (if (<= l 3400.0)
       (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
       (if (<= l 6.8e+43) (+ U (* J (- (exp l) (exp (- l))))) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * (pow(l, 7.0) * 0.0003968253968253968)) * cos((K / 2.0)));
	double tmp;
	if (l <= -4.0) {
		tmp = t_0;
	} else if (l <= 3400.0) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else if (l <= 6.8e+43) {
		tmp = U + (J * (exp(l) - exp(-l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + ((j * ((l ** 7.0d0) * 0.0003968253968253968d0)) * cos((k / 2.0d0)))
    if (l <= (-4.0d0)) then
        tmp = t_0
    else if (l <= 3400.0d0) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else if (l <= 6.8d+43) then
        tmp = u + (j * (exp(l) - exp(-l)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * (Math.pow(l, 7.0) * 0.0003968253968253968)) * Math.cos((K / 2.0)));
	double tmp;
	if (l <= -4.0) {
		tmp = t_0;
	} else if (l <= 3400.0) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else if (l <= 6.8e+43) {
		tmp = U + (J * (Math.exp(l) - Math.exp(-l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((J * (math.pow(l, 7.0) * 0.0003968253968253968)) * math.cos((K / 2.0)))
	tmp = 0
	if l <= -4.0:
		tmp = t_0
	elif l <= 3400.0:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	elif l <= 6.8e+43:
		tmp = U + (J * (math.exp(l) - math.exp(-l)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(J * Float64((l ^ 7.0) * 0.0003968253968253968)) * cos(Float64(K / 2.0))))
	tmp = 0.0
	if (l <= -4.0)
		tmp = t_0;
	elseif (l <= 3400.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	elseif (l <= 6.8e+43)
		tmp = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((J * ((l ^ 7.0) * 0.0003968253968253968)) * cos((K / 2.0)));
	tmp = 0.0;
	if (l <= -4.0)
		tmp = t_0;
	elseif (l <= 3400.0)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	elseif (l <= 6.8e+43)
		tmp = U + (J * (exp(l) - exp(-l)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(J * N[(N[Power[l, 7.0], $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.0], t$95$0, If[LessEqual[l, 3400.0], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6.8e+43], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq -4:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 3400:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 6.8 \cdot 10^{+43}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4 or 6.80000000000000024e43 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 95.0%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + 0.0003968253968253968 \cdot {\ell}^{2}\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative95.0%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{{\ell}^{2} \cdot 0.0003968253968253968}\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified95.0%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + {\ell}^{2} \cdot 0.0003968253968253968\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 95.0%

      \[\leadsto \color{blue}{\left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{7}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    7. Step-by-step derivation
      1. *-commutative95.0%

        \[\leadsto \color{blue}{\left(\left(J \cdot {\ell}^{7}\right) \cdot 0.0003968253968253968\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*95.0%

        \[\leadsto \color{blue}{\left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    8. Simplified95.0%

      \[\leadsto \color{blue}{\left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]

    if -4 < l < 3400

    1. Initial program 73.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 98.8%

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

    if 3400 < l < 6.80000000000000024e43

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 84.6%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4:\\ \;\;\;\;U + \left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq 3400:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 6.8 \cdot 10^{+43}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 96.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -5.5:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 3400:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.2 \cdot 10^{+44}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+
          U
          (* (* J (* (pow l 7.0) 0.0003968253968253968)) (cos (/ K 2.0))))))
   (if (<= l -5.5)
     t_0
     (if (<= l 3400.0)
       (+
        U
        (*
         J
         (* l (* (cos (* K 0.5)) (+ 2.0 (* 0.3333333333333333 (pow l 2.0)))))))
       (if (<= l 1.2e+44) (+ U (* J (- (exp l) (exp (- l))))) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * (pow(l, 7.0) * 0.0003968253968253968)) * cos((K / 2.0)));
	double tmp;
	if (l <= -5.5) {
		tmp = t_0;
	} else if (l <= 3400.0) {
		tmp = U + (J * (l * (cos((K * 0.5)) * (2.0 + (0.3333333333333333 * pow(l, 2.0))))));
	} else if (l <= 1.2e+44) {
		tmp = U + (J * (exp(l) - exp(-l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + ((j * ((l ** 7.0d0) * 0.0003968253968253968d0)) * cos((k / 2.0d0)))
    if (l <= (-5.5d0)) then
        tmp = t_0
    else if (l <= 3400.0d0) then
        tmp = u + (j * (l * (cos((k * 0.5d0)) * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0))))))
    else if (l <= 1.2d+44) then
        tmp = u + (j * (exp(l) - exp(-l)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * (Math.pow(l, 7.0) * 0.0003968253968253968)) * Math.cos((K / 2.0)));
	double tmp;
	if (l <= -5.5) {
		tmp = t_0;
	} else if (l <= 3400.0) {
		tmp = U + (J * (l * (Math.cos((K * 0.5)) * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0))))));
	} else if (l <= 1.2e+44) {
		tmp = U + (J * (Math.exp(l) - Math.exp(-l)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((J * (math.pow(l, 7.0) * 0.0003968253968253968)) * math.cos((K / 2.0)))
	tmp = 0
	if l <= -5.5:
		tmp = t_0
	elif l <= 3400.0:
		tmp = U + (J * (l * (math.cos((K * 0.5)) * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))))
	elif l <= 1.2e+44:
		tmp = U + (J * (math.exp(l) - math.exp(-l)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(J * Float64((l ^ 7.0) * 0.0003968253968253968)) * cos(Float64(K / 2.0))))
	tmp = 0.0
	if (l <= -5.5)
		tmp = t_0;
	elseif (l <= 3400.0)
		tmp = Float64(U + Float64(J * Float64(l * Float64(cos(Float64(K * 0.5)) * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))));
	elseif (l <= 1.2e+44)
		tmp = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((J * ((l ^ 7.0) * 0.0003968253968253968)) * cos((K / 2.0)));
	tmp = 0.0;
	if (l <= -5.5)
		tmp = t_0;
	elseif (l <= 3400.0)
		tmp = U + (J * (l * (cos((K * 0.5)) * (2.0 + (0.3333333333333333 * (l ^ 2.0))))));
	elseif (l <= 1.2e+44)
		tmp = U + (J * (exp(l) - exp(-l)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(J * N[(N[Power[l, 7.0], $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5.5], t$95$0, If[LessEqual[l, 3400.0], N[(U + N[(J * N[(l * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.2e+44], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq -5.5:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 3400:\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 1.2 \cdot 10^{+44}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.5 or 1.20000000000000007e44 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 95.0%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + 0.0003968253968253968 \cdot {\ell}^{2}\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative95.0%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{{\ell}^{2} \cdot 0.0003968253968253968}\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified95.0%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + {\ell}^{2} \cdot 0.0003968253968253968\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around inf 95.0%

      \[\leadsto \color{blue}{\left(0.0003968253968253968 \cdot \left(J \cdot {\ell}^{7}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    7. Step-by-step derivation
      1. *-commutative95.0%

        \[\leadsto \color{blue}{\left(\left(J \cdot {\ell}^{7}\right) \cdot 0.0003968253968253968\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. associate-*l*95.0%

        \[\leadsto \color{blue}{\left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    8. Simplified95.0%

      \[\leadsto \color{blue}{\left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]

    if -5.5 < l < 3400

    1. Initial program 73.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.2%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + 0.0003968253968253968 \cdot {\ell}^{2}\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Step-by-step derivation
      1. *-commutative99.2%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + \color{blue}{{\ell}^{2} \cdot 0.0003968253968253968}\right)\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified99.2%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + {\ell}^{2} \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + {\ell}^{2} \cdot 0.0003968253968253968\right)\right)\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Taylor expanded in l around 0 98.9%

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + \color{blue}{0.3333333333333333 \cdot {\ell}^{2}}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    7. Step-by-step derivation
      1. *-commutative98.9%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + \color{blue}{{\ell}^{2} \cdot 0.3333333333333333}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    8. Simplified98.9%

      \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + \color{blue}{{\ell}^{2} \cdot 0.3333333333333333}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    9. Taylor expanded in J around 0 99.0%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)} + U \]

    if 3400 < l < 1.20000000000000007e44

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 84.6%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.5:\\ \;\;\;\;U + \left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq 3400:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.2 \cdot 10^{+44}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left({\ell}^{7} \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 86.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -8500000000 \lor \neg \left(\ell \leq 3400\right):\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -8500000000.0) (not (<= l 3400.0)))
   (+ U (* J (- (exp l) (exp (- l)))))
   (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -8500000000.0) || !(l <= 3400.0)) {
		tmp = U + (J * (exp(l) - exp(-l)));
	} else {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((l <= (-8500000000.0d0)) .or. (.not. (l <= 3400.0d0))) then
        tmp = u + (j * (exp(l) - exp(-l)))
    else
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -8500000000.0) || !(l <= 3400.0)) {
		tmp = U + (J * (Math.exp(l) - Math.exp(-l)));
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -8500000000.0) or not (l <= 3400.0):
		tmp = U + (J * (math.exp(l) - math.exp(-l)))
	else:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -8500000000.0) || !(l <= 3400.0))
		tmp = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -8500000000.0) || ~((l <= 3400.0)))
		tmp = U + (J * (exp(l) - exp(-l)));
	else
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -8500000000.0], N[Not[LessEqual[l, 3400.0]], $MachinePrecision]], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -8500000000 \lor \neg \left(\ell \leq 3400\right):\\
\;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\

\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -8.5e9 or 3400 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 82.5%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]

    if -8.5e9 < l < 3400

    1. Initial program 74.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 97.3%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8500000000 \lor \neg \left(\ell \leq 3400\right):\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 63.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := J \cdot \frac{2}{\frac{U}{\ell}}\\ \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\ \;\;\;\;U \cdot \left(1 + \left|t\_0\right|\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + t\_0\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* J (/ 2.0 (/ U l)))))
   (if (<= (cos (/ K 2.0)) -0.05) (* U (+ 1.0 (fabs t_0))) (* U (+ 1.0 t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (2.0 / (U / l));
	double tmp;
	if (cos((K / 2.0)) <= -0.05) {
		tmp = U * (1.0 + fabs(t_0));
	} else {
		tmp = U * (1.0 + t_0);
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = j * (2.0d0 / (u / l))
    if (cos((k / 2.0d0)) <= (-0.05d0)) then
        tmp = u * (1.0d0 + abs(t_0))
    else
        tmp = u * (1.0d0 + t_0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = J * (2.0 / (U / l));
	double tmp;
	if (Math.cos((K / 2.0)) <= -0.05) {
		tmp = U * (1.0 + Math.abs(t_0));
	} else {
		tmp = U * (1.0 + t_0);
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (2.0 / (U / l))
	tmp = 0
	if math.cos((K / 2.0)) <= -0.05:
		tmp = U * (1.0 + math.fabs(t_0))
	else:
		tmp = U * (1.0 + t_0)
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(2.0 / Float64(U / l)))
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= -0.05)
		tmp = Float64(U * Float64(1.0 + abs(t_0)));
	else
		tmp = Float64(U * Float64(1.0 + t_0));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = J * (2.0 / (U / l));
	tmp = 0.0;
	if (cos((K / 2.0)) <= -0.05)
		tmp = U * (1.0 + abs(t_0));
	else
		tmp = U * (1.0 + t_0);
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(J * N[(2.0 / N[(U / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], -0.05], N[(U * N[(1.0 + N[Abs[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U * N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := J \cdot \frac{2}{\frac{U}{\ell}}\\
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\
\;\;\;\;U \cdot \left(1 + \left|t\_0\right|\right)\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(1 + t\_0\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < -0.050000000000000003

    1. Initial program 84.3%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 70.5%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*70.5%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*70.5%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified70.5%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 78.5%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*78.5%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified78.5%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 40.2%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*40.2%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified40.2%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    12. Step-by-step derivation
      1. add-sqr-sqrt21.0%

        \[\leadsto U \cdot \left(1 + \color{blue}{\sqrt{2 \cdot \left(J \cdot \frac{\ell}{U}\right)} \cdot \sqrt{2 \cdot \left(J \cdot \frac{\ell}{U}\right)}}\right) \]
      2. sqrt-unprod57.8%

        \[\leadsto U \cdot \left(1 + \color{blue}{\sqrt{\left(2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right) \cdot \left(2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)}}\right) \]
      3. *-commutative57.8%

        \[\leadsto U \cdot \left(1 + \sqrt{\color{blue}{\left(\left(J \cdot \frac{\ell}{U}\right) \cdot 2\right)} \cdot \left(2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)}\right) \]
      4. *-commutative57.8%

        \[\leadsto U \cdot \left(1 + \sqrt{\left(\left(J \cdot \frac{\ell}{U}\right) \cdot 2\right) \cdot \color{blue}{\left(\left(J \cdot \frac{\ell}{U}\right) \cdot 2\right)}}\right) \]
      5. swap-sqr57.8%

        \[\leadsto U \cdot \left(1 + \sqrt{\color{blue}{\left(\left(J \cdot \frac{\ell}{U}\right) \cdot \left(J \cdot \frac{\ell}{U}\right)\right) \cdot \left(2 \cdot 2\right)}}\right) \]
      6. pow257.8%

        \[\leadsto U \cdot \left(1 + \sqrt{\color{blue}{{\left(J \cdot \frac{\ell}{U}\right)}^{2}} \cdot \left(2 \cdot 2\right)}\right) \]
      7. metadata-eval57.8%

        \[\leadsto U \cdot \left(1 + \sqrt{{\left(J \cdot \frac{\ell}{U}\right)}^{2} \cdot \color{blue}{4}}\right) \]
    13. Applied egg-rr57.8%

      \[\leadsto U \cdot \left(1 + \color{blue}{\sqrt{{\left(J \cdot \frac{\ell}{U}\right)}^{2} \cdot 4}}\right) \]
    14. Step-by-step derivation
      1. *-commutative57.8%

        \[\leadsto U \cdot \left(1 + \sqrt{\color{blue}{4 \cdot {\left(J \cdot \frac{\ell}{U}\right)}^{2}}}\right) \]
      2. metadata-eval57.8%

        \[\leadsto U \cdot \left(1 + \sqrt{\color{blue}{\left(2 \cdot 2\right)} \cdot {\left(J \cdot \frac{\ell}{U}\right)}^{2}}\right) \]
      3. unpow257.8%

        \[\leadsto U \cdot \left(1 + \sqrt{\left(2 \cdot 2\right) \cdot \color{blue}{\left(\left(J \cdot \frac{\ell}{U}\right) \cdot \left(J \cdot \frac{\ell}{U}\right)\right)}}\right) \]
      4. swap-sqr57.8%

        \[\leadsto U \cdot \left(1 + \sqrt{\color{blue}{\left(2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right) \cdot \left(2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)}}\right) \]
      5. rem-sqrt-square56.7%

        \[\leadsto U \cdot \left(1 + \color{blue}{\left|2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right|}\right) \]
      6. associate-*r*56.7%

        \[\leadsto U \cdot \left(1 + \left|\color{blue}{\left(2 \cdot J\right) \cdot \frac{\ell}{U}}\right|\right) \]
      7. associate-*r/56.7%

        \[\leadsto U \cdot \left(1 + \left|\color{blue}{\frac{\left(2 \cdot J\right) \cdot \ell}{U}}\right|\right) \]
      8. associate-*l/56.3%

        \[\leadsto U \cdot \left(1 + \left|\color{blue}{\frac{2 \cdot J}{U} \cdot \ell}\right|\right) \]
      9. associate-/r/56.7%

        \[\leadsto U \cdot \left(1 + \left|\color{blue}{\frac{2 \cdot J}{\frac{U}{\ell}}}\right|\right) \]
      10. *-commutative56.7%

        \[\leadsto U \cdot \left(1 + \left|\frac{\color{blue}{J \cdot 2}}{\frac{U}{\ell}}\right|\right) \]
      11. associate-/l*56.7%

        \[\leadsto U \cdot \left(1 + \left|\color{blue}{J \cdot \frac{2}{\frac{U}{\ell}}}\right|\right) \]
    15. Simplified56.7%

      \[\leadsto U \cdot \left(1 + \color{blue}{\left|J \cdot \frac{2}{\frac{U}{\ell}}\right|}\right) \]

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

    1. Initial program 87.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 61.2%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*61.2%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*61.2%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified61.2%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 63.8%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*68.7%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified68.7%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 61.5%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*66.3%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified66.3%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    12. Taylor expanded in J around 0 61.5%

      \[\leadsto U \cdot \left(1 + \color{blue}{2 \cdot \frac{J \cdot \ell}{U}}\right) \]
    13. Step-by-step derivation
      1. associate-*l/57.7%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(\frac{J}{U} \cdot \ell\right)}\right) \]
      2. associate-/r/65.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J}{\frac{U}{\ell}}}\right) \]
      3. associate-/l*65.8%

        \[\leadsto U \cdot \left(1 + \color{blue}{\frac{2 \cdot J}{\frac{U}{\ell}}}\right) \]
      4. *-commutative65.8%

        \[\leadsto U \cdot \left(1 + \frac{\color{blue}{J \cdot 2}}{\frac{U}{\ell}}\right) \]
      5. associate-/l*66.3%

        \[\leadsto U \cdot \left(1 + \color{blue}{J \cdot \frac{2}{\frac{U}{\ell}}}\right) \]
    14. Simplified66.3%

      \[\leadsto U \cdot \left(1 + \color{blue}{J \cdot \frac{2}{\frac{U}{\ell}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.05:\\ \;\;\;\;U \cdot \left(1 + \left|J \cdot \frac{2}{\frac{U}{\ell}}\right|\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + J \cdot \frac{2}{\frac{U}{\ell}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 67.1% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \ell \cdot \cos \left(K \cdot 0.5\right)\\ t_1 := J \cdot \left(\frac{U}{J} + 2 \cdot t\_0\right)\\ \mathbf{if}\;\ell \leq -4000000000000:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq 65000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot t\_0\right)\\ \mathbf{elif}\;\ell \leq 6.2 \cdot 10^{+205}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* l (cos (* K 0.5)))) (t_1 (* J (+ (/ U J) (* 2.0 t_0)))))
   (if (<= l -4000000000000.0)
     t_1
     (if (<= l 65000000.0)
       (+ U (* 2.0 (* J t_0)))
       (if (<= l 6.2e+205) t_1 (* U (+ 1.0 (* 2.0 (* J (/ l U))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = l * cos((K * 0.5));
	double t_1 = J * ((U / J) + (2.0 * t_0));
	double tmp;
	if (l <= -4000000000000.0) {
		tmp = t_1;
	} else if (l <= 65000000.0) {
		tmp = U + (2.0 * (J * t_0));
	} else if (l <= 6.2e+205) {
		tmp = t_1;
	} else {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = l * cos((k * 0.5d0))
    t_1 = j * ((u / j) + (2.0d0 * t_0))
    if (l <= (-4000000000000.0d0)) then
        tmp = t_1
    else if (l <= 65000000.0d0) then
        tmp = u + (2.0d0 * (j * t_0))
    else if (l <= 6.2d+205) then
        tmp = t_1
    else
        tmp = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = l * Math.cos((K * 0.5));
	double t_1 = J * ((U / J) + (2.0 * t_0));
	double tmp;
	if (l <= -4000000000000.0) {
		tmp = t_1;
	} else if (l <= 65000000.0) {
		tmp = U + (2.0 * (J * t_0));
	} else if (l <= 6.2e+205) {
		tmp = t_1;
	} else {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = l * math.cos((K * 0.5))
	t_1 = J * ((U / J) + (2.0 * t_0))
	tmp = 0
	if l <= -4000000000000.0:
		tmp = t_1
	elif l <= 65000000.0:
		tmp = U + (2.0 * (J * t_0))
	elif l <= 6.2e+205:
		tmp = t_1
	else:
		tmp = U * (1.0 + (2.0 * (J * (l / U))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(l * cos(Float64(K * 0.5)))
	t_1 = Float64(J * Float64(Float64(U / J) + Float64(2.0 * t_0)))
	tmp = 0.0
	if (l <= -4000000000000.0)
		tmp = t_1;
	elseif (l <= 65000000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * t_0)));
	elseif (l <= 6.2e+205)
		tmp = t_1;
	else
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = l * cos((K * 0.5));
	t_1 = J * ((U / J) + (2.0 * t_0));
	tmp = 0.0;
	if (l <= -4000000000000.0)
		tmp = t_1;
	elseif (l <= 65000000.0)
		tmp = U + (2.0 * (J * t_0));
	elseif (l <= 6.2e+205)
		tmp = t_1;
	else
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(J * N[(N[(U / J), $MachinePrecision] + N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4000000000000.0], t$95$1, If[LessEqual[l, 65000000.0], N[(U + N[(2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6.2e+205], t$95$1, N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \ell \cdot \cos \left(K \cdot 0.5\right)\\
t_1 := J \cdot \left(\frac{U}{J} + 2 \cdot t\_0\right)\\
\mathbf{if}\;\ell \leq -4000000000000:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq 65000000:\\
\;\;\;\;U + 2 \cdot \left(J \cdot t\_0\right)\\

\mathbf{elif}\;\ell \leq 6.2 \cdot 10^{+205}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4e12 or 6.5e7 < l < 6.20000000000000035e205

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 23.9%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*23.9%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*23.9%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified23.9%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in J around inf 38.9%

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right) + \frac{U}{J}\right)} \]

    if -4e12 < l < 6.5e7

    1. Initial program 74.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 95.2%

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

    if 6.20000000000000035e205 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 50.4%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*50.4%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*50.4%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified50.4%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 62.7%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*87.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified87.8%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 54.0%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*79.1%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified79.1%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification71.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4000000000000:\\ \;\;\;\;J \cdot \left(\frac{U}{J} + 2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 65000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 6.2 \cdot 10^{+205}:\\ \;\;\;\;J \cdot \left(\frac{U}{J} + 2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 58.6% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-239}:\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{elif}\;\frac{K}{2} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;U \cdot \left(1 + J \cdot \frac{2}{\frac{U}{\ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (/ K 2.0) 5e-239)
   (* J (+ (* 2.0 l) (/ U J)))
   (if (<= (/ K 2.0) 2e-21)
     (* U (+ 1.0 (* J (/ 2.0 (/ U l)))))
     (+ U (* 2.0 (* J (* l (cos (* K 0.5)))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-239) {
		tmp = J * ((2.0 * l) + (U / J));
	} else if ((K / 2.0) <= 2e-21) {
		tmp = U * (1.0 + (J * (2.0 / (U / l))));
	} else {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((k / 2.0d0) <= 5d-239) then
        tmp = j * ((2.0d0 * l) + (u / j))
    else if ((k / 2.0d0) <= 2d-21) then
        tmp = u * (1.0d0 + (j * (2.0d0 / (u / l))))
    else
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-239) {
		tmp = J * ((2.0 * l) + (U / J));
	} else if ((K / 2.0) <= 2e-21) {
		tmp = U * (1.0 + (J * (2.0 / (U / l))));
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (K / 2.0) <= 5e-239:
		tmp = J * ((2.0 * l) + (U / J))
	elif (K / 2.0) <= 2e-21:
		tmp = U * (1.0 + (J * (2.0 / (U / l))))
	else:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (Float64(K / 2.0) <= 5e-239)
		tmp = Float64(J * Float64(Float64(2.0 * l) + Float64(U / J)));
	elseif (Float64(K / 2.0) <= 2e-21)
		tmp = Float64(U * Float64(1.0 + Float64(J * Float64(2.0 / Float64(U / l)))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((K / 2.0) <= 5e-239)
		tmp = J * ((2.0 * l) + (U / J));
	elseif ((K / 2.0) <= 2e-21)
		tmp = U * (1.0 + (J * (2.0 / (U / l))));
	else
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 5e-239], N[(J * N[(N[(2.0 * l), $MachinePrecision] + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(K / 2.0), $MachinePrecision], 2e-21], N[(U * N[(1.0 + N[(J * N[(2.0 / N[(U / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-239}:\\
\;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\

\mathbf{elif}\;\frac{K}{2} \leq 2 \cdot 10^{-21}:\\
\;\;\;\;U \cdot \left(1 + J \cdot \frac{2}{\frac{U}{\ell}}\right)\\

\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 K #s(literal 2 binary64)) < 5e-239

    1. Initial program 83.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.8%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*64.8%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*64.8%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified64.8%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 67.6%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*71.4%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified71.4%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 55.5%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*59.3%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified59.3%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    12. Taylor expanded in J around inf 55.7%

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)} \]

    if 5e-239 < (/.f64 K #s(literal 2 binary64)) < 1.99999999999999982e-21

    1. Initial program 89.4%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 61.9%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*61.9%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*61.9%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified61.9%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 66.6%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*73.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified73.8%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 66.6%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*73.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified73.8%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    12. Taylor expanded in J around 0 66.6%

      \[\leadsto U \cdot \left(1 + \color{blue}{2 \cdot \frac{J \cdot \ell}{U}}\right) \]
    13. Step-by-step derivation
      1. associate-*l/61.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(\frac{J}{U} \cdot \ell\right)}\right) \]
      2. associate-/r/73.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J}{\frac{U}{\ell}}}\right) \]
      3. associate-/l*73.8%

        \[\leadsto U \cdot \left(1 + \color{blue}{\frac{2 \cdot J}{\frac{U}{\ell}}}\right) \]
      4. *-commutative73.8%

        \[\leadsto U \cdot \left(1 + \frac{\color{blue}{J \cdot 2}}{\frac{U}{\ell}}\right) \]
      5. associate-/l*73.8%

        \[\leadsto U \cdot \left(1 + \color{blue}{J \cdot \frac{2}{\frac{U}{\ell}}}\right) \]
    14. Simplified73.8%

      \[\leadsto U \cdot \left(1 + \color{blue}{J \cdot \frac{2}{\frac{U}{\ell}}}\right) \]

    if 1.99999999999999982e-21 < (/.f64 K #s(literal 2 binary64))

    1. Initial program 93.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 60.6%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-239}:\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{elif}\;\frac{K}{2} \leq 2 \cdot 10^{-21}:\\ \;\;\;\;U \cdot \left(1 + J \cdot \frac{2}{\frac{U}{\ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 60.6% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-239}:\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (/ K 2.0) 5e-239)
   (* J (+ (* 2.0 l) (/ U J)))
   (* U (+ 1.0 (* 2.0 (* J (/ (* l (cos (* K 0.5))) U)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-239) {
		tmp = J * ((2.0 * l) + (U / J));
	} else {
		tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((k / 2.0d0) <= 5d-239) then
        tmp = j * ((2.0d0 * l) + (u / j))
    else
        tmp = u * (1.0d0 + (2.0d0 * (j * ((l * cos((k * 0.5d0))) / u))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-239) {
		tmp = J * ((2.0 * l) + (U / J));
	} else {
		tmp = U * (1.0 + (2.0 * (J * ((l * Math.cos((K * 0.5))) / U))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (K / 2.0) <= 5e-239:
		tmp = J * ((2.0 * l) + (U / J))
	else:
		tmp = U * (1.0 + (2.0 * (J * ((l * math.cos((K * 0.5))) / U))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (Float64(K / 2.0) <= 5e-239)
		tmp = Float64(J * Float64(Float64(2.0 * l) + Float64(U / J)));
	else
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(Float64(l * cos(Float64(K * 0.5))) / U)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((K / 2.0) <= 5e-239)
		tmp = J * ((2.0 * l) + (U / J));
	else
		tmp = U * (1.0 + (2.0 * (J * ((l * cos((K * 0.5))) / U))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 5e-239], N[(J * N[(N[(2.0 * l), $MachinePrecision] + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-239}:\\
\;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 K #s(literal 2 binary64)) < 5e-239

    1. Initial program 83.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.8%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*64.8%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*64.8%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified64.8%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 67.6%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*71.4%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified71.4%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 55.5%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*59.3%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified59.3%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    12. Taylor expanded in J around inf 55.7%

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)} \]

    if 5e-239 < (/.f64 K #s(literal 2 binary64))

    1. Initial program 92.2%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 61.1%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*61.1%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*61.1%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified61.1%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 66.5%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*70.1%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified70.1%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-239}:\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(K \cdot 0.5\right)}{U}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 57.1% accurate, 16.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4300000000000 \lor \neg \left(\ell \leq 65000000\right):\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \ell\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -4300000000000.0) (not (<= l 65000000.0)))
   (* J (+ (* 2.0 l) (/ U J)))
   (+ U (* J (* 2.0 l)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -4300000000000.0) || !(l <= 65000000.0)) {
		tmp = J * ((2.0 * l) + (U / J));
	} else {
		tmp = U + (J * (2.0 * l));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((l <= (-4300000000000.0d0)) .or. (.not. (l <= 65000000.0d0))) then
        tmp = j * ((2.0d0 * l) + (u / j))
    else
        tmp = u + (j * (2.0d0 * l))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -4300000000000.0) || !(l <= 65000000.0)) {
		tmp = J * ((2.0 * l) + (U / J));
	} else {
		tmp = U + (J * (2.0 * l));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -4300000000000.0) or not (l <= 65000000.0):
		tmp = J * ((2.0 * l) + (U / J))
	else:
		tmp = U + (J * (2.0 * l))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -4300000000000.0) || !(l <= 65000000.0))
		tmp = Float64(J * Float64(Float64(2.0 * l) + Float64(U / J)));
	else
		tmp = Float64(U + Float64(J * Float64(2.0 * l)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -4300000000000.0) || ~((l <= 65000000.0)))
		tmp = J * ((2.0 * l) + (U / J));
	else
		tmp = U + (J * (2.0 * l));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -4300000000000.0], N[Not[LessEqual[l, 65000000.0]], $MachinePrecision]], N[(J * N[(N[(2.0 * l), $MachinePrecision] + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4300000000000 \lor \neg \left(\ell \leq 65000000\right):\\
\;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(2 \cdot \ell\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.3e12 or 6.5e7 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 28.8%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*28.8%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*28.8%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified28.8%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 38.8%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*46.6%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified46.6%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 29.5%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*37.4%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified37.4%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    12. Taylor expanded in J around inf 35.6%

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)} \]

    if -4.3e12 < l < 6.5e7

    1. Initial program 74.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 95.2%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*95.2%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*95.1%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified95.1%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in K around 0 83.5%

      \[\leadsto \color{blue}{U + 2 \cdot \left(J \cdot \ell\right)} \]
    7. Step-by-step derivation
      1. *-commutative83.5%

        \[\leadsto U + \color{blue}{\left(J \cdot \ell\right) \cdot 2} \]
      2. associate-*r*83.5%

        \[\leadsto U + \color{blue}{J \cdot \left(\ell \cdot 2\right)} \]
    8. Simplified83.5%

      \[\leadsto \color{blue}{U + J \cdot \left(\ell \cdot 2\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification60.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4300000000000 \lor \neg \left(\ell \leq 65000000\right):\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \ell\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 55.1% accurate, 17.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-239}:\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + J \cdot \frac{2}{\frac{U}{\ell}}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (/ K 2.0) 5e-239)
   (* J (+ (* 2.0 l) (/ U J)))
   (* U (+ 1.0 (* J (/ 2.0 (/ U l)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-239) {
		tmp = J * ((2.0 * l) + (U / J));
	} else {
		tmp = U * (1.0 + (J * (2.0 / (U / l))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((k / 2.0d0) <= 5d-239) then
        tmp = j * ((2.0d0 * l) + (u / j))
    else
        tmp = u * (1.0d0 + (j * (2.0d0 / (u / l))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-239) {
		tmp = J * ((2.0 * l) + (U / J));
	} else {
		tmp = U * (1.0 + (J * (2.0 / (U / l))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (K / 2.0) <= 5e-239:
		tmp = J * ((2.0 * l) + (U / J))
	else:
		tmp = U * (1.0 + (J * (2.0 / (U / l))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (Float64(K / 2.0) <= 5e-239)
		tmp = Float64(J * Float64(Float64(2.0 * l) + Float64(U / J)));
	else
		tmp = Float64(U * Float64(1.0 + Float64(J * Float64(2.0 / Float64(U / l)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((K / 2.0) <= 5e-239)
		tmp = J * ((2.0 * l) + (U / J));
	else
		tmp = U * (1.0 + (J * (2.0 / (U / l))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 5e-239], N[(J * N[(N[(2.0 * l), $MachinePrecision] + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U * N[(1.0 + N[(J * N[(2.0 / N[(U / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-239}:\\
\;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(1 + J \cdot \frac{2}{\frac{U}{\ell}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 K #s(literal 2 binary64)) < 5e-239

    1. Initial program 83.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.8%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*64.8%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*64.8%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified64.8%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 67.6%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*71.4%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified71.4%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 55.5%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*59.3%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified59.3%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    12. Taylor expanded in J around inf 55.7%

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)} \]

    if 5e-239 < (/.f64 K #s(literal 2 binary64))

    1. Initial program 92.2%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 61.1%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*61.1%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*61.1%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified61.1%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 66.5%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*70.1%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified70.1%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 58.3%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*62.0%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified62.0%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    12. Taylor expanded in J around 0 58.3%

      \[\leadsto U \cdot \left(1 + \color{blue}{2 \cdot \frac{J \cdot \ell}{U}}\right) \]
    13. Step-by-step derivation
      1. associate-*l/56.2%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(\frac{J}{U} \cdot \ell\right)}\right) \]
      2. associate-/r/61.1%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J}{\frac{U}{\ell}}}\right) \]
      3. associate-/l*61.1%

        \[\leadsto U \cdot \left(1 + \color{blue}{\frac{2 \cdot J}{\frac{U}{\ell}}}\right) \]
      4. *-commutative61.1%

        \[\leadsto U \cdot \left(1 + \frac{\color{blue}{J \cdot 2}}{\frac{U}{\ell}}\right) \]
      5. associate-/l*62.0%

        \[\leadsto U \cdot \left(1 + \color{blue}{J \cdot \frac{2}{\frac{U}{\ell}}}\right) \]
    14. Simplified62.0%

      \[\leadsto U \cdot \left(1 + \color{blue}{J \cdot \frac{2}{\frac{U}{\ell}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-239}:\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + J \cdot \frac{2}{\frac{U}{\ell}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 55.0% accurate, 19.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;K \leq 2.2 \cdot 10^{-236}:\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= K 2.2e-236)
   (* J (+ (* 2.0 l) (/ U J)))
   (* U (+ 1.0 (* 2.0 (* J (/ l U)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (K <= 2.2e-236) {
		tmp = J * ((2.0 * l) + (U / J));
	} else {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (k <= 2.2d-236) then
        tmp = j * ((2.0d0 * l) + (u / j))
    else
        tmp = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (K <= 2.2e-236) {
		tmp = J * ((2.0 * l) + (U / J));
	} else {
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if K <= 2.2e-236:
		tmp = J * ((2.0 * l) + (U / J))
	else:
		tmp = U * (1.0 + (2.0 * (J * (l / U))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (K <= 2.2e-236)
		tmp = Float64(J * Float64(Float64(2.0 * l) + Float64(U / J)));
	else
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (K <= 2.2e-236)
		tmp = J * ((2.0 * l) + (U / J));
	else
		tmp = U * (1.0 + (2.0 * (J * (l / U))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[K, 2.2e-236], N[(J * N[(N[(2.0 * l), $MachinePrecision] + N[(U / J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;K \leq 2.2 \cdot 10^{-236}:\\
\;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 2.19999999999999992e-236

    1. Initial program 83.1%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 64.8%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*64.8%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*64.8%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified64.8%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 67.6%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*71.4%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified71.4%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 55.5%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*59.3%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified59.3%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    12. Taylor expanded in J around inf 55.7%

      \[\leadsto \color{blue}{J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)} \]

    if 2.19999999999999992e-236 < K

    1. Initial program 92.2%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 61.1%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. associate-*r*61.1%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. associate-*r*61.1%

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    5. Simplified61.1%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
    6. Taylor expanded in U around inf 66.5%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    7. Step-by-step derivation
      1. associate-/l*70.1%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)}\right) \]
    8. Simplified70.1%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell \cdot \cos \left(0.5 \cdot K\right)}{U}\right)\right)} \]
    9. Taylor expanded in K around 0 58.3%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\frac{J \cdot \ell}{U}}\right) \]
    10. Step-by-step derivation
      1. associate-/l*62.0%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified62.0%

      \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;K \leq 2.2 \cdot 10^{-236}:\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 54.0% accurate, 44.6× speedup?

\[\begin{array}{l} \\ U + J \cdot \left(2 \cdot \ell\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (+ U (* J (* 2.0 l))))
double code(double J, double l, double K, double U) {
	return U + (J * (2.0 * l));
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u + (j * (2.0d0 * l))
end function
public static double code(double J, double l, double K, double U) {
	return U + (J * (2.0 * l));
}
def code(J, l, K, U):
	return U + (J * (2.0 * l))
function code(J, l, K, U)
	return Float64(U + Float64(J * Float64(2.0 * l)))
end
function tmp = code(J, l, K, U)
	tmp = U + (J * (2.0 * l));
end
code[J_, l_, K_, U_] := N[(U + N[(J * N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + J \cdot \left(2 \cdot \ell\right)
\end{array}
Derivation
  1. Initial program 86.8%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 63.3%

    \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  4. Step-by-step derivation
    1. associate-*r*63.3%

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    2. associate-*r*63.3%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
  5. Simplified63.3%

    \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
  6. Taylor expanded in K around 0 54.2%

    \[\leadsto \color{blue}{U + 2 \cdot \left(J \cdot \ell\right)} \]
  7. Step-by-step derivation
    1. *-commutative54.2%

      \[\leadsto U + \color{blue}{\left(J \cdot \ell\right) \cdot 2} \]
    2. associate-*r*54.2%

      \[\leadsto U + \color{blue}{J \cdot \left(\ell \cdot 2\right)} \]
  8. Simplified54.2%

    \[\leadsto \color{blue}{U + J \cdot \left(\ell \cdot 2\right)} \]
  9. Final simplification54.2%

    \[\leadsto U + J \cdot \left(2 \cdot \ell\right) \]
  10. Add Preprocessing

Alternative 13: 37.1% accurate, 312.0× speedup?

\[\begin{array}{l} \\ U \end{array} \]
(FPCore (J l K U) :precision binary64 U)
double code(double J, double l, double K, double U) {
	return U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u
end function
public static double code(double J, double l, double K, double U) {
	return U;
}
def code(J, l, K, U):
	return U
function code(J, l, K, U)
	return U
end
function tmp = code(J, l, K, U)
	tmp = U;
end
code[J_, l_, K_, U_] := U
\begin{array}{l}

\\
U
\end{array}
Derivation
  1. Initial program 86.8%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in l around 0 63.3%

    \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  4. Step-by-step derivation
    1. associate-*r*63.3%

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    2. associate-*r*63.3%

      \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
  5. Simplified63.3%

    \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)} + U \]
  6. Taylor expanded in J around 0 36.9%

    \[\leadsto \color{blue}{U} \]
  7. Final simplification36.9%

    \[\leadsto U \]
  8. Add Preprocessing

Reproduce

?
herbie shell --seed 2024060 
(FPCore (J l K U)
  :name "Maksimov and Kolovsky, Equation (4)"
  :precision binary64
  (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))