Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.7%
Time: 10.6s
Alternatives: 12
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 12 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.2% 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.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -4 \cdot 10^{+86} \lor \neg \left(t_0 \leq 4 \cdot 10^{-7}\right):\\ \;\;\;\;\cos \left(\frac{K}{2}\right) \cdot \left(t_0 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 -4e+86) (not (<= t_0 4e-7)))
     (+ (* (cos (/ K 2.0)) (* t_0 J)) U)
     (+ U (* 2.0 (* l (* J (cos (* K 0.5)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -4e+86) || !(t_0 <= 4e-7)) {
		tmp = (cos((K / 2.0)) * (t_0 * J)) + U;
	} else {
		tmp = U + (2.0 * (l * (J * 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) :: t_0
    real(8) :: tmp
    t_0 = exp(l) - exp(-l)
    if ((t_0 <= (-4d+86)) .or. (.not. (t_0 <= 4d-7))) then
        tmp = (cos((k / 2.0d0)) * (t_0 * j)) + u
    else
        tmp = u + (2.0d0 * (l * (j * cos((k * 0.5d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -4e+86) || !(t_0 <= 4e-7)) {
		tmp = (Math.cos((K / 2.0)) * (t_0 * J)) + U;
	} else {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -4e+86) or not (t_0 <= 4e-7):
		tmp = (math.cos((K / 2.0)) * (t_0 * J)) + U
	else:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= -4e+86) || !(t_0 <= 4e-7))
		tmp = Float64(Float64(cos(Float64(K / 2.0)) * Float64(t_0 * J)) + U);
	else
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -4e+86) || ~((t_0 <= 4e-7)))
		tmp = (cos((K / 2.0)) * (t_0 * J)) + U;
	else
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -4e+86], N[Not[LessEqual[t$95$0, 4e-7]], $MachinePrecision]], N[(N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 * J), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -4 \cdot 10^{+86} \lor \neg \left(t_0 \leq 4 \cdot 10^{-7}\right):\\
\;\;\;\;\cos \left(\frac{K}{2}\right) \cdot \left(t_0 \cdot J\right) + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -4.0000000000000001e86 or 3.9999999999999998e-7 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

    if -4.0000000000000001e86 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 3.9999999999999998e-7

    1. Initial program 72.1%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -4 \cdot 10^{+86} \lor \neg \left(e^{\ell} - e^{-\ell} \leq 4 \cdot 10^{-7}\right):\\ \;\;\;\;\cos \left(\frac{K}{2}\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]

Alternative 2: 94.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+116}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(t_0 \cdot 0.3333333333333333\right)\right)\\ \mathbf{elif}\;\ell \leq -200:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq 0.0004:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot t_0\right)\right)\\ \mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5))) (t_1 (+ U (* (- (exp l) (exp (- l))) J))))
   (if (<= l -1.35e+116)
     (+ U (* (pow l 3.0) (* J (* t_0 0.3333333333333333))))
     (if (<= l -200.0)
       t_1
       (if (<= l 0.0004)
         (+ U (* 2.0 (* l (* J t_0))))
         (if (<= l 2.35e+80)
           t_1
           (+
            U
            (*
             (cos (/ K 2.0))
             (* J (+ (* (pow l 3.0) 0.3333333333333333) (* l 2.0)))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = U + ((exp(l) - exp(-l)) * J);
	double tmp;
	if (l <= -1.35e+116) {
		tmp = U + (pow(l, 3.0) * (J * (t_0 * 0.3333333333333333)));
	} else if (l <= -200.0) {
		tmp = t_1;
	} else if (l <= 0.0004) {
		tmp = U + (2.0 * (l * (J * t_0)));
	} else if (l <= 2.35e+80) {
		tmp = t_1;
	} else {
		tmp = U + (cos((K / 2.0)) * (J * ((pow(l, 3.0) * 0.3333333333333333) + (l * 2.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) :: t_1
    real(8) :: tmp
    t_0 = cos((k * 0.5d0))
    t_1 = u + ((exp(l) - exp(-l)) * j)
    if (l <= (-1.35d+116)) then
        tmp = u + ((l ** 3.0d0) * (j * (t_0 * 0.3333333333333333d0)))
    else if (l <= (-200.0d0)) then
        tmp = t_1
    else if (l <= 0.0004d0) then
        tmp = u + (2.0d0 * (l * (j * t_0)))
    else if (l <= 2.35d+80) then
        tmp = t_1
    else
        tmp = u + (cos((k / 2.0d0)) * (j * (((l ** 3.0d0) * 0.3333333333333333d0) + (l * 2.0d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = U + ((Math.exp(l) - Math.exp(-l)) * J);
	double tmp;
	if (l <= -1.35e+116) {
		tmp = U + (Math.pow(l, 3.0) * (J * (t_0 * 0.3333333333333333)));
	} else if (l <= -200.0) {
		tmp = t_1;
	} else if (l <= 0.0004) {
		tmp = U + (2.0 * (l * (J * t_0)));
	} else if (l <= 2.35e+80) {
		tmp = t_1;
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (J * ((Math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = U + ((math.exp(l) - math.exp(-l)) * J)
	tmp = 0
	if l <= -1.35e+116:
		tmp = U + (math.pow(l, 3.0) * (J * (t_0 * 0.3333333333333333)))
	elif l <= -200.0:
		tmp = t_1
	elif l <= 0.0004:
		tmp = U + (2.0 * (l * (J * t_0)))
	elif l <= 2.35e+80:
		tmp = t_1
	else:
		tmp = U + (math.cos((K / 2.0)) * (J * ((math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J))
	tmp = 0.0
	if (l <= -1.35e+116)
		tmp = Float64(U + Float64((l ^ 3.0) * Float64(J * Float64(t_0 * 0.3333333333333333))));
	elseif (l <= -200.0)
		tmp = t_1;
	elseif (l <= 0.0004)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * t_0))));
	elseif (l <= 2.35e+80)
		tmp = t_1;
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64((l ^ 3.0) * 0.3333333333333333) + Float64(l * 2.0)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K * 0.5));
	t_1 = U + ((exp(l) - exp(-l)) * J);
	tmp = 0.0;
	if (l <= -1.35e+116)
		tmp = U + ((l ^ 3.0) * (J * (t_0 * 0.3333333333333333)));
	elseif (l <= -200.0)
		tmp = t_1;
	elseif (l <= 0.0004)
		tmp = U + (2.0 * (l * (J * t_0)));
	elseif (l <= 2.35e+80)
		tmp = t_1;
	else
		tmp = U + (cos((K / 2.0)) * (J * (((l ^ 3.0) * 0.3333333333333333) + (l * 2.0))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.35e+116], N[(U + N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * N[(t$95$0 * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -200.0], t$95$1, If[LessEqual[l, 0.0004], N[(U + N[(2.0 * N[(l * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.35e+80], t$95$1, N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -1.35 \cdot 10^{+116}:\\
\;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(t_0 \cdot 0.3333333333333333\right)\right)\\

\mathbf{elif}\;\ell \leq -200:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\ell \leq 0.0004:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot t_0\right)\right)\\

\mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+80}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.35e116

    1. Initial program 100.0%

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

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

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

        \[\leadsto 0.3333333333333333 \cdot \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. *-commutative100.0%

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

        \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right) \cdot \cos \left(K \cdot 0.5\right)} + U \]
      4. *-commutative100.0%

        \[\leadsto \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot 0.3333333333333333\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      5. associate-*r*100.0%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      6. associate-*l*100.0%

        \[\leadsto \color{blue}{{\ell}^{3} \cdot \left(\left(J \cdot 0.3333333333333333\right) \cdot \cos \left(K \cdot 0.5\right)\right)} + U \]
      7. associate-*l*100.0%

        \[\leadsto {\ell}^{3} \cdot \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot \cos \left(K \cdot 0.5\right)\right)\right)} + U \]
      8. *-commutative100.0%

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

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

    if -1.35e116 < l < -200 or 4.00000000000000019e-4 < l < 2.35000000000000005e80

    1. Initial program 100.0%

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

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

    if -200 < l < 4.00000000000000019e-4

    1. Initial program 72.3%

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

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

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

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

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

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

    if 2.35000000000000005e80 < 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. Taylor expanded in l around 0 95.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+116}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 0.3333333333333333\right)\right)\\ \mathbf{elif}\;\ell \leq -200:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.0004:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+80}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\right)\\ \end{array} \]

Alternative 3: 94.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U + {\ell}^{3} \cdot \left(J \cdot \left(t_0 \cdot 0.3333333333333333\right)\right)\\ t_2 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -200:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq 0.00022:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot t_0\right)\right)\\ \mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+80}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5)))
        (t_1 (+ U (* (pow l 3.0) (* J (* t_0 0.3333333333333333)))))
        (t_2 (+ U (* (- (exp l) (exp (- l))) J))))
   (if (<= l -1.35e+116)
     t_1
     (if (<= l -200.0)
       t_2
       (if (<= l 0.00022)
         (+ U (* 2.0 (* l (* J t_0))))
         (if (<= l 2.35e+80) t_2 t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = U + (pow(l, 3.0) * (J * (t_0 * 0.3333333333333333)));
	double t_2 = U + ((exp(l) - exp(-l)) * J);
	double tmp;
	if (l <= -1.35e+116) {
		tmp = t_1;
	} else if (l <= -200.0) {
		tmp = t_2;
	} else if (l <= 0.00022) {
		tmp = U + (2.0 * (l * (J * t_0)));
	} else if (l <= 2.35e+80) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	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) :: t_2
    real(8) :: tmp
    t_0 = cos((k * 0.5d0))
    t_1 = u + ((l ** 3.0d0) * (j * (t_0 * 0.3333333333333333d0)))
    t_2 = u + ((exp(l) - exp(-l)) * j)
    if (l <= (-1.35d+116)) then
        tmp = t_1
    else if (l <= (-200.0d0)) then
        tmp = t_2
    else if (l <= 0.00022d0) then
        tmp = u + (2.0d0 * (l * (j * t_0)))
    else if (l <= 2.35d+80) then
        tmp = t_2
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = U + (Math.pow(l, 3.0) * (J * (t_0 * 0.3333333333333333)));
	double t_2 = U + ((Math.exp(l) - Math.exp(-l)) * J);
	double tmp;
	if (l <= -1.35e+116) {
		tmp = t_1;
	} else if (l <= -200.0) {
		tmp = t_2;
	} else if (l <= 0.00022) {
		tmp = U + (2.0 * (l * (J * t_0)));
	} else if (l <= 2.35e+80) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = U + (math.pow(l, 3.0) * (J * (t_0 * 0.3333333333333333)))
	t_2 = U + ((math.exp(l) - math.exp(-l)) * J)
	tmp = 0
	if l <= -1.35e+116:
		tmp = t_1
	elif l <= -200.0:
		tmp = t_2
	elif l <= 0.00022:
		tmp = U + (2.0 * (l * (J * t_0)))
	elif l <= 2.35e+80:
		tmp = t_2
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(U + Float64((l ^ 3.0) * Float64(J * Float64(t_0 * 0.3333333333333333))))
	t_2 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J))
	tmp = 0.0
	if (l <= -1.35e+116)
		tmp = t_1;
	elseif (l <= -200.0)
		tmp = t_2;
	elseif (l <= 0.00022)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * t_0))));
	elseif (l <= 2.35e+80)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K * 0.5));
	t_1 = U + ((l ^ 3.0) * (J * (t_0 * 0.3333333333333333)));
	t_2 = U + ((exp(l) - exp(-l)) * J);
	tmp = 0.0;
	if (l <= -1.35e+116)
		tmp = t_1;
	elseif (l <= -200.0)
		tmp = t_2;
	elseif (l <= 0.00022)
		tmp = U + (2.0 * (l * (J * t_0)));
	elseif (l <= 2.35e+80)
		tmp = t_2;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * N[(t$95$0 * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.35e+116], t$95$1, If[LessEqual[l, -200.0], t$95$2, If[LessEqual[l, 0.00022], N[(U + N[(2.0 * N[(l * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.35e+80], t$95$2, t$95$1]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := U + {\ell}^{3} \cdot \left(J \cdot \left(t_0 \cdot 0.3333333333333333\right)\right)\\
t_2 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -1.35 \cdot 10^{+116}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\ell \leq -200:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\ell \leq 0.00022:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot t_0\right)\right)\\

\mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+80}:\\
\;\;\;\;t_2\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.35e116 or 2.35000000000000005e80 < 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. Taylor expanded in l around 0 97.7%

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

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left({\ell}^{3} \cdot J\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative97.7%

        \[\leadsto 0.3333333333333333 \cdot \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. *-commutative97.7%

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

        \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right) \cdot \cos \left(K \cdot 0.5\right)} + U \]
      4. *-commutative97.7%

        \[\leadsto \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot 0.3333333333333333\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      5. associate-*r*97.7%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      6. associate-*l*97.7%

        \[\leadsto \color{blue}{{\ell}^{3} \cdot \left(\left(J \cdot 0.3333333333333333\right) \cdot \cos \left(K \cdot 0.5\right)\right)} + U \]
      7. associate-*l*97.7%

        \[\leadsto {\ell}^{3} \cdot \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot \cos \left(K \cdot 0.5\right)\right)\right)} + U \]
      8. *-commutative97.7%

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

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

    if -1.35e116 < l < -200 or 2.20000000000000008e-4 < l < 2.35000000000000005e80

    1. Initial program 100.0%

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

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

    if -200 < l < 2.20000000000000008e-4

    1. Initial program 72.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+116}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 0.3333333333333333\right)\right)\\ \mathbf{elif}\;\ell \leq -200:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.00022:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+80}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot 0.3333333333333333\right)\right)\\ \end{array} \]

