Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.7%
Time: 12.8s
Alternatives: 10
Speedup: 1.5×

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 10 alternatives:

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

Initial Program: 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 -\infty \lor \neg \left(t_0 \leq 10^{-8}\right):\\ \;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(2 \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 (- INFINITY)) (not (<= t_0 1e-8)))
     (+ (* (* t_0 J) (cos (/ K 2.0))) U)
     (+ U (* l (* 2.0 (* 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 <= -((double) INFINITY)) || !(t_0 <= 1e-8)) {
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = U + (l * (2.0 * (J * cos((K * 0.5)))));
	}
	return tmp;
}
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 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 1e-8)) {
		tmp = ((t_0 * J) * Math.cos((K / 2.0))) + U;
	} else {
		tmp = U + (l * (2.0 * (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 <= -math.inf) or not (t_0 <= 1e-8):
		tmp = ((t_0 * J) * math.cos((K / 2.0))) + U
	else:
		tmp = U + (l * (2.0 * (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 <= Float64(-Inf)) || !(t_0 <= 1e-8))
		tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U + Float64(l * Float64(2.0 * 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 <= -Inf) || ~((t_0 <= 1e-8)))
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	else
		tmp = U + (l * (2.0 * (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, (-Infinity)], N[Not[LessEqual[t$95$0, 1e-8]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(l * N[(2.0 * 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 -\infty \lor \neg \left(t_0 \leq 10^{-8}\right):\\
\;\;\;\;\left(t_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\

\mathbf{else}:\\
\;\;\;\;U + \ell \cdot \left(2 \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))) < -inf.0 or 1e-8 < (-.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 -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 1e-8

    1. Initial program 70.9%

      \[\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(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

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

Alternative 2: 94.5% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.00166:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+77}:\\
\;\;\;\;t_0\\

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


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

    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 \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. Taylor expanded in l around inf 100.0%

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

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

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

    if -1.35e91 < l < -0.00166 or 0.00110000000000000007 < l < 1.9000000000000001e77

    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 83.3%

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

    if -0.00166 < l < 0.00110000000000000007

    1. Initial program 70.9%

      \[\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(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

    if 1.9000000000000001e77 < 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.8%

      \[\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 simplification97.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+91}:\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot \left(\cos \left(K \cdot 0.5\right) \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -0.00166:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 0.0011:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+77}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \end{array} \]

Alternative 3: 94.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U + \left(J \cdot 0.3333333333333333\right) \cdot \left(t_0 \cdot {\ell}^{3}\right)\\ t_2 := \left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq -0.0095:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\ell \leq 0.00045:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot t_0\right)\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+77}:\\ \;\;\;\;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 (* (* J 0.3333333333333333) (* t_0 (pow l 3.0)))))
        (t_2 (+ (* (- (exp l) (exp (- l))) J) U)))
   (if (<= l -1.35e+91)
     t_1
     (if (<= l -0.0095)
       t_2
       (if (<= l 0.00045)
         (+ U (* l (* 2.0 (* J t_0))))
         (if (<= l 1.9e+77) 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 + ((J * 0.3333333333333333) * (t_0 * pow(l, 3.0)));
	double t_2 = ((exp(l) - exp(-l)) * J) + U;
	double tmp;
	if (l <= -1.35e+91) {
		tmp = t_1;
	} else if (l <= -0.0095) {
		tmp = t_2;
	} else if (l <= 0.00045) {
		tmp = U + (l * (2.0 * (J * t_0)));
	} else if (l <= 1.9e+77) {
		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 + ((j * 0.3333333333333333d0) * (t_0 * (l ** 3.0d0)))
    t_2 = ((exp(l) - exp(-l)) * j) + u
    if (l <= (-1.35d+91)) then
        tmp = t_1
    else if (l <= (-0.0095d0)) then
        tmp = t_2
    else if (l <= 0.00045d0) then
        tmp = u + (l * (2.0d0 * (j * t_0)))
    else if (l <= 1.9d+77) 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 + ((J * 0.3333333333333333) * (t_0 * Math.pow(l, 3.0)));
	double t_2 = ((Math.exp(l) - Math.exp(-l)) * J) + U;
	double tmp;
	if (l <= -1.35e+91) {
		tmp = t_1;
	} else if (l <= -0.0095) {
		tmp = t_2;
	} else if (l <= 0.00045) {
		tmp = U + (l * (2.0 * (J * t_0)));
	} else if (l <= 1.9e+77) {
		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 + ((J * 0.3333333333333333) * (t_0 * math.pow(l, 3.0)))
	t_2 = ((math.exp(l) - math.exp(-l)) * J) + U
	tmp = 0
	if l <= -1.35e+91:
		tmp = t_1
	elif l <= -0.0095:
		tmp = t_2
	elif l <= 0.00045:
		tmp = U + (l * (2.0 * (J * t_0)))
	elif l <= 1.9e+77:
		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(Float64(J * 0.3333333333333333) * Float64(t_0 * (l ^ 3.0))))
	t_2 = Float64(Float64(Float64(exp(l) - exp(Float64(-l))) * J) + U)
	tmp = 0.0
	if (l <= -1.35e+91)
		tmp = t_1;
	elseif (l <= -0.0095)
		tmp = t_2;
	elseif (l <= 0.00045)
		tmp = Float64(U + Float64(l * Float64(2.0 * Float64(J * t_0))));
	elseif (l <= 1.9e+77)
		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 + ((J * 0.3333333333333333) * (t_0 * (l ^ 3.0)));
	t_2 = ((exp(l) - exp(-l)) * J) + U;
	tmp = 0.0;
	if (l <= -1.35e+91)
		tmp = t_1;
	elseif (l <= -0.0095)
		tmp = t_2;
	elseif (l <= 0.00045)
		tmp = U + (l * (2.0 * (J * t_0)));
	elseif (l <= 1.9e+77)
		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[(J * 0.3333333333333333), $MachinePrecision] * N[(t$95$0 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision] + U), $MachinePrecision]}, If[LessEqual[l, -1.35e+91], t$95$1, If[LessEqual[l, -0.0095], t$95$2, If[LessEqual[l, 0.00045], N[(U + N[(l * N[(2.0 * N[(J * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.9e+77], t$95$2, t$95$1]]]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+77}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.35e91 or 1.9000000000000001e77 < 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 99.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. Taylor expanded in l around inf 99.0%

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

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

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

    if -1.35e91 < l < -0.00949999999999999976 or 4.4999999999999999e-4 < l < 1.9000000000000001e77

    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 83.3%

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

    if -0.00949999999999999976 < l < 4.4999999999999999e-4

    1. Initial program 70.9%

      \[\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(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.35 \cdot 10^{+91}:\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot \left(\cos \left(K \cdot 0.5\right) \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -0.0095:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{elif}\;\ell \leq 0.00045:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.9 \cdot 10^{+77}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J + U\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot 0.3333333333333333\right) \cdot \left(\cos \left(K \cdot 0.5\right) \cdot {\ell}^{3}\right)\\ \end{array} \]

Alternative 4: 81.3% accurate, 1.4× speedup?

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

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


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

    1. Initial program 89.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 90.1%

      \[\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. Taylor expanded in K around 0 41.9%

      \[\leadsto \color{blue}{J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)} + U \]
    4. Step-by-step derivation
      1. add-sqr-sqrt35.9%

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

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

        \[\leadsto J \cdot \left(\sqrt{\color{blue}{\left({\ell}^{3} \cdot 0.3333333333333333\right)} \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)} + 2 \cdot \ell\right) + U \]
      4. *-commutative66.8%

        \[\leadsto J \cdot \left(\sqrt{\left({\ell}^{3} \cdot 0.3333333333333333\right) \cdot \color{blue}{\left({\ell}^{3} \cdot 0.3333333333333333\right)}} + 2 \cdot \ell\right) + U \]
      5. swap-sqr66.8%

        \[\leadsto J \cdot \left(\sqrt{\color{blue}{\left({\ell}^{3} \cdot {\ell}^{3}\right) \cdot \left(0.3333333333333333 \cdot 0.3333333333333333\right)}} + 2 \cdot \ell\right) + U \]
      6. pow-prod-up66.8%

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

        \[\leadsto J \cdot \left(\sqrt{{\ell}^{\color{blue}{6}} \cdot \left(0.3333333333333333 \cdot 0.3333333333333333\right)} + 2 \cdot \ell\right) + U \]
      8. metadata-eval66.8%

        \[\leadsto J \cdot \left(\sqrt{{\ell}^{6} \cdot \color{blue}{0.1111111111111111}} + 2 \cdot \ell\right) + U \]
    5. Applied egg-rr66.8%

      \[\leadsto J \cdot \left(\color{blue}{\sqrt{{\ell}^{6} \cdot 0.1111111111111111}} + 2 \cdot \ell\right) + U \]
    6. Taylor expanded in l around -inf 79.2%

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

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

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

    if -0.0050000000000000001 < (cos.f64 (/.f64 K 2))

    1. Initial program 84.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 87.2%

      \[\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. Taylor expanded in K around 0 83.6%

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

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

Alternative 5: 87.2% accurate, 1.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;U + \ell \cdot \left(2 \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 < -0.0080000000000000002 or 5.19999999999999968e-5 < 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 K around 0 75.6%

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

    if -0.0080000000000000002 < l < 5.19999999999999968e-5

    1. Initial program 70.9%

      \[\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(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. *-commutative99.9%

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

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

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

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

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

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

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

Alternative 6: 78.6% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -9200000000000 \lor \neg \left(\ell \leq 2.3 \cdot 10^{+52}\right):\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\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 -9200000000000.0) (not (<= l 2.3e+52)))
   (* 0.3333333333333333 (* J (pow l 3.0)))
   (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -9200000000000.0) || !(l <= 2.3e+52)) {
		tmp = 0.3333333333333333 * (J * pow(l, 3.0));
	} 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 <= (-9200000000000.0d0)) .or. (.not. (l <= 2.3d+52))) then
        tmp = 0.3333333333333333d0 * (j * (l ** 3.0d0))
    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 <= -9200000000000.0) || !(l <= 2.3e+52)) {
		tmp = 0.3333333333333333 * (J * Math.pow(l, 3.0));
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -9200000000000.0) or not (l <= 2.3e+52):
		tmp = 0.3333333333333333 * (J * math.pow(l, 3.0))
	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 <= -9200000000000.0) || !(l <= 2.3e+52))
		tmp = Float64(0.3333333333333333 * Float64(J * (l ^ 3.0)));
	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 <= -9200000000000.0) || ~((l <= 2.3e+52)))
		tmp = 0.3333333333333333 * (J * (l ^ 3.0));
	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, -9200000000000.0], N[Not[LessEqual[l, 2.3e+52]], $MachinePrecision]], N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $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 -9200000000000 \lor \neg \left(\ell \leq 2.3 \cdot 10^{+52}\right):\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\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 < -9.2e12 or 2.3e52 < 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 83.6%

      \[\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. Taylor expanded in K around 0 62.1%

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

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

    if -9.2e12 < l < 2.3e52

    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 91.7%

      \[\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 simplification78.2%

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

Alternative 7: 78.6% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2300000000000 \lor \neg \left(\ell \leq 2.3 \cdot 10^{+52}\right):\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

\mathbf{else}:\\
\;\;\;\;U + \ell \cdot \left(2 \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 < -2.3e12 or 2.3e52 < 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 83.6%

      \[\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. Taylor expanded in K around 0 62.1%

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

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

    if -2.3e12 < l < 2.3e52

    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 91.7%

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

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

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

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

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

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

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

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

Alternative 8: 71.8% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2650000000000 \lor \neg \left(\ell \leq 2.15 \cdot 10^{+52}\right):\\
\;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.65e12 or 2.15e52 < 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 83.6%

      \[\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. Taylor expanded in K around 0 62.1%

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

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

    if -2.65e12 < l < 2.15e52

    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 91.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2650000000000 \lor \neg \left(\ell \leq 2.15 \cdot 10^{+52}\right):\\ \;\;\;\;0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \end{array} \]

Alternative 9: 53.9% accurate, 44.6× speedup?

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

\\
U + \ell \cdot \left(J \cdot 2\right)
\end{array}
Derivation
  1. Initial program 85.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 61.1%

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

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

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

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

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

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

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

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

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

Alternative 10: 37.2% 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.8%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Applied egg-rr25.5%

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

    \[\leadsto \color{blue}{U} \]
  4. Final simplification35.7%

    \[\leadsto U \]

Reproduce

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