| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 20544 |
\[\left(J \cdot \left(2 \cdot \ell + \left(0.3333333333333333 \cdot {\ell}^{3} + 0.016666666666666666 \cdot {\ell}^{5}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\]
(FPCore (J l K U) :precision binary64 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
(FPCore (J l K U)
:precision binary64
(+
(*
(*
J
(+
(* 0.3333333333333333 (pow l 3.0))
(+
(* 2.0 l)
(+
(* 0.0003968253968253968 (pow l 7.0))
(* 0.016666666666666666 (pow l 5.0))))))
(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 ((J * ((0.3333333333333333 * pow(l, 3.0)) + ((2.0 * l) + ((0.0003968253968253968 * pow(l, 7.0)) + (0.016666666666666666 * pow(l, 5.0)))))) * 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
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 * ((0.3333333333333333d0 * (l ** 3.0d0)) + ((2.0d0 * l) + ((0.0003968253968253968d0 * (l ** 7.0d0)) + (0.016666666666666666d0 * (l ** 5.0d0)))))) * 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;
}
public static double code(double J, double l, double K, double U) {
return ((J * ((0.3333333333333333 * Math.pow(l, 3.0)) + ((2.0 * l) + ((0.0003968253968253968 * Math.pow(l, 7.0)) + (0.016666666666666666 * Math.pow(l, 5.0)))))) * 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
def code(J, l, K, U): return ((J * ((0.3333333333333333 * math.pow(l, 3.0)) + ((2.0 * l) + ((0.0003968253968253968 * math.pow(l, 7.0)) + (0.016666666666666666 * math.pow(l, 5.0)))))) * 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 code(J, l, K, U) return Float64(Float64(Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(Float64(2.0 * l) + Float64(Float64(0.0003968253968253968 * (l ^ 7.0)) + Float64(0.016666666666666666 * (l ^ 5.0)))))) * 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
function tmp = code(J, l, K, U) tmp = ((J * ((0.3333333333333333 * (l ^ 3.0)) + ((2.0 * l) + ((0.0003968253968253968 * (l ^ 7.0)) + (0.016666666666666666 * (l ^ 5.0)))))) * 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]
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 * l), $MachinePrecision] + N[(N[(0.0003968253968253968 * N[Power[l, 7.0], $MachinePrecision]), $MachinePrecision] + N[(0.016666666666666666 * N[Power[l, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 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
\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \left(2 \cdot \ell + \left(0.0003968253968253968 \cdot {\ell}^{7} + 0.016666666666666666 \cdot {\ell}^{5}\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
Results
Initial program 17.4
Taylor expanded in l around 0 0.3
Simplified0.3
[Start]0.3 | \[ \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \left(0.0003968253968253968 \cdot {\ell}^{7} + \left(0.016666666666666666 \cdot {\ell}^{5} + 2 \cdot \ell\right)\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.3 | \[ \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \left(0.0003968253968253968 \cdot {\ell}^{7} + \color{blue}{\left(2 \cdot \ell + 0.016666666666666666 \cdot {\ell}^{5}\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\] |
rational_best_oopsla_all_46_json_45_simplify-82 [=>]0.3 | \[ \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \color{blue}{\left(2 \cdot \ell + \left(0.0003968253968253968 \cdot {\ell}^{7} + 0.016666666666666666 \cdot {\ell}^{5}\right)\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 20544 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 13824 |
| Alternative 3 | |
|---|---|
| Error | 9.9 |
| Cost | 7504 |
| Alternative 4 | |
|---|---|
| Error | 0.6 |
| Cost | 7104 |
| Alternative 5 | |
|---|---|
| Error | 9.2 |
| Cost | 448 |
| Alternative 6 | |
|---|---|
| Error | 18.6 |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (J l K U)
:name "Maksimov and Kolovsky, Equation (4)"
:precision binary64
(+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))