Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.7%
Time: 14.6s
Alternatives: 16
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 16 alternatives:

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

Initial Program: 86.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{-6}\right):\\ \;\;\;\;J \cdot \left(t_0 \cdot \cos \left(K \cdot 0.5\right)\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right) + 0.016666666666666666 \cdot {\ell}^{5}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e-6)))
     (+ (* J (* t_0 (cos (* K 0.5)))) U)
     (+
      U
      (*
       (cos (/ K 2.0))
       (*
        J
        (+
         (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))
         (* 0.016666666666666666 (pow l 5.0)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 5e-6)) {
		tmp = (J * (t_0 * cos((K * 0.5)))) + U;
	} else {
		tmp = U + (cos((K / 2.0)) * (J * (((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0)) + (0.016666666666666666 * pow(l, 5.0)))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 5e-6)) {
		tmp = (J * (t_0 * Math.cos((K * 0.5)))) + U;
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (J * (((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0)) + (0.016666666666666666 * Math.pow(l, 5.0)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 5e-6):
		tmp = (J * (t_0 * math.cos((K * 0.5)))) + U
	else:
		tmp = U + (math.cos((K / 2.0)) * (J * (((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)) + (0.016666666666666666 * math.pow(l, 5.0)))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 5e-6))
		tmp = Float64(Float64(J * Float64(t_0 * cos(Float64(K * 0.5)))) + U);
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)) + Float64(0.016666666666666666 * (l ^ 5.0))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -Inf) || ~((t_0 <= 5e-6)))
		tmp = (J * (t_0 * cos((K * 0.5)))) + U;
	else
		tmp = U + (cos((K / 2.0)) * (J * (((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)) + (0.016666666666666666 * (l ^ 5.0)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 5e-6]], $MachinePrecision]], N[(N[(J * N[(t$95$0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision] + N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{-6}\right):\\
\;\;\;\;J \cdot \left(t_0 \cdot \cos \left(K \cdot 0.5\right)\right) + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 5.00000000000000041e-6 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    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 J around 0 100.0%

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

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.00000000000000041e-6

    1. Initial program 67.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 99.9%

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

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

Alternative 2: 97.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;\left(J \cdot t_1\right) \cdot \cos \left(\frac{K}{2}\right) \leq -\infty:\\ \;\;\;\;J \cdot \left(t_1 \cdot t_0\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(t_0 \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) + J \cdot \left(t_0 \cdot \left(0.0003968253968253968 \cdot {\ell}^{7} + 0.016666666666666666 \cdot {\ell}^{5}\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (cos (* K 0.5))) (t_1 (- (exp l) (exp (- l)))))
   (if (<= (* (* J t_1) (cos (/ K 2.0))) (- INFINITY))
     (+ (* J (* t_1 t_0)) U)
     (+
      U
      (+
       (* J (* t_0 (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))))
       (*
        J
        (*
         t_0
         (+
          (* 0.0003968253968253968 (pow l 7.0))
          (* 0.016666666666666666 (pow l 5.0))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = exp(l) - exp(-l);
	double tmp;
	if (((J * t_1) * cos((K / 2.0))) <= -((double) INFINITY)) {
		tmp = (J * (t_1 * t_0)) + U;
	} else {
		tmp = U + ((J * (t_0 * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0)))) + (J * (t_0 * ((0.0003968253968253968 * pow(l, 7.0)) + (0.016666666666666666 * pow(l, 5.0))))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.cos((K * 0.5));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if (((J * t_1) * Math.cos((K / 2.0))) <= -Double.POSITIVE_INFINITY) {
		tmp = (J * (t_1 * t_0)) + U;
	} else {
		tmp = U + ((J * (t_0 * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0)))) + (J * (t_0 * ((0.0003968253968253968 * Math.pow(l, 7.0)) + (0.016666666666666666 * Math.pow(l, 5.0))))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = math.exp(l) - math.exp(-l)
	tmp = 0
	if ((J * t_1) * math.cos((K / 2.0))) <= -math.inf:
		tmp = (J * (t_1 * t_0)) + U
	else:
		tmp = U + ((J * (t_0 * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)))) + (J * (t_0 * ((0.0003968253968253968 * math.pow(l, 7.0)) + (0.016666666666666666 * math.pow(l, 5.0))))))
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if (Float64(Float64(J * t_1) * cos(Float64(K / 2.0))) <= Float64(-Inf))
		tmp = Float64(Float64(J * Float64(t_1 * t_0)) + U);
	else
		tmp = Float64(U + Float64(Float64(J * Float64(t_0 * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)))) + Float64(J * Float64(t_0 * Float64(Float64(0.0003968253968253968 * (l ^ 7.0)) + Float64(0.016666666666666666 * (l ^ 5.0)))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = cos((K * 0.5));
	t_1 = exp(l) - exp(-l);
	tmp = 0.0;
	if (((J * t_1) * cos((K / 2.0))) <= -Inf)
		tmp = (J * (t_1 * t_0)) + U;
	else
		tmp = U + ((J * (t_0 * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)))) + (J * (t_0 * ((0.0003968253968253968 * (l ^ 7.0)) + (0.016666666666666666 * (l ^ 5.0))))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(J * t$95$1), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], (-Infinity)], N[(N[(J * N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[(J * N[(t$95$0 * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(J * N[(t$95$0 * N[(N[(0.0003968253968253968 * N[Power[l, 7.0], $MachinePrecision]), $MachinePrecision] + N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2))) < -inf.0

    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 J around 0 100.0%

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

    if -inf.0 < (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2)))

    1. Initial program 76.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 98.3%

      \[\leadsto \color{blue}{\left(0.0003968253968253968 \cdot \left(J \cdot \left({\ell}^{7} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + \left(0.016666666666666666 \cdot \left(J \cdot \left({\ell}^{5} \cdot \cos \left(0.5 \cdot K\right)\right)\right) + \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)\right)\right)} + U \]
    4. Simplified98.3%

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

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

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

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

Alternative 3: 97.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\left(J \cdot t_0\right) \cdot t_1 \leq -\infty:\\ \;\;\;\;J \cdot \left(t_0 \cdot \cos \left(K \cdot 0.5\right)\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + t_1 \cdot \left(J \cdot \left(0.0003968253968253968 \cdot {\ell}^{7} + \left(\left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right) + 0.016666666666666666 \cdot {\ell}^{5}\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))) (t_1 (cos (/ K 2.0))))
   (if (<= (* (* J t_0) t_1) (- INFINITY))
     (+ (* J (* t_0 (cos (* K 0.5)))) U)
     (+
      U
      (*
       t_1
       (*
        J
        (+
         (* 0.0003968253968253968 (pow l 7.0))
         (+
          (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0))
          (* 0.016666666666666666 (pow l 5.0))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double t_1 = cos((K / 2.0));
	double tmp;
	if (((J * t_0) * t_1) <= -((double) INFINITY)) {
		tmp = (J * (t_0 * cos((K * 0.5)))) + U;
	} else {
		tmp = U + (t_1 * (J * ((0.0003968253968253968 * pow(l, 7.0)) + (((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0)) + (0.016666666666666666 * pow(l, 5.0))))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (((J * t_0) * t_1) <= -Double.POSITIVE_INFINITY) {
		tmp = (J * (t_0 * Math.cos((K * 0.5)))) + U;
	} else {
		tmp = U + (t_1 * (J * ((0.0003968253968253968 * Math.pow(l, 7.0)) + (((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0)) + (0.016666666666666666 * Math.pow(l, 5.0))))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if ((J * t_0) * t_1) <= -math.inf:
		tmp = (J * (t_0 * math.cos((K * 0.5)))) + U
	else:
		tmp = U + (t_1 * (J * ((0.0003968253968253968 * math.pow(l, 7.0)) + (((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0)) + (0.016666666666666666 * math.pow(l, 5.0))))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (Float64(Float64(J * t_0) * t_1) <= Float64(-Inf))
		tmp = Float64(Float64(J * Float64(t_0 * cos(Float64(K * 0.5)))) + U);
	else
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(Float64(0.0003968253968253968 * (l ^ 7.0)) + Float64(Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0)) + Float64(0.016666666666666666 * (l ^ 5.0)))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	t_1 = cos((K / 2.0));
	tmp = 0.0;
	if (((J * t_0) * t_1) <= -Inf)
		tmp = (J * (t_0 * cos((K * 0.5)))) + U;
	else
		tmp = U + (t_1 * (J * ((0.0003968253968253968 * (l ^ 7.0)) + (((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0)) + (0.016666666666666666 * (l ^ 5.0))))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(J * t$95$0), $MachinePrecision] * t$95$1), $MachinePrecision], (-Infinity)], N[(N[(J * N[(t$95$0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(t$95$1 * N[(J * N[(N[(0.0003968253968253968 * N[Power[l, 7.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision] + N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2))) < -inf.0

    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 J around 0 100.0%

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

    if -inf.0 < (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2)))

    1. Initial program 76.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 98.2%

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

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

Alternative 4: 99.9% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -0.004 \lor \neg \left(t_0 \leq 5 \cdot 10^{-6}\right):\\
\;\;\;\;J \cdot \left(t_0 \cdot \cos \left(K \cdot 0.5\right)\right) + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.0040000000000000001 or 5.00000000000000041e-6 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    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 J around 0 99.9%

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

    if -0.0040000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 5.00000000000000041e-6

    1. Initial program 66.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.9%

      \[\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 2 regimes into one program.
  4. Final simplification99.9%

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

Alternative 5: 95.1% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.5 \cdot 10^{+102} \lor \neg \left(\ell \leq -4500000\right) \land \left(\ell \leq 37000 \lor \neg \left(\ell \leq 3 \cdot 10^{+97}\right)\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.5e102 or -4.5e6 < l < 37000 or 2.9999999999999998e97 < l

    1. Initial program 80.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 98.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 \]

    if -2.5e102 < l < -4.5e6 or 37000 < l < 2.9999999999999998e97

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.5 \cdot 10^{+102} \lor \neg \left(\ell \leq -4500000\right) \land \left(\ell \leq 37000 \lor \neg \left(\ell \leq 3 \cdot 10^{+97}\right)\right):\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(e^{\ell} - e^{-\ell}\right) + U\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 84.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -8 \cdot 10^{+200}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+149}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2 + \sqrt{{\ell}^{6} \cdot 0.1111111111111111}\right)\\ \mathbf{elif}\;\ell \leq -4500000 \lor \neg \left(\ell \leq 37000\right):\\ \;\;\;\;J \cdot \left(e^{\ell} - e^{-\ell}\right) + U\\ \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 (<= l -8e+200)
   (+ U (* 0.3333333333333333 (* J (pow l 3.0))))
   (if (<= l -1.5e+149)
     (+ U (* J (+ (* l 2.0) (sqrt (* (pow l 6.0) 0.1111111111111111)))))
     (if (or (<= l -4500000.0) (not (<= l 37000.0)))
       (+ (* J (- (exp l) (exp (- l)))) U)
       (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -8e+200) {
		tmp = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	} else if (l <= -1.5e+149) {
		tmp = U + (J * ((l * 2.0) + sqrt((pow(l, 6.0) * 0.1111111111111111))));
	} else if ((l <= -4500000.0) || !(l <= 37000.0)) {
		tmp = (J * (exp(l) - exp(-l))) + U;
	} 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 <= (-8d+200)) then
        tmp = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
    else if (l <= (-1.5d+149)) then
        tmp = u + (j * ((l * 2.0d0) + sqrt(((l ** 6.0d0) * 0.1111111111111111d0))))
    else if ((l <= (-4500000.0d0)) .or. (.not. (l <= 37000.0d0))) then
        tmp = (j * (exp(l) - exp(-l))) + u
    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 <= -8e+200) {
		tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
	} else if (l <= -1.5e+149) {
		tmp = U + (J * ((l * 2.0) + Math.sqrt((Math.pow(l, 6.0) * 0.1111111111111111))));
	} else if ((l <= -4500000.0) || !(l <= 37000.0)) {
		tmp = (J * (Math.exp(l) - Math.exp(-l))) + U;
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -8e+200:
		tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0)))
	elif l <= -1.5e+149:
		tmp = U + (J * ((l * 2.0) + math.sqrt((math.pow(l, 6.0) * 0.1111111111111111))))
	elif (l <= -4500000.0) or not (l <= 37000.0):
		tmp = (J * (math.exp(l) - math.exp(-l))) + U
	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 <= -8e+200)
		tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))));
	elseif (l <= -1.5e+149)
		tmp = Float64(U + Float64(J * Float64(Float64(l * 2.0) + sqrt(Float64((l ^ 6.0) * 0.1111111111111111)))));
	elseif ((l <= -4500000.0) || !(l <= 37000.0))
		tmp = Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) + U);
	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 <= -8e+200)
		tmp = U + (0.3333333333333333 * (J * (l ^ 3.0)));
	elseif (l <= -1.5e+149)
		tmp = U + (J * ((l * 2.0) + sqrt(((l ^ 6.0) * 0.1111111111111111))));
	elseif ((l <= -4500000.0) || ~((l <= 37000.0)))
		tmp = (J * (exp(l) - exp(-l))) + U;
	else
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -8e+200], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -1.5e+149], N[(U + N[(J * N[(N[(l * 2.0), $MachinePrecision] + N[Sqrt[N[(N[Power[l, 6.0], $MachinePrecision] * 0.1111111111111111), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, -4500000.0], N[Not[LessEqual[l, 37000.0]], $MachinePrecision]], N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $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 -8 \cdot 10^{+200}:\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

\mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+149}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2 + \sqrt{{\ell}^{6} \cdot 0.1111111111111111}\right)\\

\mathbf{elif}\;\ell \leq -4500000 \lor \neg \left(\ell \leq 37000\right):\\
\;\;\;\;J \cdot \left(e^{\ell} - e^{-\ell}\right) + U\\

\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 4 regimes
  2. if l < -7.9999999999999998e200

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 85.7%

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

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

    if -7.9999999999999998e200 < l < -1.50000000000000002e149

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 8.3%

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

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

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

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

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

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

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

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

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

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

    if -1.50000000000000002e149 < l < -4.5e6 or 37000 < 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 79.1%

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

    if -4.5e6 < l < 37000

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8 \cdot 10^{+200}:\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{+149}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2 + \sqrt{{\ell}^{6} \cdot 0.1111111111111111}\right)\\ \mathbf{elif}\;\ell \leq -4500000 \lor \neg \left(\ell \leq 37000\right):\\ \;\;\;\;J \cdot \left(e^{\ell} - e^{-\ell}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 78.9% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 83.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 59.8%

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

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

    1. Initial program 84.0%

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 84.6%

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

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

Alternative 8: 86.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4500000 \lor \neg \left(\ell \leq 37000\right):\\ \;\;\;\;J \cdot \left(e^{\ell} - e^{-\ell}\right) + U\\ \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 -4500000.0) (not (<= l 37000.0)))
   (+ (* J (- (exp l) (exp (- l)))) U)
   (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -4500000.0) || !(l <= 37000.0)) {
		tmp = (J * (exp(l) - exp(-l))) + U;
	} 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 <= (-4500000.0d0)) .or. (.not. (l <= 37000.0d0))) then
        tmp = (j * (exp(l) - exp(-l))) + u
    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 <= -4500000.0) || !(l <= 37000.0)) {
		tmp = (J * (Math.exp(l) - Math.exp(-l))) + U;
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -4500000.0) or not (l <= 37000.0):
		tmp = (J * (math.exp(l) - math.exp(-l))) + U
	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 <= -4500000.0) || !(l <= 37000.0))
		tmp = Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) + U);
	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 <= -4500000.0) || ~((l <= 37000.0)))
		tmp = (J * (exp(l) - exp(-l))) + U;
	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, -4500000.0], N[Not[LessEqual[l, 37000.0]], $MachinePrecision]], N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $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 -4500000 \lor \neg \left(\ell \leq 37000\right):\\
\;\;\;\;J \cdot \left(e^{\ell} - e^{-\ell}\right) + U\\

\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 < -4.5e6 or 37000 < 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 73.8%

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

    if -4.5e6 < l < 37000

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

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

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

Alternative 9: 78.4% accurate, 2.6× speedup?

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

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

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

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


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

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 52.9%

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

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

    if -1.95e8 < l < 12000

    1. Initial program 67.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 97.5%

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

    if 12000 < 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 80.4%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 62.0%

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

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

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

Alternative 10: 71.7% accurate, 2.6× speedup?

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

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

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

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


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

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

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 52.9%

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

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

    if -4.5e6 < l < 1750

    1. Initial program 67.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 64.4%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 82.6%

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

    if 1750 < 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 80.4%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 62.0%

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

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

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

Alternative 11: 71.7% accurate, 2.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.5e6 or 2.4500000000000002 < 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 73.2%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 56.9%

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

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

    if -4.5e6 < l < 2.4500000000000002

    1. Initial program 67.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 64.4%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 82.6%

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

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

Alternative 12: 54.1% accurate, 2.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.8 \cdot 10^{+205} \lor \neg \left(\ell \leq -4500000\right):\\
\;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\

\mathbf{else}:\\
\;\;\;\;{U}^{-3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.8000000000000003e205 or -4.5e6 < l

    1. Initial program 80.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 K around 0 71.4%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 61.2%

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

    if -5.8000000000000003e205 < l < -4.5e6

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{{U}^{-3}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification56.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.8 \cdot 10^{+205} \lor \neg \left(\ell \leq -4500000\right):\\ \;\;\;\;U + J \cdot \left(\ell \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;{U}^{-3}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 41.7% accurate, 23.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -7 \cdot 10^{+15} \lor \neg \left(\ell \leq 1.95 \cdot 10^{-17}\right):\\
\;\;\;\;U \cdot U\\

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


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

    1. Initial program 97.9%

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

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

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

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

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

    if -7e15 < l < 1.94999999999999995e-17

    1. Initial program 69.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7 \cdot 10^{+15} \lor \neg \left(\ell \leq 1.95 \cdot 10^{-17}\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 53.9% 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 83.8%

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

    \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  4. Taylor expanded in l around 0 51.6%

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

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

Alternative 15: 2.8% accurate, 312.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (J l K U) :precision binary64 1.0)
double code(double J, double l, double K, double U) {
	return 1.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 = 1.0d0
end function
public static double code(double J, double l, double K, double U) {
	return 1.0;
}
def code(J, l, K, U):
	return 1.0
function code(J, l, K, U)
	return 1.0
end
function tmp = code(J, l, K, U)
	tmp = 1.0;
end
code[J_, l_, K_, U_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 83.8%

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

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

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

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

    \[\leadsto \color{blue}{\frac{-4 - U}{-4 - U}} \]
  6. Step-by-step derivation
    1. *-inverses2.7%

      \[\leadsto \color{blue}{1} \]
  7. Simplified2.7%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification2.7%

    \[\leadsto 1 \]
  9. Add Preprocessing

Alternative 16: 37.0% 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 83.8%

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

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

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

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

    \[\leadsto \color{blue}{U} \]
  6. Final simplification32.8%

    \[\leadsto U \]
  7. Add Preprocessing

Reproduce

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