Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.0% → 98.6%
Time: 22.9s
Alternatives: 17
Speedup: 1.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 17 alternatives:

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

Initial Program: 86.0% 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: 98.6% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \cos \left(0.5 \cdot K\right)\\
t_1 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t\_1 \leq -0.2 \lor \neg \left(t\_1 \leq 0\right):\\
\;\;\;\;J \cdot \left(t\_1 \cdot t\_0\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.20000000000000001 or 0.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    4. Taylor expanded in J around inf 100.0%

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

    if -0.20000000000000001 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 0.0

    1. Initial program 77.0%

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

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

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

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

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

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

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

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

Alternative 2: 97.9% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq 3.8 \lor \neg \left(\ell \leq 8 \cdot 10^{+102}\right):\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\

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


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

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

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

    if -4 < l < 3.7999999999999998 or 7.99999999999999982e102 < l

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

    if 3.7999999999999998 < l < 7.99999999999999982e102

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

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

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

Alternative 3: 93.3% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.5 \cdot 10^{+145} \lor \neg \left(\ell \leq -0.44 \lor \neg \left(\ell \leq 3.8\right) \land \ell \leq 5.8 \cdot 10^{+112}\right):\\
\;\;\;\;U + \ell \cdot \left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.49999999999999983e145 or -0.440000000000000002 < l < 3.7999999999999998 or 5.8000000000000004e112 < l

    1. Initial program 85.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 J around 0 85.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.49999999999999983e145 < l < -0.440000000000000002 or 3.7999999999999998 < l < 5.8000000000000004e112

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.5 \cdot 10^{+145} \lor \neg \left(\ell \leq -0.44 \lor \neg \left(\ell \leq 3.8\right) \land \ell \leq 5.8 \cdot 10^{+112}\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 96.5% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\ell \leq 3.8 \lor \neg \left(\ell \leq 1.5 \cdot 10^{+113}\right):\\
\;\;\;\;U + \ell \cdot \left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\

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


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

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

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

    if -4 < l < 3.7999999999999998 or 1.5e113 < l

    1. Initial program 82.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.7999999999999998 < l < 1.5e113

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

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

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

Alternative 5: 78.7% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

    1. Initial program 90.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 J around 0 90.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 76.5% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

    1. Initial program 90.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 J around 0 90.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 87.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5.5 \cdot 10^{+118} \lor \neg \left(\ell \leq -600\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U + -262144\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -5.5e+118) (not (<= l -600.0)))
   (+ U (* l (* J (* (cos (* 0.5 K)) (+ 2.0 (* 0.3333333333333333 (* l l)))))))
   (log1p (expm1 (+ U -262144.0)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -5.5e+118) || !(l <= -600.0)) {
		tmp = U + (l * (J * (cos((0.5 * K)) * (2.0 + (0.3333333333333333 * (l * l))))));
	} else {
		tmp = log1p(expm1((U + -262144.0)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -5.5e+118) || !(l <= -600.0)) {
		tmp = U + (l * (J * (Math.cos((0.5 * K)) * (2.0 + (0.3333333333333333 * (l * l))))));
	} else {
		tmp = Math.log1p(Math.expm1((U + -262144.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -5.5e+118) or not (l <= -600.0):
		tmp = U + (l * (J * (math.cos((0.5 * K)) * (2.0 + (0.3333333333333333 * (l * l))))))
	else:
		tmp = math.log1p(math.expm1((U + -262144.0)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -5.5e+118) || !(l <= -600.0))
		tmp = Float64(U + Float64(l * Float64(J * Float64(cos(Float64(0.5 * K)) * Float64(2.0 + Float64(0.3333333333333333 * Float64(l * l)))))));
	else
		tmp = log1p(expm1(Float64(U + -262144.0)));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -5.5e+118], N[Not[LessEqual[l, -600.0]], $MachinePrecision]], N[(U + N[(l * N[(J * N[(N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision] * N[(2.0 + N[(0.3333333333333333 * N[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[1 + N[(Exp[N[(U + -262144.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.5 \cdot 10^{+118} \lor \neg \left(\ell \leq -600\right):\\
\;\;\;\;U + \ell \cdot \left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U + -262144\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.5000000000000003e118 or -600 < l

    1. Initial program 87.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.5000000000000003e118 < l < -600

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

      \[\leadsto \color{blue}{-4 + U} \]
    6. Step-by-step derivation
      1. +-commutative4.0%

        \[\leadsto \color{blue}{U + -4} \]
    7. Simplified4.0%

      \[\leadsto \color{blue}{U + -4} \]
    8. Applied egg-rr72.7%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(U + -262144\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.5 \cdot 10^{+118} \lor \neg \left(\ell \leq -600\right):\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(U + -262144\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 85.5% accurate, 2.7× speedup?

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

\\
U + \ell \cdot \left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 88.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 J around 0 88.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto U + \ell \cdot \left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \]
  10. Add Preprocessing

Alternative 9: 52.5% accurate, 17.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -650:\\
\;\;\;\;U \cdot \left(0.4444444444444444 + U \cdot \left(U \cdot 0.7901234567901234 - 0.5925925925925926\right)\right) - 0.3333333333333333\\

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


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

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

      \[\leadsto \color{blue}{\frac{U}{U + \left(-4 \cdot U + U \cdot \left(-4 \cdot U\right)\right)}} \]
    6. Step-by-step derivation
      1. associate-+r+1.8%

        \[\leadsto \frac{U}{\color{blue}{\left(U + -4 \cdot U\right) + U \cdot \left(-4 \cdot U\right)}} \]
      2. distribute-rgt1-in1.9%

        \[\leadsto \frac{U}{\color{blue}{\left(-4 + 1\right) \cdot U} + U \cdot \left(-4 \cdot U\right)} \]
      3. metadata-eval1.9%

        \[\leadsto \frac{U}{\color{blue}{-3} \cdot U + U \cdot \left(-4 \cdot U\right)} \]
      4. *-commutative1.9%

        \[\leadsto \frac{U}{\color{blue}{U \cdot -3} + U \cdot \left(-4 \cdot U\right)} \]
      5. distribute-lft-out1.9%

        \[\leadsto \frac{U}{\color{blue}{U \cdot \left(-3 + -4 \cdot U\right)}} \]
      6. associate-/r*1.9%

        \[\leadsto \color{blue}{\frac{\frac{U}{U}}{-3 + -4 \cdot U}} \]
      7. *-inverses1.9%

        \[\leadsto \frac{\color{blue}{1}}{-3 + -4 \cdot U} \]
      8. *-commutative1.9%

        \[\leadsto \frac{1}{-3 + \color{blue}{U \cdot -4}} \]
    7. Simplified1.9%

      \[\leadsto \color{blue}{\frac{1}{-3 + U \cdot -4}} \]
    8. Taylor expanded in U around 0 25.9%

      \[\leadsto \color{blue}{U \cdot \left(0.4444444444444444 + U \cdot \left(0.7901234567901234 \cdot U - 0.5925925925925926\right)\right) - 0.3333333333333333} \]

    if -650 < l

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 41.5% accurate, 23.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6.2e33 or 5.2e17 < 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-rr16.7%

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

    if -6.2e33 < l < 5.2e17

    1. Initial program 78.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*78.5%

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

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

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

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

Alternative 11: 41.7% accurate, 23.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -820:\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{elif}\;\ell \leq 5.2 \cdot 10^{+17}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -820.0) (- -4.0 (* U U)) (if (<= l 5.2e+17) U (* U U))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -820.0) {
		tmp = -4.0 - (U * U);
	} else if (l <= 5.2e+17) {
		tmp = U;
	} else {
		tmp = U * 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 <= (-820.0d0)) then
        tmp = (-4.0d0) - (u * u)
    else if (l <= 5.2d+17) then
        tmp = u
    else
        tmp = u * u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -820.0) {
		tmp = -4.0 - (U * U);
	} else if (l <= 5.2e+17) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -820.0:
		tmp = -4.0 - (U * U)
	elif l <= 5.2e+17:
		tmp = U
	else:
		tmp = U * U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -820.0)
		tmp = Float64(-4.0 - Float64(U * U));
	elseif (l <= 5.2e+17)
		tmp = U;
	else
		tmp = Float64(U * U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -820.0)
		tmp = -4.0 - (U * U);
	elseif (l <= 5.2e+17)
		tmp = U;
	else
		tmp = U * U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -820.0], N[(-4.0 - N[(U * U), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.2e+17], U, N[(U * U), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -820:\\
\;\;\;\;-4 - U \cdot U\\

\mathbf{elif}\;\ell \leq 5.2 \cdot 10^{+17}:\\
\;\;\;\;U\\

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


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

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

      \[\leadsto \color{blue}{-4 + \left(-U\right) \cdot U} \]
    6. Step-by-step derivation
      1. cancel-sign-sub-inv23.2%

        \[\leadsto \color{blue}{-4 - U \cdot U} \]
    7. Simplified23.2%

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

    if -820 < l < 5.2e17

    1. Initial program 77.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*77.7%

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

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

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

    if 5.2e17 < 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-rr19.3%

      \[\leadsto \color{blue}{U \cdot U} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 12: 69.8% accurate, 24.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \ell \cdot \left(J \cdot \left(\color{blue}{1} \cdot \left(0.3333333333333333 \cdot \left(\ell \cdot \ell\right) + 2\right)\right)\right) + U \]
  10. Final simplification69.1%

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

Alternative 13: 53.8% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 36.2% accurate, 312.0× speedup?

\[\begin{array}{l} \\ U \end{array} \]
(FPCore (J l K U) :precision binary64 U)
double code(double J, double l, double K, double U) {
	return U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u
end function
public static double code(double J, double l, double K, double U) {
	return U;
}
def code(J, l, K, U):
	return U
function code(J, l, K, U)
	return U
end
function tmp = code(J, l, K, U)
	tmp = U;
end
code[J_, l_, K_, U_] := U
\begin{array}{l}

\\
U
\end{array}
Derivation
  1. Initial program 88.4%

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

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

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

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

    \[\leadsto \color{blue}{U} \]
  6. Add Preprocessing

Alternative 15: 2.7% accurate, 312.0× speedup?

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

\\
-0.3333333333333333
\end{array}
Derivation
  1. Initial program 88.4%

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

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

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

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

    \[\leadsto \color{blue}{\frac{U}{U + \left(-4 \cdot U + U \cdot \left(-4 \cdot U\right)\right)}} \]
  6. Step-by-step derivation
    1. associate-+r+2.5%

      \[\leadsto \frac{U}{\color{blue}{\left(U + -4 \cdot U\right) + U \cdot \left(-4 \cdot U\right)}} \]
    2. distribute-rgt1-in2.5%

      \[\leadsto \frac{U}{\color{blue}{\left(-4 + 1\right) \cdot U} + U \cdot \left(-4 \cdot U\right)} \]
    3. metadata-eval2.5%

      \[\leadsto \frac{U}{\color{blue}{-3} \cdot U + U \cdot \left(-4 \cdot U\right)} \]
    4. *-commutative2.5%

      \[\leadsto \frac{U}{\color{blue}{U \cdot -3} + U \cdot \left(-4 \cdot U\right)} \]
    5. distribute-lft-out2.5%

      \[\leadsto \frac{U}{\color{blue}{U \cdot \left(-3 + -4 \cdot U\right)}} \]
    6. associate-/r*2.5%

      \[\leadsto \color{blue}{\frac{\frac{U}{U}}{-3 + -4 \cdot U}} \]
    7. *-inverses2.5%

      \[\leadsto \frac{\color{blue}{1}}{-3 + -4 \cdot U} \]
    8. *-commutative2.5%

      \[\leadsto \frac{1}{-3 + \color{blue}{U \cdot -4}} \]
  7. Simplified2.5%

    \[\leadsto \color{blue}{\frac{1}{-3 + U \cdot -4}} \]
  8. Taylor expanded in U around 0 3.0%

    \[\leadsto \color{blue}{-0.3333333333333333} \]
  9. Add Preprocessing

Alternative 16: 2.7% accurate, 312.0× speedup?

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

\\
-4
\end{array}
Derivation
  1. Initial program 88.4%

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

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

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

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

    \[\leadsto \color{blue}{-4 + U} \]
  6. Step-by-step derivation
    1. +-commutative27.0%

      \[\leadsto \color{blue}{U + -4} \]
  7. Simplified27.0%

    \[\leadsto \color{blue}{U + -4} \]
  8. Taylor expanded in U around 0 3.0%

    \[\leadsto \color{blue}{-4} \]
  9. Add Preprocessing

Alternative 17: 2.8% accurate, 312.0× speedup?

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

\\
-19683
\end{array}
Derivation
  1. Initial program 88.4%

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

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

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

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

    \[\leadsto \color{blue}{\frac{U}{U + \left(-4 \cdot U + U \cdot \left(-4 \cdot U\right)\right)}} \]
  6. Step-by-step derivation
    1. associate-+r+2.5%

      \[\leadsto \frac{U}{\color{blue}{\left(U + -4 \cdot U\right) + U \cdot \left(-4 \cdot U\right)}} \]
    2. distribute-rgt1-in2.5%

      \[\leadsto \frac{U}{\color{blue}{\left(-4 + 1\right) \cdot U} + U \cdot \left(-4 \cdot U\right)} \]
    3. metadata-eval2.5%

      \[\leadsto \frac{U}{\color{blue}{-3} \cdot U + U \cdot \left(-4 \cdot U\right)} \]
    4. *-commutative2.5%

      \[\leadsto \frac{U}{\color{blue}{U \cdot -3} + U \cdot \left(-4 \cdot U\right)} \]
    5. distribute-lft-out2.5%

      \[\leadsto \frac{U}{\color{blue}{U \cdot \left(-3 + -4 \cdot U\right)}} \]
    6. associate-/r*2.5%

      \[\leadsto \color{blue}{\frac{\frac{U}{U}}{-3 + -4 \cdot U}} \]
    7. *-inverses2.5%

      \[\leadsto \frac{\color{blue}{1}}{-3 + -4 \cdot U} \]
    8. *-commutative2.5%

      \[\leadsto \frac{1}{-3 + \color{blue}{U \cdot -4}} \]
  7. Simplified2.5%

    \[\leadsto \color{blue}{\frac{1}{-3 + U \cdot -4}} \]
  8. Applied egg-rr2.9%

    \[\leadsto \color{blue}{U \cdot -262144 + -19683} \]
  9. Taylor expanded in U around 0 2.9%

    \[\leadsto \color{blue}{-19683} \]
  10. Add Preprocessing

Reproduce

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