Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 85.9% → 99.5%
Time: 15.4s
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: 85.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 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 83.5%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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 \]
    3. associate-*l*99.5%

      \[\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 \]
    4. *-commutative99.5%

      \[\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 \]
  10. Applied egg-rr99.5%

    \[\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 \]
  11. Final simplification99.5%

    \[\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 \]
  12. Add Preprocessing

Alternative 2: 87.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t\_0 \leq -0.5 \lor \neg \left(t\_0 \leq 2 \cdot 10^{-13}\right):\\ \;\;\;\;U + J \cdot 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 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 -0.5) (not (<= t_0 2e-13)))
     (+ U (* J t_0))
     (+ U (* 2.0 (* J (* l (cos (* K 0.5)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -0.5) || !(t_0 <= 2e-13)) {
		tmp = U + (J * t_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) :: t_0
    real(8) :: tmp
    t_0 = exp(l) - exp(-l)
    if ((t_0 <= (-0.5d0)) .or. (.not. (t_0 <= 2d-13))) then
        tmp = u + (j * t_0)
    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 t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -0.5) || !(t_0 <= 2e-13)) {
		tmp = U + (J * t_0);
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -0.5) or not (t_0 <= 2e-13):
		tmp = U + (J * 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(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= -0.5) || !(t_0 <= 2e-13))
		tmp = Float64(U + Float64(J * 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 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -0.5) || ~((t_0 <= 2e-13)))
		tmp = U + (J * 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[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.5], N[Not[LessEqual[t$95$0, 2e-13]], $MachinePrecision]], N[(U + N[(J * t$95$0), $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}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t\_0 \leq -0.5 \lor \neg \left(t\_0 \leq 2 \cdot 10^{-13}\right):\\
\;\;\;\;U + J \cdot 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 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.5 or 2.0000000000000001e-13 < (-.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 K around 0 73.4%

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

    if -0.5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.0000000000000001e-13

    1. Initial program 67.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -0.5 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-13}\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} \]
  5. Add Preprocessing

Alternative 3: 95.5% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\
\mathbf{if}\;\ell \leq -8 \cdot 10^{+106}:\\
\;\;\;\;t\_0\\

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

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -8.00000000000000073e106 or 1650 < l

    1. Initial program 100.0%

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

        \[\leadsto \color{blue}{J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right)\right)} + U \]
      2. fma-define100.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. Taylor expanded in l around 0 94.1%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)}, U\right) \]
    6. Step-by-step derivation
      1. distribute-lft-in94.1%

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 \cdot \cos \left(0.5 \cdot K\right)\right) + \ell \cdot \left({\ell}^{2} \cdot \left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)}, U\right) \]
      2. fma-define94.1%

        \[\leadsto \mathsf{fma}\left(J, \color{blue}{\mathsf{fma}\left(\ell, 2 \cdot \cos \left(0.5 \cdot K\right), \ell \cdot \left({\ell}^{2} \cdot \left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)\right)}, U\right) \]
      3. *-commutative94.1%

        \[\leadsto \mathsf{fma}\left(J, \mathsf{fma}\left(\ell, 2 \cdot \cos \left(0.5 \cdot K\right), \color{blue}{\left({\ell}^{2} \cdot \left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right) \cdot \ell}\right), U\right) \]
      4. *-commutative94.1%

        \[\leadsto \mathsf{fma}\left(J, \mathsf{fma}\left(\ell, 2 \cdot \cos \left(0.5 \cdot K\right), \color{blue}{\left(\left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot {\ell}^{2}\right)} \cdot \ell\right), U\right) \]
      5. associate-*l*94.1%

        \[\leadsto \mathsf{fma}\left(J, \mathsf{fma}\left(\ell, 2 \cdot \cos \left(0.5 \cdot K\right), \color{blue}{\left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot \left({\ell}^{2} \cdot \ell\right)}\right), U\right) \]
    7. Simplified94.1%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\mathsf{fma}\left(\ell, 2 \cdot \cos \left(0.5 \cdot K\right), \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left({\ell}^{2}, \mathsf{fma}\left({\ell}^{2}, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right)\right) \cdot {\ell}^{3}\right)}, U\right) \]
    8. Taylor expanded in l around inf 94.1%

      \[\leadsto \color{blue}{0.0003968253968253968 \cdot \left(J \cdot \left({\ell}^{7} \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
    9. Step-by-step derivation
      1. *-commutative94.1%

        \[\leadsto 0.0003968253968253968 \cdot \left(J \cdot \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{7}\right)}\right) \]
      2. associate-*r*94.1%

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

        \[\leadsto \color{blue}{\left(0.0003968253968253968 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot {\ell}^{7}} \]
      4. *-commutative94.1%

        \[\leadsto \color{blue}{{\ell}^{7} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
      5. associate-*r*94.1%

        \[\leadsto {\ell}^{7} \cdot \color{blue}{\left(\left(0.0003968253968253968 \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)\right)} \]
      6. associate-*r*94.1%

        \[\leadsto \color{blue}{\left({\ell}^{7} \cdot \left(0.0003968253968253968 \cdot J\right)\right) \cdot \cos \left(0.5 \cdot K\right)} \]
      7. *-commutative94.1%

        \[\leadsto \left({\ell}^{7} \cdot \color{blue}{\left(J \cdot 0.0003968253968253968\right)}\right) \cdot \cos \left(0.5 \cdot K\right) \]
    10. Simplified94.1%

      \[\leadsto \color{blue}{\left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(0.5 \cdot K\right)} \]

    if -8.00000000000000073e106 < l < -0.085999999999999993

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

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

    if -0.085999999999999993 < l < 1650

    1. Initial program 67.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 l around 0 99.1%

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

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

Alternative 4: 96.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ t_1 := \cos \left(K \cdot 0.5\right)\\ t_2 := \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right) \cdot t\_1\\ \mathbf{if}\;\ell \leq -8 \cdot 10^{+106}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\ell \leq -0.00185:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 0.00125:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t\_1\right)\right)\\ \mathbf{elif}\;\ell \leq 170000000000:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (- (exp l) (exp (- l))))))
        (t_1 (cos (* K 0.5)))
        (t_2 (* (* (pow l 7.0) (* J 0.0003968253968253968)) t_1)))
   (if (<= l -8e+106)
     t_2
     (if (<= l -0.00185)
       t_0
       (if (<= l 0.00125)
         (+ U (* 2.0 (* J (* l t_1))))
         (if (<= l 170000000000.0) t_0 t_2))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (exp(l) - exp(-l)));
	double t_1 = cos((K * 0.5));
	double t_2 = (pow(l, 7.0) * (J * 0.0003968253968253968)) * t_1;
	double tmp;
	if (l <= -8e+106) {
		tmp = t_2;
	} else if (l <= -0.00185) {
		tmp = t_0;
	} else if (l <= 0.00125) {
		tmp = U + (2.0 * (J * (l * t_1)));
	} else if (l <= 170000000000.0) {
		tmp = t_0;
	} 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) :: tmp
    t_0 = u + (j * (exp(l) - exp(-l)))
    t_1 = cos((k * 0.5d0))
    t_2 = ((l ** 7.0d0) * (j * 0.0003968253968253968d0)) * t_1
    if (l <= (-8d+106)) then
        tmp = t_2
    else if (l <= (-0.00185d0)) then
        tmp = t_0
    else if (l <= 0.00125d0) then
        tmp = u + (2.0d0 * (j * (l * t_1)))
    else if (l <= 170000000000.0d0) then
        tmp = t_0
    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 = U + (J * (Math.exp(l) - Math.exp(-l)));
	double t_1 = Math.cos((K * 0.5));
	double t_2 = (Math.pow(l, 7.0) * (J * 0.0003968253968253968)) * t_1;
	double tmp;
	if (l <= -8e+106) {
		tmp = t_2;
	} else if (l <= -0.00185) {
		tmp = t_0;
	} else if (l <= 0.00125) {
		tmp = U + (2.0 * (J * (l * t_1)));
	} else if (l <= 170000000000.0) {
		tmp = t_0;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (math.exp(l) - math.exp(-l)))
	t_1 = math.cos((K * 0.5))
	t_2 = (math.pow(l, 7.0) * (J * 0.0003968253968253968)) * t_1
	tmp = 0
	if l <= -8e+106:
		tmp = t_2
	elif l <= -0.00185:
		tmp = t_0
	elif l <= 0.00125:
		tmp = U + (2.0 * (J * (l * t_1)))
	elif l <= 170000000000.0:
		tmp = t_0
	else:
		tmp = t_2
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))))
	t_1 = cos(Float64(K * 0.5))
	t_2 = Float64(Float64((l ^ 7.0) * Float64(J * 0.0003968253968253968)) * t_1)
	tmp = 0.0
	if (l <= -8e+106)
		tmp = t_2;
	elseif (l <= -0.00185)
		tmp = t_0;
	elseif (l <= 0.00125)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_1))));
	elseif (l <= 170000000000.0)
		tmp = t_0;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (exp(l) - exp(-l)));
	t_1 = cos((K * 0.5));
	t_2 = ((l ^ 7.0) * (J * 0.0003968253968253968)) * t_1;
	tmp = 0.0;
	if (l <= -8e+106)
		tmp = t_2;
	elseif (l <= -0.00185)
		tmp = t_0;
	elseif (l <= 0.00125)
		tmp = U + (2.0 * (J * (l * t_1)));
	elseif (l <= 170000000000.0)
		tmp = t_0;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Power[l, 7.0], $MachinePrecision] * N[(J * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]}, If[LessEqual[l, -8e+106], t$95$2, If[LessEqual[l, -0.00185], t$95$0, If[LessEqual[l, 0.00125], N[(U + N[(2.0 * N[(J * N[(l * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 170000000000.0], t$95$0, t$95$2]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
t_1 := \cos \left(K \cdot 0.5\right)\\
t_2 := \left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right) \cdot t\_1\\
\mathbf{if}\;\ell \leq -8 \cdot 10^{+106}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;\ell \leq -0.00185:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 170000000000:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -8.00000000000000073e106 or 1.7e11 < l

    1. Initial program 100.0%

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

        \[\leadsto \color{blue}{J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right)\right)} + U \]
      2. fma-define100.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. Taylor expanded in l around 0 98.0%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)}, U\right) \]
    6. Step-by-step derivation
      1. distribute-lft-in98.0%

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

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

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

        \[\leadsto \mathsf{fma}\left(J, \mathsf{fma}\left(\ell, 2 \cdot \cos \left(0.5 \cdot K\right), \color{blue}{\left(\left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot {\ell}^{2}\right)} \cdot \ell\right), U\right) \]
      5. associate-*l*98.0%

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

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\mathsf{fma}\left(\ell, 2 \cdot \cos \left(0.5 \cdot K\right), \left(\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left({\ell}^{2}, \mathsf{fma}\left({\ell}^{2}, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right)\right) \cdot {\ell}^{3}\right)}, U\right) \]
    8. Taylor expanded in l around inf 98.0%

      \[\leadsto \color{blue}{0.0003968253968253968 \cdot \left(J \cdot \left({\ell}^{7} \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
    9. Step-by-step derivation
      1. *-commutative98.0%

        \[\leadsto 0.0003968253968253968 \cdot \left(J \cdot \color{blue}{\left(\cos \left(0.5 \cdot K\right) \cdot {\ell}^{7}\right)}\right) \]
      2. associate-*r*98.0%

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

        \[\leadsto \color{blue}{\left(0.0003968253968253968 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot {\ell}^{7}} \]
      4. *-commutative98.0%

        \[\leadsto \color{blue}{{\ell}^{7} \cdot \left(0.0003968253968253968 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)} \]
      5. associate-*r*98.0%

        \[\leadsto {\ell}^{7} \cdot \color{blue}{\left(\left(0.0003968253968253968 \cdot J\right) \cdot \cos \left(0.5 \cdot K\right)\right)} \]
      6. associate-*r*98.0%

        \[\leadsto \color{blue}{\left({\ell}^{7} \cdot \left(0.0003968253968253968 \cdot J\right)\right) \cdot \cos \left(0.5 \cdot K\right)} \]
      7. *-commutative98.0%

        \[\leadsto \left({\ell}^{7} \cdot \color{blue}{\left(J \cdot 0.0003968253968253968\right)}\right) \cdot \cos \left(0.5 \cdot K\right) \]
    10. Simplified98.0%

      \[\leadsto \color{blue}{\left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(0.5 \cdot K\right)} \]

    if -8.00000000000000073e106 < l < -0.0018500000000000001 or 0.00125000000000000003 < l < 1.7e11

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

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

    if -0.0018500000000000001 < l < 0.00125000000000000003

    1. Initial program 67.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -8 \cdot 10^{+106}:\\ \;\;\;\;\left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \mathbf{elif}\;\ell \leq -0.00185:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 0.00125:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 170000000000:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;\left({\ell}^{7} \cdot \left(J \cdot 0.0003968253968253968\right)\right) \cdot \cos \left(K \cdot 0.5\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 73.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \left(\ell \cdot \frac{t\_0}{U}\right)\right)\right)\\ \mathbf{if}\;\ell \leq -6.2 \cdot 10^{+143}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -620:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{elif}\;\ell \leq 820000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 3.3 \cdot 10^{+120}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {K}^{2} \cdot -0.25\right)\right)\\ \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 (+ 1.0 (* 2.0 (* J (* l (/ t_0 U))))))))
   (if (<= l -6.2e+143)
     t_1
     (if (<= l -620.0)
       (log1p (expm1 U))
       (if (<= l 820000000.0)
         (+ U (* 2.0 (* J (* l t_0))))
         (if (<= l 3.3e+120)
           (+ U (* J (* l (+ 2.0 (* (pow K 2.0) -0.25)))))
           t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = cos((K * 0.5));
	double t_1 = U * (1.0 + (2.0 * (J * (l * (t_0 / U)))));
	double tmp;
	if (l <= -6.2e+143) {
		tmp = t_1;
	} else if (l <= -620.0) {
		tmp = log1p(expm1(U));
	} else if (l <= 820000000.0) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 3.3e+120) {
		tmp = U + (J * (l * (2.0 + (pow(K, 2.0) * -0.25))));
	} else {
		tmp = t_1;
	}
	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 = U * (1.0 + (2.0 * (J * (l * (t_0 / U)))));
	double tmp;
	if (l <= -6.2e+143) {
		tmp = t_1;
	} else if (l <= -620.0) {
		tmp = Math.log1p(Math.expm1(U));
	} else if (l <= 820000000.0) {
		tmp = U + (2.0 * (J * (l * t_0)));
	} else if (l <= 3.3e+120) {
		tmp = U + (J * (l * (2.0 + (Math.pow(K, 2.0) * -0.25))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.cos((K * 0.5))
	t_1 = U * (1.0 + (2.0 * (J * (l * (t_0 / U)))))
	tmp = 0
	if l <= -6.2e+143:
		tmp = t_1
	elif l <= -620.0:
		tmp = math.log1p(math.expm1(U))
	elif l <= 820000000.0:
		tmp = U + (2.0 * (J * (l * t_0)))
	elif l <= 3.3e+120:
		tmp = U + (J * (l * (2.0 + (math.pow(K, 2.0) * -0.25))))
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = cos(Float64(K * 0.5))
	t_1 = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l * Float64(t_0 / U))))))
	tmp = 0.0
	if (l <= -6.2e+143)
		tmp = t_1;
	elseif (l <= -620.0)
		tmp = log1p(expm1(U));
	elseif (l <= 820000000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * t_0))));
	elseif (l <= 3.3e+120)
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64((K ^ 2.0) * -0.25)))));
	else
		tmp = t_1;
	end
	return 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[(1.0 + N[(2.0 * N[(J * N[(l * N[(t$95$0 / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -6.2e+143], t$95$1, If[LessEqual[l, -620.0], N[Log[1 + N[(Exp[U] - 1), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 820000000.0], N[(U + N[(2.0 * N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 3.3e+120], N[(U + N[(J * N[(l * N[(2.0 + N[(N[Power[K, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(K \cdot 0.5\right)\\
t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \left(\ell \cdot \frac{t\_0}{U}\right)\right)\right)\\
\mathbf{if}\;\ell \leq -6.2 \cdot 10^{+143}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -620:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\

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

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

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -6.1999999999999998e143 or 3.29999999999999991e120 < l

    1. Initial program 100.0%

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

        \[\leadsto \color{blue}{J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right)\right)} + U \]
      2. fma-define100.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. Taylor expanded in l around 0 100.0%

      \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)}, U\right) \]
    6. Step-by-step derivation
      1. distribute-lft-in100.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{U \cdot \mathsf{fma}\left(J, \frac{\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left({\ell}^{3}, \mathsf{fma}\left({\ell}^{2}, \mathsf{fma}\left({\ell}^{2}, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2 \cdot \ell\right)}{U}, 1\right)} \]
    11. Taylor expanded in l around 0 49.8%

      \[\leadsto U \cdot \color{blue}{\left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
    12. Step-by-step derivation
      1. associate-/l*71.4%

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

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

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

    if -6.1999999999999998e143 < l < -620

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)} \]

    if -620 < l < 8.2e8

    1. Initial program 68.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 l around 0 96.1%

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

    if 8.2e8 < l < 3.29999999999999991e120

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.2 \cdot 10^{+143}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \left(\ell \cdot \frac{\cos \left(K \cdot 0.5\right)}{U}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -620:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U\right)\right)\\ \mathbf{elif}\;\ell \leq 820000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 3.3 \cdot 10^{+120}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {K}^{2} \cdot -0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \left(\ell \cdot \frac{\cos \left(K \cdot 0.5\right)}{U}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 67.3% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 + {K}^{2} \cdot -0.25\\ t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{if}\;\ell \leq -1 \cdot 10^{+17}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq 800000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.15 \cdot 10^{+125}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot t\_0\right)\\ \mathbf{elif}\;\ell \leq 3.2 \cdot 10^{+195} \lor \neg \left(\ell \leq 1.75 \cdot 10^{+289}\right):\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \ell\right) \cdot t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ 2.0 (* (pow K 2.0) -0.25)))
        (t_1 (* U (+ 1.0 (* 2.0 (* J (/ l U)))))))
   (if (<= l -1e+17)
     t_1
     (if (<= l 800000000.0)
       (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
       (if (<= l 2.15e+125)
         (+ U (* J (* l t_0)))
         (if (or (<= l 3.2e+195) (not (<= l 1.75e+289)))
           t_1
           (+ U (* (* J l) t_0))))))))
double code(double J, double l, double K, double U) {
	double t_0 = 2.0 + (pow(K, 2.0) * -0.25);
	double t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	double tmp;
	if (l <= -1e+17) {
		tmp = t_1;
	} else if (l <= 800000000.0) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else if (l <= 2.15e+125) {
		tmp = U + (J * (l * t_0));
	} else if ((l <= 3.2e+195) || !(l <= 1.75e+289)) {
		tmp = t_1;
	} else {
		tmp = U + ((J * l) * t_0);
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 2.0d0 + ((k ** 2.0d0) * (-0.25d0))
    t_1 = u * (1.0d0 + (2.0d0 * (j * (l / u))))
    if (l <= (-1d+17)) then
        tmp = t_1
    else if (l <= 800000000.0d0) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else if (l <= 2.15d+125) then
        tmp = u + (j * (l * t_0))
    else if ((l <= 3.2d+195) .or. (.not. (l <= 1.75d+289))) then
        tmp = t_1
    else
        tmp = u + ((j * l) * t_0)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = 2.0 + (Math.pow(K, 2.0) * -0.25);
	double t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	double tmp;
	if (l <= -1e+17) {
		tmp = t_1;
	} else if (l <= 800000000.0) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else if (l <= 2.15e+125) {
		tmp = U + (J * (l * t_0));
	} else if ((l <= 3.2e+195) || !(l <= 1.75e+289)) {
		tmp = t_1;
	} else {
		tmp = U + ((J * l) * t_0);
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = 2.0 + (math.pow(K, 2.0) * -0.25)
	t_1 = U * (1.0 + (2.0 * (J * (l / U))))
	tmp = 0
	if l <= -1e+17:
		tmp = t_1
	elif l <= 800000000.0:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	elif l <= 2.15e+125:
		tmp = U + (J * (l * t_0))
	elif (l <= 3.2e+195) or not (l <= 1.75e+289):
		tmp = t_1
	else:
		tmp = U + ((J * l) * t_0)
	return tmp
function code(J, l, K, U)
	t_0 = Float64(2.0 + Float64((K ^ 2.0) * -0.25))
	t_1 = Float64(U * Float64(1.0 + Float64(2.0 * Float64(J * Float64(l / U)))))
	tmp = 0.0
	if (l <= -1e+17)
		tmp = t_1;
	elseif (l <= 800000000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	elseif (l <= 2.15e+125)
		tmp = Float64(U + Float64(J * Float64(l * t_0)));
	elseif ((l <= 3.2e+195) || !(l <= 1.75e+289))
		tmp = t_1;
	else
		tmp = Float64(U + Float64(Float64(J * l) * t_0));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = 2.0 + ((K ^ 2.0) * -0.25);
	t_1 = U * (1.0 + (2.0 * (J * (l / U))));
	tmp = 0.0;
	if (l <= -1e+17)
		tmp = t_1;
	elseif (l <= 800000000.0)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	elseif (l <= 2.15e+125)
		tmp = U + (J * (l * t_0));
	elseif ((l <= 3.2e+195) || ~((l <= 1.75e+289)))
		tmp = t_1;
	else
		tmp = U + ((J * l) * t_0);
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(2.0 + N[(N[Power[K, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U * N[(1.0 + N[(2.0 * N[(J * N[(l / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1e+17], t$95$1, If[LessEqual[l, 800000000.0], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.15e+125], N[(U + N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 3.2e+195], N[Not[LessEqual[l, 1.75e+289]], $MachinePrecision]], t$95$1, N[(U + N[(N[(J * l), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 + {K}^{2} \cdot -0.25\\
t_1 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\
\mathbf{if}\;\ell \leq -1 \cdot 10^{+17}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;\ell \leq 2.15 \cdot 10^{+125}:\\
\;\;\;\;U + J \cdot \left(\ell \cdot t\_0\right)\\

\mathbf{elif}\;\ell \leq 3.2 \cdot 10^{+195} \lor \neg \left(\ell \leq 1.75 \cdot 10^{+289}\right):\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1e17 or 2.15000000000000018e125 < l < 3.19999999999999982e195 or 1.75000000000000011e289 < l

    1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    9. Taylor expanded in U around inf 35.8%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    10. Step-by-step derivation
      1. associate-/l*53.4%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified53.4%

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

    if -1e17 < l < 8e8

    1. Initial program 69.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 92.8%

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

    if 8e8 < l < 2.15000000000000018e125

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified12.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.19999999999999982e195 < l < 1.75000000000000011e289

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1 \cdot 10^{+17}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{elif}\;\ell \leq 800000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.15 \cdot 10^{+125}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {K}^{2} \cdot -0.25\right)\right)\\ \mathbf{elif}\;\ell \leq 3.2 \cdot 10^{+195} \lor \neg \left(\ell \leq 1.75 \cdot 10^{+289}\right):\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \ell\right) \cdot \left(2 + {K}^{2} \cdot -0.25\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 68.0% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
t_0 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\
\mathbf{if}\;\ell \leq -5 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\

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

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5e16 or 3.7999999999999998e124 < l

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified31.1%

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    9. Taylor expanded in U around inf 33.2%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    10. Step-by-step derivation
      1. associate-/l*47.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified47.8%

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

    if -5e16 < l < 8e8

    1. Initial program 69.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 92.8%

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

    if 8e8 < l < 3.7999999999999998e124

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified12.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5 \cdot 10^{+16}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{elif}\;\ell \leq 800000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 3.8 \cdot 10^{+124}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + {K}^{2} \cdot -0.25\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 67.4% accurate, 2.5× speedup?

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

\\
\begin{array}{l}
t_0 := U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\
\mathbf{if}\;\ell \leq -5 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 2.75 \cdot 10^{+124}:\\
\;\;\;\;U + \left(J \cdot 8 - J \cdot {K}^{2}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -5e16 or 2.74999999999999989e124 < l

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified31.1%

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    9. Taylor expanded in U around inf 33.2%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    10. Step-by-step derivation
      1. associate-/l*47.8%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified47.8%

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

    if -5e16 < l < 8e8

    1. Initial program 69.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 92.8%

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

    if 8e8 < l < 2.74999999999999989e124

    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. Applied egg-rr3.4%

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

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

        \[\leadsto \left(\color{blue}{\left(-1 \cdot J\right) \cdot {K}^{2}} + 8 \cdot J\right) + U \]
      2. +-commutative36.5%

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

        \[\leadsto \left(8 \cdot J + \color{blue}{-1 \cdot \left(J \cdot {K}^{2}\right)}\right) + U \]
      4. mul-1-neg36.5%

        \[\leadsto \left(8 \cdot J + \color{blue}{\left(-J \cdot {K}^{2}\right)}\right) + U \]
      5. unsub-neg36.5%

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

        \[\leadsto \left(\color{blue}{J \cdot 8} - J \cdot {K}^{2}\right) + U \]
    6. Simplified36.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5 \cdot 10^{+16}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \mathbf{elif}\;\ell \leq 800000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.75 \cdot 10^{+124}:\\ \;\;\;\;U + \left(J \cdot 8 - J \cdot {K}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \left(J \cdot \frac{\ell}{U}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 58.6% accurate, 2.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.35999999999999999

    1. Initial program 84.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    9. Taylor expanded in J around inf 42.6%

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

    if 0.35999999999999999 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 83.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    9. Taylor expanded in U around inf 61.3%

      \[\leadsto \color{blue}{U \cdot \left(1 + 2 \cdot \frac{J \cdot \ell}{U}\right)} \]
    10. Step-by-step derivation
      1. associate-/l*68.9%

        \[\leadsto U \cdot \left(1 + 2 \cdot \color{blue}{\left(J \cdot \frac{\ell}{U}\right)}\right) \]
    11. Simplified68.9%

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

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

Alternative 10: 71.7% accurate, 2.7× speedup?

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

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

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

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

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

    \[\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 l around 0 93.8%

    \[\leadsto \mathsf{fma}\left(J, \color{blue}{\ell \cdot \left(2 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right)\right)}, U\right) \]
  6. Step-by-step derivation
    1. distribute-lft-in93.8%

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

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

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

      \[\leadsto \mathsf{fma}\left(J, \mathsf{fma}\left(\ell, 2 \cdot \cos \left(0.5 \cdot K\right), \color{blue}{\left(\left(0.3333333333333333 \cdot \cos \left(0.5 \cdot K\right) + {\ell}^{2} \cdot \left(0.0003968253968253968 \cdot \left({\ell}^{2} \cdot \cos \left(0.5 \cdot K\right)\right) + 0.016666666666666666 \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot {\ell}^{2}\right)} \cdot \ell\right), U\right) \]
    5. associate-*l*93.8%

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

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

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

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

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

      \[\leadsto U \cdot \color{blue}{\mathsf{fma}\left(J, \frac{2 \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right) + {\ell}^{3} \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(0.3333333333333333 + {\ell}^{2} \cdot \left(0.016666666666666666 + 0.0003968253968253968 \cdot {\ell}^{2}\right)\right)\right)}{U}, 1\right)} \]
  10. Simplified92.6%

    \[\leadsto \color{blue}{U \cdot \mathsf{fma}\left(J, \frac{\cos \left(0.5 \cdot K\right) \cdot \mathsf{fma}\left({\ell}^{3}, \mathsf{fma}\left({\ell}^{2}, \mathsf{fma}\left({\ell}^{2}, 0.0003968253968253968, 0.016666666666666666\right), 0.3333333333333333\right), 2 \cdot \ell\right)}{U}, 1\right)} \]
  11. Taylor expanded in l around 0 65.6%

    \[\leadsto U \cdot \color{blue}{\left(1 + 2 \cdot \frac{J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)}{U}\right)} \]
  12. Step-by-step derivation
    1. associate-/l*71.6%

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

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

    \[\leadsto U \cdot \color{blue}{\left(1 + 2 \cdot \left(J \cdot \left(\ell \cdot \frac{\cos \left(0.5 \cdot K\right)}{U}\right)\right)\right)} \]
  14. Final simplification71.6%

    \[\leadsto U \cdot \left(1 + 2 \cdot \left(J \cdot \left(\ell \cdot \frac{\cos \left(K \cdot 0.5\right)}{U}\right)\right)\right) \]
  15. Add Preprocessing

Alternative 11: 42.9% accurate, 20.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;J \leq -6.2 \cdot 10^{+150} \lor \neg \left(J \leq 10^{+159}\right):\\
\;\;\;\;J \cdot \left(2 \cdot \ell\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if J < -6.20000000000000028e150 or 9.9999999999999993e158 < J

    1. Initial program 63.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    9. Taylor expanded in J around inf 50.0%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} \]
    10. Step-by-step derivation
      1. *-commutative50.0%

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot 2} \]
      2. associate-*r*50.0%

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} \]
      3. *-commutative50.0%

        \[\leadsto J \cdot \color{blue}{\left(2 \cdot \ell\right)} \]
    11. Simplified50.0%

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

    if -6.20000000000000028e150 < J < 9.9999999999999993e158

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified89.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 42.2%

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

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

Alternative 12: 55.4% accurate, 22.3× speedup?

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

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

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


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

    1. Initial program 78.0%

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

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

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

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

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

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

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

    if 9.5e7 < l

    1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    9. Taylor expanded in J around inf 31.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 95000000:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;J \cdot \left(2 \cdot \ell + \frac{U}{J}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 42.8% accurate, 23.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3.4 \cdot 10^{+34} \lor \neg \left(\ell \leq 95000000\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -3.4e+34) (not (<= l 95000000.0))) (* U U) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -3.4e+34) || !(l <= 95000000.0)) {
		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 <= (-3.4d+34)) .or. (.not. (l <= 95000000.0d0))) 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 <= -3.4e+34) || !(l <= 95000000.0)) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -3.4e+34) or not (l <= 95000000.0):
		tmp = U * U
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -3.4e+34) || !(l <= 95000000.0))
		tmp = Float64(U * U);
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -3.4e+34) || ~((l <= 95000000.0)))
		tmp = U * U;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -3.4e+34], N[Not[LessEqual[l, 95000000.0]], $MachinePrecision]], N[(U * U), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.4 \cdot 10^{+34} \lor \neg \left(\ell \leq 95000000\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -3.3999999999999999e34 or 9.5e7 < l

    1. Initial program 100.0%

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

        \[\leadsto \color{blue}{J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right)\right)} + U \]
      2. fma-define100.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-rr15.7%

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

    if -3.3999999999999999e34 < l < 9.5e7

    1. Initial program 70.7%

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

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

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

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

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

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

Alternative 14: 54.1% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

    \[\leadsto U + \ell \cdot \left(J \cdot 2\right) \]
  10. 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.5%

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

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

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

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

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

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

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

    \[\leadsto 1 \]
  9. Add Preprocessing

Alternative 16: 37.1% 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.5%

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

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

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

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

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

    \[\leadsto U \]
  7. Add Preprocessing

Reproduce

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