Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.2% → 99.4%
Time: 12.0s
Alternatives: 11
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 11 alternatives:

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

Initial Program: 86.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.4% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

Alternative 2: 96.8% accurate, 1.4× speedup?

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

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

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

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

\mathbf{elif}\;\ell \leq 4.5 \cdot 10^{+61}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.19999999999999961e90 or 4.5e61 < l

    1. Initial program 100.0%

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

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

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

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

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

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

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

    if -4.19999999999999961e90 < l < -6.8e-4 or 5.50000000000000033e-4 < l < 4.5e61

    1. Initial program 99.7%

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

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

    if -6.8e-4 < l < 5.50000000000000033e-4

    1. Initial program 65.7%

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

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. *-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-*r*99.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.2 \cdot 10^{+90}:\\ \;\;\;\;U + \left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq -0.00068:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 0.00055:\\ \;\;\;\;U + \left(J \cdot \ell\right) \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{elif}\;\ell \leq 4.5 \cdot 10^{+61}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left({\ell}^{5} \cdot \left(J \cdot 0.016666666666666666\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \]

Alternative 3: 79.4% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 79.0%

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

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

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

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

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

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

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

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

    1. Initial program 83.4%

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

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

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

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

Alternative 4: 87.3% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.00015 \lor \neg \left(\ell \leq 2.8 \cdot 10^{-5}\right):\\
\;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.49999999999999987e-4 or 2.79999999999999996e-5 < l

    1. Initial program 99.9%

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

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

    if -1.49999999999999987e-4 < l < 2.79999999999999996e-5

    1. Initial program 65.7%

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

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    3. Step-by-step derivation
      1. *-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-*r*99.9%

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

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

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

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

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

Alternative 5: 63.9% accurate, 2.8× speedup?

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

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

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

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

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

Alternative 6: 64.0% accurate, 2.8× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 7: 42.4% accurate, 34.2× speedup?

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

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

\mathbf{elif}\;\ell \leq 1.45:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;U \cdot \left(U - -4\right)\\


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

    1. Initial program 100.0%

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

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

    if -750 < l < 1.44999999999999996

    1. Initial program 66.7%

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

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

    if 1.44999999999999996 < 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. Applied egg-rr10.4%

      \[\leadsto \color{blue}{U \cdot \left(U - -4\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification42.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -750:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 1.45:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(U - -4\right)\\ \end{array} \]

Alternative 8: 42.2% accurate, 34.2× speedup?

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

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

\mathbf{elif}\;\ell \leq 1.76 \cdot 10^{+52}:\\
\;\;\;\;U\\

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


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

    1. Initial program 100.0%

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

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

    if -660 < l < 1.75999999999999993e52

    1. Initial program 68.5%

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

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

    if 1.75999999999999993e52 < 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. *-commutative100.0%

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

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

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

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

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

        \[\leadsto \color{blue}{-4 - U \cdot U} \]
    6. Simplified15.4%

      \[\leadsto \color{blue}{-4 - U \cdot U} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification43.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -660:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 1.76 \cdot 10^{+52}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;-4 - U \cdot U\\ \end{array} \]

Alternative 9: 42.0% accurate, 43.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -22000 or 6.2000000000000001e63 < 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. Applied egg-rr18.6%

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

    if -22000 < l < 6.2000000000000001e63

    1. Initial program 68.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -22000 \lor \neg \left(\ell \leq 6.2 \cdot 10^{+63}\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]

Alternative 10: 54.1% accurate, 44.6× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 11: 36.9% accurate, 312.0× speedup?

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

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

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

    \[\leadsto \color{blue}{U} \]
  3. Final simplification35.2%

    \[\leadsto U \]

Reproduce

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