| Alternative 1 | |
|---|---|
| Error | 2% |
| Cost | 33540 |
(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 (* x (* c s))) (t_1 (cos (+ x x))))
(if (or (<= s -1.08e-200) (not (<= s 5.2e-192)))
(* t_1 (pow (* s (* x c)) -2.0))
(* (/ t_1 t_0) (/ 1.0 t_0)))))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 = x * (c * s);
double t_1 = cos((x + x));
double tmp;
if ((s <= -1.08e-200) || !(s <= 5.2e-192)) {
tmp = t_1 * pow((s * (x * c)), -2.0);
} else {
tmp = (t_1 / t_0) * (1.0 / t_0);
}
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) :: tmp
t_0 = x * (c * s)
t_1 = cos((x + x))
if ((s <= (-1.08d-200)) .or. (.not. (s <= 5.2d-192))) then
tmp = t_1 * ((s * (x * c)) ** (-2.0d0))
else
tmp = (t_1 / t_0) * (1.0d0 / t_0)
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 = x * (c * s);
double t_1 = Math.cos((x + x));
double tmp;
if ((s <= -1.08e-200) || !(s <= 5.2e-192)) {
tmp = t_1 * Math.pow((s * (x * c)), -2.0);
} else {
tmp = (t_1 / t_0) * (1.0 / t_0);
}
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 = x * (c * s) t_1 = math.cos((x + x)) tmp = 0 if (s <= -1.08e-200) or not (s <= 5.2e-192): tmp = t_1 * math.pow((s * (x * c)), -2.0) else: tmp = (t_1 / t_0) * (1.0 / t_0) 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(x * Float64(c * s)) t_1 = cos(Float64(x + x)) tmp = 0.0 if ((s <= -1.08e-200) || !(s <= 5.2e-192)) tmp = Float64(t_1 * (Float64(s * Float64(x * c)) ^ -2.0)); else tmp = Float64(Float64(t_1 / t_0) * Float64(1.0 / t_0)); 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 = x * (c * s); t_1 = cos((x + x)); tmp = 0.0; if ((s <= -1.08e-200) || ~((s <= 5.2e-192))) tmp = t_1 * ((s * (x * c)) ^ -2.0); else tmp = (t_1 / t_0) * (1.0 / t_0); 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[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[s, -1.08e-200], N[Not[LessEqual[s, 5.2e-192]], $MachinePrecision]], N[(t$95$1 * N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 / t$95$0), $MachinePrecision] * N[(1.0 / t$95$0), $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 := x \cdot \left(c \cdot s\right)\\
t_1 := \cos \left(x + x\right)\\
\mathbf{if}\;s \leq -1.08 \cdot 10^{-200} \lor \neg \left(s \leq 5.2 \cdot 10^{-192}\right):\\
\;\;\;\;t_1 \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{t_0} \cdot \frac{1}{t_0}\\
\end{array}
Results
if s < -1.08000000000000002e-200 or 5.2000000000000003e-192 < s Initial program 37.86
Simplified4.5
[Start]37.86 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]37.86 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]44.59 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]44.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]44.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]44.6 | \[ \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 [=>]44.6 | \[ \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 [=>]30.1 | \[ \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.5 | \[ \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 inf 44.59
Simplified2.89
[Start]44.59 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
|---|---|
count-2 [<=]44.59 | \[ \frac{\cos \color{blue}{\left(x + x\right)}}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
associate-*r* [=>]44.6 | \[ \frac{\cos \left(x + x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}}
\] |
unpow2 [=>]44.6 | \[ \frac{\cos \left(x + x\right)}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{\left(x \cdot x\right)}}
\] |
associate-/r* [=>]44.54 | \[ \color{blue}{\frac{\frac{\cos \left(x + x\right)}{{c}^{2} \cdot {s}^{2}}}{x \cdot x}}
\] |
unpow2 [=>]44.54 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}}}{x \cdot x}
\] |
unpow2 [=>]44.54 | \[ \frac{\frac{\cos \left(x + x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}}}{x \cdot x}
\] |
swap-sqr [<=]30.13 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}}{x \cdot x}
\] |
unpow2 [<=]30.13 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}}}}{x \cdot x}
\] |
*-lft-identity [<=]30.13 | \[ \frac{\color{blue}{1 \cdot \frac{\cos \left(x + x\right)}{{\left(c \cdot s\right)}^{2}}}}{x \cdot x}
\] |
associate-*l/ [<=]30.79 | \[ \color{blue}{\frac{1}{x \cdot x} \cdot \frac{\cos \left(x + x\right)}{{\left(c \cdot s\right)}^{2}}}
\] |
unpow2 [=>]30.79 | \[ \frac{1}{x \cdot x} \cdot \frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}
\] |
associate-/r* [=>]30.66 | \[ \frac{1}{x \cdot x} \cdot \color{blue}{\frac{\frac{\cos \left(x + x\right)}{c \cdot s}}{c \cdot s}}
\] |
times-frac [<=]24.34 | \[ \color{blue}{\frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\left(x \cdot x\right) \cdot \left(c \cdot s\right)}}
\] |
*-commutative [<=]24.34 | \[ \frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\color{blue}{\left(c \cdot s\right) \cdot \left(x \cdot x\right)}}
\] |
associate-*r* [=>]10.54 | \[ \frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right) \cdot x}}
\] |
*-commutative [<=]10.54 | \[ \frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right)} \cdot x}
\] |
if -1.08000000000000002e-200 < s < 5.2000000000000003e-192Initial program 100
Simplified8.39
[Start]100 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]100 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]100 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]100 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]100 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]100 | \[ \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 [=>]100 | \[ \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 [=>]42.86 | \[ \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 [=>]8.39 | \[ \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)}}
\] |
Applied egg-rr8.31
Final simplification3.39
| Alternative 1 | |
|---|---|
| Error | 2% |
| Cost | 33540 |
| Alternative 2 | |
|---|---|
| Error | 26.45% |
| Cost | 7888 |
| Alternative 3 | |
|---|---|
| Error | 3.87% |
| Cost | 7753 |
| Alternative 4 | |
|---|---|
| Error | 11.17% |
| Cost | 7625 |
| Alternative 5 | |
|---|---|
| Error | 3.86% |
| Cost | 7625 |
| Alternative 6 | |
|---|---|
| Error | 12.27% |
| Cost | 7624 |
| Alternative 7 | |
|---|---|
| Error | 4.81% |
| Cost | 7360 |
| Alternative 8 | |
|---|---|
| Error | 32.52% |
| Cost | 964 |
| Alternative 9 | |
|---|---|
| Error | 29.53% |
| Cost | 964 |
| Alternative 10 | |
|---|---|
| Error | 30.62% |
| Cost | 964 |
| Alternative 11 | |
|---|---|
| Error | 25.86% |
| Cost | 960 |
| Alternative 12 | |
|---|---|
| Error | 35.23% |
| Cost | 832 |
| Alternative 13 | |
|---|---|
| Error | 25.95% |
| Cost | 832 |
| Alternative 14 | |
|---|---|
| Error | 26.06% |
| Cost | 832 |
| Alternative 15 | |
|---|---|
| Error | 25.83% |
| Cost | 832 |
herbie shell --seed 2023102
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))