Alternative 4: 77.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.94:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) 0.94)
   (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))
   (+ U (* J (+ (* (pow l 3.0) 0.3333333333333333) (* l 2.0))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= 0.94) {
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	} else {
		tmp = U + (J * ((pow(l, 3.0) * 0.3333333333333333) + (l * 2.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) :: tmp
    if (cos((k / 2.0d0)) <= 0.94d0) then
        tmp = u + (2.0d0 * (l * (j * cos((k * 0.5d0)))))
    else
        tmp = u + (j * (((l ** 3.0d0) * 0.3333333333333333d0) + (l * 2.0d0)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (Math.cos((K / 2.0)) <= 0.94) {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	} else {
		tmp = U + (J * ((Math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= 0.94:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	else:
		tmp = U + (J * ((math.pow(l, 3.0) * 0.3333333333333333) + (l * 2.0)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= 0.94)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	else
		tmp = Float64(U + Float64(J * Float64(Float64((l ^ 3.0) * 0.3333333333333333) + Float64(l * 2.0))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (cos((K / 2.0)) <= 0.94)
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	else
		tmp = U + (J * (((l ^ 3.0) * 0.3333333333333333) + (l * 2.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.94], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(N[(N[Power[l, 3.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.94:\\
\;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K 2)) < 0.93999999999999995

    1. Initial program 83.2%

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

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

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

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

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

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

    if 0.93999999999999995 < (cos.f64 (/.f64 K 2))

    1. Initial program 86.7%

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

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

      \[\leadsto \color{blue}{\left(2 \cdot \left(\ell \cdot J\right) + 0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right)} + U \]
    4. Taylor expanded in J around 0 86.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.94:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\\ \end{array} \]

Alternative 5: 86.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{if}\;\ell \leq -200:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 0.00085:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+80}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(0.3333333333333333 + -0.041666666666666664 \cdot \left(K \cdot K\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (- (exp l) (exp (- l))) J))))
   (if (<= l -200.0)
     t_0
     (if (<= l 0.00085)
       (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))
       (if (<= l 2.35e+80)
         t_0
         (+
          U
          (*
           (pow l 3.0)
           (*
            J
            (+ 0.3333333333333333 (* -0.041666666666666664 (* K K)))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((exp(l) - exp(-l)) * J);
	double tmp;
	if (l <= -200.0) {
		tmp = t_0;
	} else if (l <= 0.00085) {
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	} else if (l <= 2.35e+80) {
		tmp = t_0;
	} else {
		tmp = U + (pow(l, 3.0) * (J * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))));
	}
	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 + ((exp(l) - exp(-l)) * j)
    if (l <= (-200.0d0)) then
        tmp = t_0
    else if (l <= 0.00085d0) then
        tmp = u + (2.0d0 * (l * (j * cos((k * 0.5d0)))))
    else if (l <= 2.35d+80) then
        tmp = t_0
    else
        tmp = u + ((l ** 3.0d0) * (j * (0.3333333333333333d0 + ((-0.041666666666666664d0) * (k * k)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + ((Math.exp(l) - Math.exp(-l)) * J);
	double tmp;
	if (l <= -200.0) {
		tmp = t_0;
	} else if (l <= 0.00085) {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	} else if (l <= 2.35e+80) {
		tmp = t_0;
	} else {
		tmp = U + (Math.pow(l, 3.0) * (J * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((math.exp(l) - math.exp(-l)) * J)
	tmp = 0
	if l <= -200.0:
		tmp = t_0
	elif l <= 0.00085:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	elif l <= 2.35e+80:
		tmp = t_0
	else:
		tmp = U + (math.pow(l, 3.0) * (J * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(exp(l) - exp(Float64(-l))) * J))
	tmp = 0.0
	if (l <= -200.0)
		tmp = t_0;
	elseif (l <= 0.00085)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	elseif (l <= 2.35e+80)
		tmp = t_0;
	else
		tmp = Float64(U + Float64((l ^ 3.0) * Float64(J * Float64(0.3333333333333333 + Float64(-0.041666666666666664 * Float64(K * K))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((exp(l) - exp(-l)) * J);
	tmp = 0.0;
	if (l <= -200.0)
		tmp = t_0;
	elseif (l <= 0.00085)
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	elseif (l <= 2.35e+80)
		tmp = t_0;
	else
		tmp = U + ((l ^ 3.0) * (J * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -200.0], t$95$0, If[LessEqual[l, 0.00085], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.35e+80], t$95$0, N[(U + N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * N[(0.3333333333333333 + N[(-0.041666666666666664 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -200:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+80}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(0.3333333333333333 + -0.041666666666666664 \cdot \left(K \cdot K\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -200 or 8.49999999999999953e-4 < l < 2.35000000000000005e80

    1. Initial program 100.0%

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

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

    if -200 < l < 8.49999999999999953e-4

    1. Initial program 72.3%

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

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

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

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

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

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

    if 2.35000000000000005e80 < 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. Taylor expanded in l around 0 95.0%

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

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

        \[\leadsto 0.3333333333333333 \cdot \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. *-commutative95.0%

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

        \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right) \cdot \cos \left(K \cdot 0.5\right)} + U \]
      4. *-commutative95.0%

        \[\leadsto \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot 0.3333333333333333\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      5. associate-*r*95.0%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      6. associate-*l*95.0%

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

        \[\leadsto {\ell}^{3} \cdot \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot \cos \left(K \cdot 0.5\right)\right)\right)} + U \]
      8. *-commutative95.0%

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

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

      \[\leadsto {\ell}^{3} \cdot \left(J \cdot \color{blue}{\left(0.3333333333333333 + -0.041666666666666664 \cdot {K}^{2}\right)}\right) + U \]
    7. Step-by-step derivation
      1. unpow281.8%

        \[\leadsto {\ell}^{3} \cdot \left(J \cdot \left(0.3333333333333333 + -0.041666666666666664 \cdot \color{blue}{\left(K \cdot K\right)}\right)\right) + U \]
    8. Simplified81.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -200:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 0.00085:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.35 \cdot 10^{+80}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(0.3333333333333333 + -0.041666666666666664 \cdot \left(K \cdot K\right)\right)\right)\\ \end{array} \]

Alternative 6: 80.3% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -195 \lor \neg \left(\ell \leq 500\right):\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(0.3333333333333333 + -0.041666666666666664 \cdot \left(K \cdot K\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -195.0) (not (<= l 500.0)))
   (+
    U
    (*
     (pow l 3.0)
     (* J (+ 0.3333333333333333 (* -0.041666666666666664 (* K K))))))
   (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -195.0) || !(l <= 500.0)) {
		tmp = U + (pow(l, 3.0) * (J * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))));
	} else {
		tmp = U + (2.0 * (l * (J * 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 <= (-195.0d0)) .or. (.not. (l <= 500.0d0))) then
        tmp = u + ((l ** 3.0d0) * (j * (0.3333333333333333d0 + ((-0.041666666666666664d0) * (k * k)))))
    else
        tmp = u + (2.0d0 * (l * (j * 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 <= -195.0) || !(l <= 500.0)) {
		tmp = U + (Math.pow(l, 3.0) * (J * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))));
	} else {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -195.0) or not (l <= 500.0):
		tmp = U + (math.pow(l, 3.0) * (J * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))))
	else:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -195.0) || !(l <= 500.0))
		tmp = Float64(U + Float64((l ^ 3.0) * Float64(J * Float64(0.3333333333333333 + Float64(-0.041666666666666664 * Float64(K * K))))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -195.0) || ~((l <= 500.0)))
		tmp = U + ((l ^ 3.0) * (J * (0.3333333333333333 + (-0.041666666666666664 * (K * K)))));
	else
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -195.0], N[Not[LessEqual[l, 500.0]], $MachinePrecision]], N[(U + N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * N[(0.3333333333333333 + N[(-0.041666666666666664 * N[(K * K), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -195 \lor \neg \left(\ell \leq 500\right):\\
\;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(0.3333333333333333 + -0.041666666666666664 \cdot \left(K \cdot K\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -195 or 500 < 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. Taylor expanded in l around 0 73.3%

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

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left({\ell}^{3} \cdot J\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative73.3%

        \[\leadsto 0.3333333333333333 \cdot \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. *-commutative73.3%

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

        \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right) \cdot \cos \left(K \cdot 0.5\right)} + U \]
      4. *-commutative73.3%

        \[\leadsto \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot 0.3333333333333333\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      5. associate-*r*73.3%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      6. associate-*l*73.3%

        \[\leadsto \color{blue}{{\ell}^{3} \cdot \left(\left(J \cdot 0.3333333333333333\right) \cdot \cos \left(K \cdot 0.5\right)\right)} + U \]
      7. associate-*l*73.3%

        \[\leadsto {\ell}^{3} \cdot \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot \cos \left(K \cdot 0.5\right)\right)\right)} + U \]
      8. *-commutative73.3%

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

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

      \[\leadsto {\ell}^{3} \cdot \left(J \cdot \color{blue}{\left(0.3333333333333333 + -0.041666666666666664 \cdot {K}^{2}\right)}\right) + U \]
    7. Step-by-step derivation
      1. unpow263.8%

        \[\leadsto {\ell}^{3} \cdot \left(J \cdot \left(0.3333333333333333 + -0.041666666666666664 \cdot \color{blue}{\left(K \cdot K\right)}\right)\right) + U \]
    8. Simplified63.8%

      \[\leadsto {\ell}^{3} \cdot \left(J \cdot \color{blue}{\left(0.3333333333333333 + -0.041666666666666664 \cdot \left(K \cdot K\right)\right)}\right) + U \]

    if -195 < l < 500

    1. Initial program 72.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -195 \lor \neg \left(\ell \leq 500\right):\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot \left(0.3333333333333333 + -0.041666666666666664 \cdot \left(K \cdot K\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]

Alternative 7: 78.7% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{if}\;\ell \leq -5 \cdot 10^{+39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 3800:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 3 \cdot 10^{+86}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (pow l 3.0) (* J 0.3333333333333333)))))
   (if (<= l -5e+39)
     t_0
     (if (<= l 3800.0)
       (+ U (* 2.0 (* l (* J (cos (* K 0.5))))))
       (if (<= l 3e+86) (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25)))) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (pow(l, 3.0) * (J * 0.3333333333333333));
	double tmp;
	if (l <= -5e+39) {
		tmp = t_0;
	} else if (l <= 3800.0) {
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	} else if (l <= 3e+86) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} 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 + ((l ** 3.0d0) * (j * 0.3333333333333333d0))
    if (l <= (-5d+39)) then
        tmp = t_0
    else if (l <= 3800.0d0) then
        tmp = u + (2.0d0 * (l * (j * cos((k * 0.5d0)))))
    else if (l <= 3d+86) then
        tmp = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
    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 + (Math.pow(l, 3.0) * (J * 0.3333333333333333));
	double tmp;
	if (l <= -5e+39) {
		tmp = t_0;
	} else if (l <= 3800.0) {
		tmp = U + (2.0 * (l * (J * Math.cos((K * 0.5)))));
	} else if (l <= 3e+86) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (math.pow(l, 3.0) * (J * 0.3333333333333333))
	tmp = 0
	if l <= -5e+39:
		tmp = t_0
	elif l <= 3800.0:
		tmp = U + (2.0 * (l * (J * math.cos((K * 0.5)))))
	elif l <= 3e+86:
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64((l ^ 3.0) * Float64(J * 0.3333333333333333)))
	tmp = 0.0
	if (l <= -5e+39)
		tmp = t_0;
	elseif (l <= 3800.0)
		tmp = Float64(U + Float64(2.0 * Float64(l * Float64(J * cos(Float64(K * 0.5))))));
	elseif (l <= 3e+86)
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((l ^ 3.0) * (J * 0.3333333333333333));
	tmp = 0.0;
	if (l <= -5e+39)
		tmp = t_0;
	elseif (l <= 3800.0)
		tmp = U + (2.0 * (l * (J * cos((K * 0.5)))));
	elseif (l <= 3e+86)
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5e+39], t$95$0, If[LessEqual[l, 3800.0], N[(U + N[(2.0 * N[(l * N[(J * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 3e+86], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\
\mathbf{if}\;\ell \leq -5 \cdot 10^{+39}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 3 \cdot 10^{+86}:\\
\;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.00000000000000015e39 or 2.99999999999999977e86 < 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. Taylor expanded in l around 0 88.8%

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

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left({\ell}^{3} \cdot J\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative88.8%

        \[\leadsto 0.3333333333333333 \cdot \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. *-commutative88.8%

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

        \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right) \cdot \cos \left(K \cdot 0.5\right)} + U \]
      4. *-commutative88.8%

        \[\leadsto \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot 0.3333333333333333\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      5. associate-*r*88.8%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      6. associate-*l*88.8%

        \[\leadsto \color{blue}{{\ell}^{3} \cdot \left(\left(J \cdot 0.3333333333333333\right) \cdot \cos \left(K \cdot 0.5\right)\right)} + U \]
      7. associate-*l*88.8%

        \[\leadsto {\ell}^{3} \cdot \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot \cos \left(K \cdot 0.5\right)\right)\right)} + U \]
      8. *-commutative88.8%

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

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

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

    if -5.00000000000000015e39 < l < 3800

    1. Initial program 73.8%

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

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

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

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

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

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

    if 3800 < l < 2.99999999999999977e86

    1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{2 \cdot \left(\ell \cdot J\right) + \left(-0.25 \cdot \left({K}^{2} \cdot \left(\ell \cdot J\right)\right) + U\right)} \]
    6. Step-by-step derivation
      1. associate-+r+31.2%

        \[\leadsto \color{blue}{\left(2 \cdot \left(\ell \cdot J\right) + -0.25 \cdot \left({K}^{2} \cdot \left(\ell \cdot J\right)\right)\right) + U} \]
      2. +-commutative31.2%

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

        \[\leadsto U + \left(2 \cdot \left(\ell \cdot J\right) + \color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)}\right) \]
      4. distribute-rgt-out31.2%

        \[\leadsto U + \color{blue}{\left(\ell \cdot J\right) \cdot \left(2 + -0.25 \cdot {K}^{2}\right)} \]
      5. *-commutative31.2%

        \[\leadsto U + \left(\ell \cdot J\right) \cdot \left(2 + \color{blue}{{K}^{2} \cdot -0.25}\right) \]
      6. unpow231.2%

        \[\leadsto U + \left(\ell \cdot J\right) \cdot \left(2 + \color{blue}{\left(K \cdot K\right)} \cdot -0.25\right) \]
    7. Simplified31.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5 \cdot 10^{+39}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{elif}\;\ell \leq 3800:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 3 \cdot 10^{+86}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \end{array} \]

Alternative 8: 72.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{if}\;\ell \leq -3.4 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 470:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq 1.06 \cdot 10^{+85}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* (pow l 3.0) (* J 0.3333333333333333)))))
   (if (<= l -3.4e-10)
     t_0
     (if (<= l 470.0)
       (+ U (* 2.0 (* l J)))
       (if (<= l 1.06e+85) (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25)))) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (pow(l, 3.0) * (J * 0.3333333333333333));
	double tmp;
	if (l <= -3.4e-10) {
		tmp = t_0;
	} else if (l <= 470.0) {
		tmp = U + (2.0 * (l * J));
	} else if (l <= 1.06e+85) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} 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 + ((l ** 3.0d0) * (j * 0.3333333333333333d0))
    if (l <= (-3.4d-10)) then
        tmp = t_0
    else if (l <= 470.0d0) then
        tmp = u + (2.0d0 * (l * j))
    else if (l <= 1.06d+85) then
        tmp = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
    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 + (Math.pow(l, 3.0) * (J * 0.3333333333333333));
	double tmp;
	if (l <= -3.4e-10) {
		tmp = t_0;
	} else if (l <= 470.0) {
		tmp = U + (2.0 * (l * J));
	} else if (l <= 1.06e+85) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (math.pow(l, 3.0) * (J * 0.3333333333333333))
	tmp = 0
	if l <= -3.4e-10:
		tmp = t_0
	elif l <= 470.0:
		tmp = U + (2.0 * (l * J))
	elif l <= 1.06e+85:
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64((l ^ 3.0) * Float64(J * 0.3333333333333333)))
	tmp = 0.0
	if (l <= -3.4e-10)
		tmp = t_0;
	elseif (l <= 470.0)
		tmp = Float64(U + Float64(2.0 * Float64(l * J)));
	elseif (l <= 1.06e+85)
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((l ^ 3.0) * (J * 0.3333333333333333));
	tmp = 0.0;
	if (l <= -3.4e-10)
		tmp = t_0;
	elseif (l <= 470.0)
		tmp = U + (2.0 * (l * J));
	elseif (l <= 1.06e+85)
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.4e-10], t$95$0, If[LessEqual[l, 470.0], N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.06e+85], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\
\mathbf{if}\;\ell \leq -3.4 \cdot 10^{-10}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 1.06 \cdot 10^{+85}:\\
\;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.40000000000000015e-10 or 1.0600000000000001e85 < l

    1. Initial program 99.6%

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

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

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left({\ell}^{3} \cdot J\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative82.5%

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

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

        \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right)\right) \cdot \cos \left(K \cdot 0.5\right)} + U \]
      4. *-commutative82.5%

        \[\leadsto \color{blue}{\left(\left({\ell}^{3} \cdot J\right) \cdot 0.3333333333333333\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      5. associate-*r*82.5%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)} \cdot \cos \left(K \cdot 0.5\right) + U \]
      6. associate-*l*82.5%

        \[\leadsto \color{blue}{{\ell}^{3} \cdot \left(\left(J \cdot 0.3333333333333333\right) \cdot \cos \left(K \cdot 0.5\right)\right)} + U \]
      7. associate-*l*82.5%

        \[\leadsto {\ell}^{3} \cdot \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot \cos \left(K \cdot 0.5\right)\right)\right)} + U \]
      8. *-commutative82.5%

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

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

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

    if -3.40000000000000015e-10 < l < 470

    1. Initial program 72.2%

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

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

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

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

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

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

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

    if 470 < l < 1.0600000000000001e85

    1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{2 \cdot \left(\ell \cdot J\right) + \left(-0.25 \cdot \left({K}^{2} \cdot \left(\ell \cdot J\right)\right) + U\right)} \]
    6. Step-by-step derivation
      1. associate-+r+31.2%

        \[\leadsto \color{blue}{\left(2 \cdot \left(\ell \cdot J\right) + -0.25 \cdot \left({K}^{2} \cdot \left(\ell \cdot J\right)\right)\right) + U} \]
      2. +-commutative31.2%

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

        \[\leadsto U + \left(2 \cdot \left(\ell \cdot J\right) + \color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)}\right) \]
      4. distribute-rgt-out31.2%

        \[\leadsto U + \color{blue}{\left(\ell \cdot J\right) \cdot \left(2 + -0.25 \cdot {K}^{2}\right)} \]
      5. *-commutative31.2%

        \[\leadsto U + \left(\ell \cdot J\right) \cdot \left(2 + \color{blue}{{K}^{2} \cdot -0.25}\right) \]
      6. unpow231.2%

        \[\leadsto U + \left(\ell \cdot J\right) \cdot \left(2 + \color{blue}{\left(K \cdot K\right)} \cdot -0.25\right) \]
    7. Simplified31.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.4 \cdot 10^{-10}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{elif}\;\ell \leq 470:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \mathbf{elif}\;\ell \leq 1.06 \cdot 10^{+85}:\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \end{array} \]

Alternative 9: 59.5% accurate, 18.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -160 \lor \neg \left(\ell \leq 3800\right):\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -160.0) (not (<= l 3800.0)))
   (+ U (* (* l J) (+ 2.0 (* (* K K) -0.25))))
   (+ U (* 2.0 (* l J)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -160.0) || !(l <= 3800.0)) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} else {
		tmp = U + (2.0 * (l * J));
	}
	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 <= (-160.0d0)) .or. (.not. (l <= 3800.0d0))) then
        tmp = u + ((l * j) * (2.0d0 + ((k * k) * (-0.25d0))))
    else
        tmp = u + (2.0d0 * (l * j))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -160.0) || !(l <= 3800.0)) {
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	} else {
		tmp = U + (2.0 * (l * J));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -160.0) or not (l <= 3800.0):
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)))
	else:
		tmp = U + (2.0 * (l * J))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -160.0) || !(l <= 3800.0))
		tmp = Float64(U + Float64(Float64(l * J) * Float64(2.0 + Float64(Float64(K * K) * -0.25))));
	else
		tmp = Float64(U + Float64(2.0 * Float64(l * J)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -160.0) || ~((l <= 3800.0)))
		tmp = U + ((l * J) * (2.0 + ((K * K) * -0.25)));
	else
		tmp = U + (2.0 * (l * J));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -160.0], N[Not[LessEqual[l, 3800.0]], $MachinePrecision]], N[(U + N[(N[(l * J), $MachinePrecision] * N[(2.0 + N[(N[(K * K), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -160 \lor \neg \left(\ell \leq 3800\right):\\
\;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -160 or 3800 < 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. Taylor expanded in l around 0 28.4%

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

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

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

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

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

      \[\leadsto \color{blue}{2 \cdot \left(\ell \cdot J\right) + \left(-0.25 \cdot \left({K}^{2} \cdot \left(\ell \cdot J\right)\right) + U\right)} \]
    6. Step-by-step derivation
      1. associate-+r+15.8%

        \[\leadsto \color{blue}{\left(2 \cdot \left(\ell \cdot J\right) + -0.25 \cdot \left({K}^{2} \cdot \left(\ell \cdot J\right)\right)\right) + U} \]
      2. +-commutative15.8%

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

        \[\leadsto U + \left(2 \cdot \left(\ell \cdot J\right) + \color{blue}{\left(-0.25 \cdot {K}^{2}\right) \cdot \left(\ell \cdot J\right)}\right) \]
      4. distribute-rgt-out34.3%

        \[\leadsto U + \color{blue}{\left(\ell \cdot J\right) \cdot \left(2 + -0.25 \cdot {K}^{2}\right)} \]
      5. *-commutative34.3%

        \[\leadsto U + \left(\ell \cdot J\right) \cdot \left(2 + \color{blue}{{K}^{2} \cdot -0.25}\right) \]
      6. unpow234.3%

        \[\leadsto U + \left(\ell \cdot J\right) \cdot \left(2 + \color{blue}{\left(K \cdot K\right)} \cdot -0.25\right) \]
    7. Simplified34.3%

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

    if -160 < l < 3800

    1. Initial program 72.3%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -160 \lor \neg \left(\ell \leq 3800\right):\\ \;\;\;\;U + \left(\ell \cdot J\right) \cdot \left(2 + \left(K \cdot K\right) \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(\ell \cdot J\right)\\ \end{array} \]

Alternative 10: 54.2% accurate, 44.6× speedup?

\[\begin{array}{l} \\ U + 2 \cdot \left(\ell \cdot J\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (+ U (* 2.0 (* l J))))
double code(double J, double l, double K, double U) {
	return U + (2.0 * (l * J));
}
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 + (2.0d0 * (l * j))
end function
public static double code(double J, double l, double K, double U) {
	return U + (2.0 * (l * J));
}
def code(J, l, K, U):
	return U + (2.0 * (l * J))
function code(J, l, K, U)
	return Float64(U + Float64(2.0 * Float64(l * J)))
end
function tmp = code(J, l, K, U)
	tmp = U + (2.0 * (l * J));
end
code[J_, l_, K_, U_] := N[(U + N[(2.0 * N[(l * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

    \[\leadsto U + 2 \cdot \left(\ell \cdot J\right) \]

Alternative 11: 39.5% accurate, 61.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 92:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U) :precision binary64 (if (<= l 92.0) U (* U U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 92.0) {
		tmp = U;
	} else {
		tmp = U * 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 (l <= 92.0d0) then
        tmp = u
    else
        tmp = u * u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 92.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= 92.0:
		tmp = U
	else:
		tmp = U * U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= 92.0)
		tmp = U;
	else
		tmp = Float64(U * U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= 92.0)
		tmp = U;
	else
		tmp = U * U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, 92.0], U, N[(U * U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 92:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;U \cdot U\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 92

    1. Initial program 81.3%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*81.3%

        \[\leadsto \color{blue}{J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right)\right)} + U \]
      2. fma-def81.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified81.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Taylor expanded in J around 0 47.9%

      \[\leadsto \color{blue}{U} \]

    if 92 < 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. Step-by-step derivation
      1. associate-*l*100.0%

        \[\leadsto \color{blue}{J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right)\right)} + U \]
      2. fma-def100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Applied egg-rr20.4%

      \[\leadsto \color{blue}{U \cdot U} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification42.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 92:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 12: 36.6% 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 85.2%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Step-by-step derivation
    1. associate-*l*85.2%

      \[\leadsto \color{blue}{J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right)\right)} + U \]
    2. fma-def85.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  3. Simplified85.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  4. Taylor expanded in J around 0 38.4%

    \[\leadsto \color{blue}{U} \]
  5. Final simplification38.4%

    \[\leadsto U \]

Reproduce

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