| Alternative 1 | |
|---|---|
| Error | 7.9 |
| Cost | 7888 |
(FPCore (x c s) :precision binary64 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
(FPCore (x c s)
:precision binary64
(let* ((t_0 (/ 1.0 (* x (* c s)))) (t_1 (cos (* x 2.0))) (t_2 (* c (* x s))))
(if (<= x -9e-16)
(/ t_1 (* t_2 t_2))
(if (<= x 2e-57) (* t_0 t_0) (/ t_1 (* t_2 (* s (* x c))))))))double code(double x, double c, double s) {
return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
double code(double x, double c, double s) {
double t_0 = 1.0 / (x * (c * s));
double t_1 = cos((x * 2.0));
double t_2 = c * (x * s);
double tmp;
if (x <= -9e-16) {
tmp = t_1 / (t_2 * t_2);
} else if (x <= 2e-57) {
tmp = t_0 * t_0;
} else {
tmp = t_1 / (t_2 * (s * (x * c)));
}
return tmp;
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = 1.0d0 / (x * (c * s))
t_1 = cos((x * 2.0d0))
t_2 = c * (x * s)
if (x <= (-9d-16)) then
tmp = t_1 / (t_2 * t_2)
else if (x <= 2d-57) then
tmp = t_0 * t_0
else
tmp = t_1 / (t_2 * (s * (x * c)))
end if
code = tmp
end function
public static double code(double x, double c, double s) {
return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
public static double code(double x, double c, double s) {
double t_0 = 1.0 / (x * (c * s));
double t_1 = Math.cos((x * 2.0));
double t_2 = c * (x * s);
double tmp;
if (x <= -9e-16) {
tmp = t_1 / (t_2 * t_2);
} else if (x <= 2e-57) {
tmp = t_0 * t_0;
} else {
tmp = t_1 / (t_2 * (s * (x * c)));
}
return tmp;
}
def code(x, c, s): return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
def code(x, c, s): t_0 = 1.0 / (x * (c * s)) t_1 = math.cos((x * 2.0)) t_2 = c * (x * s) tmp = 0 if x <= -9e-16: tmp = t_1 / (t_2 * t_2) elif x <= 2e-57: tmp = t_0 * t_0 else: tmp = t_1 / (t_2 * (s * (x * c))) return tmp
function code(x, c, s) return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) end
function code(x, c, s) t_0 = Float64(1.0 / Float64(x * Float64(c * s))) t_1 = cos(Float64(x * 2.0)) t_2 = Float64(c * Float64(x * s)) tmp = 0.0 if (x <= -9e-16) tmp = Float64(t_1 / Float64(t_2 * t_2)); elseif (x <= 2e-57) tmp = Float64(t_0 * t_0); else tmp = Float64(t_1 / Float64(t_2 * Float64(s * Float64(x * c)))); end return tmp end
function tmp = code(x, c, s) tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x)); end
function tmp_2 = code(x, c, s) t_0 = 1.0 / (x * (c * s)); t_1 = cos((x * 2.0)); t_2 = c * (x * s); tmp = 0.0; if (x <= -9e-16) tmp = t_1 / (t_2 * t_2); elseif (x <= 2e-57) tmp = t_0 * t_0; else tmp = t_1 / (t_2 * (s * (x * c))); end tmp_2 = tmp; end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, c_, s_] := Block[{t$95$0 = N[(1.0 / N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9e-16], N[(t$95$1 / N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2e-57], N[(t$95$0 * t$95$0), $MachinePrecision], N[(t$95$1 / N[(t$95$2 * N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\begin{array}{l}
t_0 := \frac{1}{x \cdot \left(c \cdot s\right)}\\
t_1 := \cos \left(x \cdot 2\right)\\
t_2 := c \cdot \left(x \cdot s\right)\\
\mathbf{if}\;x \leq -9 \cdot 10^{-16}:\\
\;\;\;\;\frac{t_1}{t_2 \cdot t_2}\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-57}:\\
\;\;\;\;t_0 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{t_2 \cdot \left(s \cdot \left(x \cdot c\right)\right)}\\
\end{array}
Results
if x < -9.0000000000000003e-16Initial program 24.8
Simplified2.1
[Start]24.8 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]24.8 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]26.2 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]26.3 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]26.3 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]26.3 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}\right)}
\] |
unpow2 [=>]26.3 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right)}
\] |
unswap-sqr [=>]14.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)}}
\] |
unswap-sqr [=>]2.1 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}}
\] |
Taylor expanded in s around 0 3.9
Taylor expanded in s around 0 2.6
if -9.0000000000000003e-16 < x < 1.99999999999999991e-57Initial program 35.7
Simplified4.2
[Start]35.7 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]35.7 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]45.2 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]45.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]45.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]45.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}\right)}
\] |
unpow2 [=>]45.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right)}
\] |
unswap-sqr [=>]35.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)}}
\] |
unswap-sqr [=>]4.2 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}}
\] |
Taylor expanded in x around 0 4.2
Applied egg-rr4.2
if 1.99999999999999991e-57 < x Initial program 24.4
Simplified2.1
[Start]24.4 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]24.4 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]25.9 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]26.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]26.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]26.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}\right)}
\] |
unpow2 [=>]26.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right)}
\] |
unswap-sqr [=>]13.2 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)}}
\] |
unswap-sqr [=>]2.1 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}}
\] |
Taylor expanded in s around 0 3.5
Taylor expanded in x around 0 3.9
Final simplification3.6
| Alternative 1 | |
|---|---|
| Error | 7.9 |
| Cost | 7888 |
| Alternative 2 | |
|---|---|
| Error | 9.7 |
| Cost | 7625 |
| Alternative 3 | |
|---|---|
| Error | 2.9 |
| Cost | 7625 |
| Alternative 4 | |
|---|---|
| Error | 2.5 |
| Cost | 7488 |
| Alternative 5 | |
|---|---|
| Error | 2.7 |
| Cost | 7360 |
| Alternative 6 | |
|---|---|
| Error | 17.0 |
| Cost | 960 |
| Alternative 7 | |
|---|---|
| Error | 17.1 |
| Cost | 832 |
| Alternative 8 | |
|---|---|
| Error | 18.2 |
| Cost | 832 |
| Alternative 9 | |
|---|---|
| Error | 17.0 |
| Cost | 832 |
herbie shell --seed 2023067
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))