Average Error: 16.7 → 0.1
Time: 17.2s
Precision: binary64
Cost: 19776
\[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
\[\mathsf{fma}\left(J, \left(2 \cdot \sinh \ell\right) \cdot \cos \left(\frac{K}{2}\right), U\right) \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
(FPCore (J l K U)
 :precision binary64
 (fma J (* (* 2.0 (sinh 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;
}
double code(double J, double l, double K, double U) {
	return fma(J, ((2.0 * sinh(l)) * 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 code(J, l, K, U)
	return fma(J, Float64(Float64(2.0 * sinh(l)) * cos(Float64(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]
code[J_, l_, K_, U_] := N[(J * N[(N[(2.0 * N[Sinh[l], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\mathsf{fma}\left(J, \left(2 \cdot \sinh \ell\right) \cdot \cos \left(\frac{K}{2}\right), U\right)

Error

Derivation

  1. Initial program 16.7

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Simplified16.7

    \[\leadsto \color{blue}{\mathsf{fma}\left(J \cdot \left(e^{\ell} - e^{-\ell}\right), \cos \left(\frac{K}{2}\right), U\right)} \]
    Proof
    (fma.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2)) U): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (*.f64 J (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))) (cos.f64 (/.f64 K 2))) U)): 1 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.1

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(2 \cdot \sinh \ell\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    Proof
    (fma.f64 J (*.f64 (*.f64 2 (sinh.f64 l)) (cos.f64 (/.f64 K 2))) U): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 J (*.f64 (*.f64 2 (sinh.f64 l)) (cos.f64 (/.f64 K 2)))) U)): 2 points increase in error, 1 points decrease in error
    (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 J (*.f64 2 (sinh.f64 l))) (cos.f64 (/.f64 K 2)))) U): 7 points increase in error, 6 points decrease in error
  5. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(J, \left(2 \cdot \sinh \ell\right) \cdot \cos \left(\frac{K}{2}\right), U\right) \]

Alternatives

Alternative 1
Error0.1
Cost13504
\[U + J \cdot \left(\sinh \ell \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right) \]
Alternative 2
Error8.9
Cost7240
\[\begin{array}{l} \mathbf{if}\;U \leq -6.5 \cdot 10^{-218}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \ell\right)\\ \mathbf{elif}\;U \leq 1.6 \cdot 10^{-196}:\\ \;\;\;\;2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \sinh \ell\right)\\ \end{array} \]
Alternative 3
Error8.9
Cost7240
\[\begin{array}{l} \mathbf{if}\;U \leq -1.72 \cdot 10^{-217}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \ell\right)\\ \mathbf{elif}\;U \leq 1.2 \cdot 10^{-194}:\\ \;\;\;\;\cos \left(K \cdot 0.5\right) \cdot \left(\ell \cdot \left(J \cdot 2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \sinh \ell\right)\\ \end{array} \]
Alternative 4
Error0.6
Cost7104
\[U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right) \]
Alternative 5
Error8.3
Cost6848
\[U + 2 \cdot \left(J \cdot \sinh \ell\right) \]
Alternative 6
Error8.5
Cost832
\[U + \frac{J}{\ell \cdot -0.08333333333333333 + 0.5 \cdot \frac{1}{\ell}} \]
Alternative 7
Error8.6
Cost448
\[U + \frac{J}{\frac{0.5}{\ell}} \]
Alternative 8
Error8.6
Cost448
\[U + 2 \cdot \left(J \cdot \ell\right) \]
Alternative 9
Error18.0
Cost64
\[U \]

Error

Reproduce

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