Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.5% → 99.5%
Time: 9.0s
Alternatives: 10
Speedup: 1.3×

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.5% 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.5% accurate, 1.0× speedup?

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

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

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

    \[\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 \]
  4. Taylor expanded in l around 0 64.9%

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

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

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

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

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

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

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

Alternative 2: 86.3% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+25} \lor \neg \left(t_0 \leq 2 \cdot 10^{+141}\right):\\
\;\;\;\;U + t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -2.00000000000000018e25 or 2.00000000000000003e141 < (*.f64 J (-.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 \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 74.5%

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

    if -2.00000000000000018e25 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < 2.00000000000000003e141

    1. Initial program 71.7%

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

      \[\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 simplification87.0%

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

Alternative 3: 95.1% accurate, 1.3× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-18}:\\
\;\;\;\;U + 2 \cdot \left(\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right)\\

\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.8000000000000005e102 or 5.60000000000000037e102 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 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 \]
    4. Taylor expanded in l around inf 100.0%

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

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

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

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

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

    if -5.8000000000000005e102 < l < -0.00145 or 1.3e-18 < l < 5.60000000000000037e102

    1. Initial program 99.9%

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

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

    if -0.00145 < l < 1.3e-18

    1. Initial program 71.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.8 \cdot 10^{+102}:\\ \;\;\;\;U + \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq -0.00145:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 1.3 \cdot 10^{-18}:\\ \;\;\;\;U + 2 \cdot \left(\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right) \cdot J\right)\\ \mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 95.4% accurate, 1.3× speedup?

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

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

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

\mathbf{elif}\;\ell \leq 2200000:\\
\;\;\;\;U + t_0 \cdot \left(J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\right)\\

\mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5.8000000000000005e102 or 5.60000000000000037e102 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 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 \]
    4. Taylor expanded in l around inf 100.0%

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

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

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

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

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

    if -5.8000000000000005e102 < l < -0.031 or 2.2e6 < l < 5.60000000000000037e102

    1. Initial program 100.0%

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

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

    if -0.031 < l < 2.2e6

    1. Initial program 72.3%

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

      \[\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 3 regimes into one program.
  4. Final simplification97.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.8 \cdot 10^{+102}:\\ \;\;\;\;U + \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq -0.031:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 2200000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left({\ell}^{3} \cdot 0.3333333333333333 + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 81.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.045:\\ \;\;\;\;U + -0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\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.045)
   (+ U (* -0.3333333333333333 (* J (pow l 3.0))))
   (+ 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.045) {
		tmp = U + (-0.3333333333333333 * (J * pow(l, 3.0)));
	} 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.045d0)) then
        tmp = u + ((-0.3333333333333333d0) * (j * (l ** 3.0d0)))
    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.045) {
		tmp = U + (-0.3333333333333333 * (J * Math.pow(l, 3.0)));
	} 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.045:
		tmp = U + (-0.3333333333333333 * (J * math.pow(l, 3.0)))
	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.045)
		tmp = Float64(U + Float64(-0.3333333333333333 * Float64(J * (l ^ 3.0))));
	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.045)
		tmp = U + (-0.3333333333333333 * (J * (l ^ 3.0)));
	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.045], N[(U + N[(-0.3333333333333333 * N[(J * N[Power[l, 3.0], $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.045:\\
\;\;\;\;U + -0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\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.044999999999999998

    1. Initial program 84.2%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 92.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 \]
    4. Taylor expanded in K around 0 33.7%

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

        \[\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-unprod57.6%

        \[\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. *-commutative57.6%

        \[\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. *-commutative57.6%

        \[\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-sqr57.6%

        \[\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-up57.6%

        \[\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-eval57.6%

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

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

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

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

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

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

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

    1. Initial program 86.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 88.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 \]
    4. Taylor expanded in K around 0 85.3%

      \[\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 simplification83.0%

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

Alternative 6: 74.0% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := J \cdot {\ell}^{3}\\
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq -0.045:\\
\;\;\;\;U + -0.3333333333333333 \cdot t_0\\

\mathbf{else}:\\
\;\;\;\;U + 0.3333333333333333 \cdot t_0\\


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

    1. Initial program 84.2%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 92.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 \]
    4. Taylor expanded in K around 0 33.7%

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

        \[\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-unprod57.6%

        \[\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. *-commutative57.6%

        \[\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. *-commutative57.6%

        \[\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-sqr57.6%

        \[\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-up57.6%

        \[\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-eval57.6%

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

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

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

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

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

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

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

    1. Initial program 86.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 88.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 \]
    4. Taylor expanded in K around 0 85.3%

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

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

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

Alternative 7: 78.2% accurate, 2.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -7.8e5 or 4.4000000000000004 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 79.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 \]
    4. Taylor expanded in K around 0 58.7%

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

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

    if -7.8e5 < l < 4.4000000000000004

    1. Initial program 71.9%

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

      \[\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 simplification79.1%

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

Alternative 8: 57.1% accurate, 2.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if K < 1.7e11

    1. Initial program 87.3%

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

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

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

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

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

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

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

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

    if 1.7e11 < K

    1. Initial program 80.5%

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

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

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

        \[\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-unprod55.5%

        \[\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. *-commutative55.5%

        \[\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. *-commutative55.5%

        \[\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-sqr55.5%

        \[\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-up55.5%

        \[\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-eval55.5%

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

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

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

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

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

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

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

Alternative 9: 54.5% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 36.9% 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.9%

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

    \[\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 \]
  4. Taylor expanded in l around inf 75.1%

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

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

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

      \[\leadsto \color{blue}{\left({\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
  6. Simplified75.1%

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

    \[\leadsto \color{blue}{U} \]
  8. Final simplification36.3%

    \[\leadsto U \]
  9. Add Preprocessing

Reproduce

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