Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.1% → 99.4%
Time: 9.0s
Alternatives: 9
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 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.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.4% accurate, 1.0× speedup?

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

\\
J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right) + U
\end{array}
Derivation
  1. Initial program 84.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 84.6%

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

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

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

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

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

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

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

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

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

      \[\leadsto J \cdot \left(\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(2 \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
    10. distribute-rgt-out84.6%

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

      \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)}\right) + U \]
  4. Simplified84.6%

    \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
  5. Taylor expanded in l around 0 60.8%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.6% 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 -\infty \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;U + t_0\\ \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
 (let* ((t_0 (* J (- (exp l) (exp (- l))))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 0.0)))
     (+ U t_0)
     (+ U (* 2.0 (* J (* l (cos (* K 0.5)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = J * (exp(l) - exp(-l));
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 0.0)) {
		tmp = U + t_0;
	} else {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	}
	return tmp;
}
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 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 0.0)) {
		tmp = U + t_0;
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = J * (math.exp(l) - math.exp(-l))
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 0.0):
		tmp = U + t_0
	else:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(J * Float64(exp(l) - exp(Float64(-l))))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 0.0))
		tmp = Float64(U + t_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)
	t_0 = J * (exp(l) - exp(-l));
	tmp = 0.0;
	if ((t_0 <= -Inf) || ~((t_0 <= 0.0)))
		tmp = U + t_0;
	else
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	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, (-Infinity)], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], N[(U + t$95$0), $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}
t_0 := J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;U + t_0\\

\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 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -inf.0 or -0.0 < (*.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. Taylor expanded in K around 0 78.2%

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

    if -inf.0 < (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) < -0.0

    1. Initial program 68.4%

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

      \[\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 simplification88.4%

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

Alternative 3: 95.1% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq -0.29:\\
\;\;\;\;t_3\\

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

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

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.4e151 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. Taylor expanded in l around 0 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. 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 \]
    6. Step-by-step derivation
      1. *-commutative100.0%

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

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

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

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

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

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

    if -3.4e151 < l < -0.28999999999999998 or 0.34499999999999997 < 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. Taylor expanded in K around 0 91.7%

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

    if -0.28999999999999998 < l < 0.34499999999999997

    1. Initial program 69.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\left(0.3333333333333333 \cdot {\ell}^{3}\right) \cdot \cos \left(0.5 \cdot K\right) + \color{blue}{\left(2 \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)}\right) + U \]
      10. distribute-rgt-out99.9%

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

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Step-by-step derivation
      1. fma-udef99.9%

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

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

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(\color{blue}{\ell \cdot 2} + 0.3333333333333333 \cdot {\ell}^{3}\right)\right) + U \]
    6. Applied egg-rr99.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.4 \cdot 10^{+151}:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -0.29:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 0.345:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + 2 \cdot \ell\right)\right)\\ \mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \end{array} \]

Alternative 4: 95.0% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq 0.0032:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t_0\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 < -3.4e151 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. Taylor expanded in l around 0 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. 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 \]
    6. Step-by-step derivation
      1. *-commutative100.0%

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

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

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

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

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

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

    if -3.4e151 < l < -7.5000000000000002e-4 or 0.00320000000000000015 < 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. Taylor expanded in K around 0 91.8%

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

    if -7.5000000000000002e-4 < l < 0.00320000000000000015

    1. Initial program 68.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.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.4 \cdot 10^{+151}:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -0.00075:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 0.0032:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 5.6 \cdot 10^{+102}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \end{array} \]

Alternative 5: 78.1% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -11.5 \lor \neg \left(\ell \leq 5.4\right):\\ \;\;\;\;U + 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 -11.5) (not (<= l 5.4)))
   (+ U (* 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 <= -11.5) || !(l <= 5.4)) {
		tmp = U + (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 <= (-11.5d0)) .or. (.not. (l <= 5.4d0))) then
        tmp = u + (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 <= -11.5) || !(l <= 5.4)) {
		tmp = U + (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 <= -11.5) or not (l <= 5.4):
		tmp = U + (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 <= -11.5) || !(l <= 5.4))
		tmp = Float64(U + 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 <= -11.5) || ~((l <= 5.4)))
		tmp = U + (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, -11.5], N[Not[LessEqual[l, 5.4]], $MachinePrecision]], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -11.5 \lor \neg \left(\ell \leq 5.4\right):\\
\;\;\;\;U + 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 < -11.5 or 5.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. Taylor expanded in l around 0 69.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)}\right) + U \]
    4. Simplified69.8%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in K around 0 51.2%

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

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

    if -11.5 < l < 5.4000000000000004

    1. Initial program 69.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -11.5 \lor \neg \left(\ell \leq 5.4\right):\\ \;\;\;\;U + 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 6: 78.1% accurate, 2.7× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)}\right) + U \]
    4. Simplified69.2%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in K around 0 53.6%

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

    if -0.00115 < l < 1.32e13

    1. Initial program 69.4%

      \[\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 98.7%

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

    if 1.32e13 < 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 71.5%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)}\right) + U \]
    4. Simplified71.5%

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in K around 0 49.6%

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

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

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

Alternative 7: 71.3% accurate, 2.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.89999999999999991 or 1.6500000000000001e-7 < l

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 2 \cdot \ell\right)\right)} + U \]
    5. Taylor expanded in K around 0 50.8%

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

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

    if -2.89999999999999991 < l < 1.6500000000000001e-7

    1. Initial program 68.7%

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

      \[\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. associate-*r*99.8%

        \[\leadsto 2 \cdot \color{blue}{\left(\left(J \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
      2. *-commutative99.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*99.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*99.8%

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

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

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

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

Alternative 8: 53.6% accurate, 44.6× speedup?

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

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

    \[\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. associate-*r*60.8%

      \[\leadsto 2 \cdot \color{blue}{\left(\left(J \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)\right)} + U \]
    2. *-commutative60.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*60.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*60.8%

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

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

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

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

Alternative 9: 36.3% 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 84.8%

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

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

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

    \[\leadsto U \]

Reproduce

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