| Alternative 1 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 13572 |

(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 (cos (+ x x))))
(if (<= s 4e+198)
(* (pow (* s (* x c)) -2.0) t_0)
(/ t_0 (pow (* x (* s c)) 2.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 = cos((x + x));
double tmp;
if (s <= 4e+198) {
tmp = pow((s * (x * c)), -2.0) * t_0;
} else {
tmp = t_0 / pow((x * (s * c)), 2.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) :: tmp
t_0 = cos((x + x))
if (s <= 4d+198) then
tmp = ((s * (x * c)) ** (-2.0d0)) * t_0
else
tmp = t_0 / ((x * (s * c)) ** 2.0d0)
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 = Math.cos((x + x));
double tmp;
if (s <= 4e+198) {
tmp = Math.pow((s * (x * c)), -2.0) * t_0;
} else {
tmp = t_0 / Math.pow((x * (s * c)), 2.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 = math.cos((x + x)) tmp = 0 if s <= 4e+198: tmp = math.pow((s * (x * c)), -2.0) * t_0 else: tmp = t_0 / math.pow((x * (s * c)), 2.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 = cos(Float64(x + x)) tmp = 0.0 if (s <= 4e+198) tmp = Float64((Float64(s * Float64(x * c)) ^ -2.0) * t_0); else tmp = Float64(t_0 / (Float64(x * Float64(s * c)) ^ 2.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 = cos((x + x)); tmp = 0.0; if (s <= 4e+198) tmp = ((s * (x * c)) ^ -2.0) * t_0; else tmp = t_0 / ((x * (s * c)) ^ 2.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[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[s, 4e+198], N[(N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision] * t$95$0), $MachinePrecision], N[(t$95$0 / N[Power[N[(x * N[(s * c), $MachinePrecision]), $MachinePrecision], 2.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 := \cos \left(x + x\right)\\
\mathbf{if}\;s \leq 4 \cdot 10^{+198}:\\
\;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2} \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{{\left(x \cdot \left(s \cdot c\right)\right)}^{2}}\\
\end{array}
Results
if s < 4.00000000000000007e198Initial program 61.5%
Simplified97.5%
[Start]61.5 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]61.5 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(x \cdot \left(x \cdot {s}^{2}\right)\right)}}
\] |
associate-*r* [=>]52.3 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot {s}^{2}\right)}}
\] |
associate-*r* [=>]55.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot \left(x \cdot x\right)\right) \cdot {s}^{2}}}
\] |
unpow2 [=>]55.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot x\right)\right) \cdot {s}^{2}}
\] |
unswap-sqr [=>]74.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right)} \cdot {s}^{2}}
\] |
unpow2 [=>]74.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(\left(c \cdot x\right) \cdot \left(c \cdot x\right)\right) \cdot \color{blue}{\left(s \cdot s\right)}}
\] |
swap-sqr [<=]97.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(\left(c \cdot x\right) \cdot s\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)}}
\] |
*-commutative [<=]97.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(s \cdot \left(c \cdot x\right)\right)} \cdot \left(\left(c \cdot x\right) \cdot s\right)}
\] |
*-commutative [<=]97.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(c \cdot x\right)\right) \cdot \color{blue}{\left(s \cdot \left(c \cdot x\right)\right)}}
\] |
*-commutative [=>]97.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \color{blue}{\left(x \cdot c\right)}\right) \cdot \left(s \cdot \left(c \cdot x\right)\right)}
\] |
*-commutative [=>]97.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \color{blue}{\left(x \cdot c\right)}\right)}
\] |
Applied egg-rr97.7%
[Start]97.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}
\] |
|---|---|
clear-num [=>]97.4 | \[ \color{blue}{\frac{1}{\frac{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)}{\cos \left(2 \cdot x\right)}}}
\] |
associate-/r/ [=>]97.4 | \[ \color{blue}{\frac{1}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot c\right)\right)} \cdot \cos \left(2 \cdot x\right)}
\] |
pow2 [=>]97.4 | \[ \frac{1}{\color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{2}}} \cdot \cos \left(2 \cdot x\right)
\] |
pow-flip [=>]97.7 | \[ \color{blue}{{\left(s \cdot \left(x \cdot c\right)\right)}^{\left(-2\right)}} \cdot \cos \left(2 \cdot x\right)
\] |
metadata-eval [=>]97.7 | \[ {\left(s \cdot \left(x \cdot c\right)\right)}^{\color{blue}{-2}} \cdot \cos \left(2 \cdot x\right)
\] |
cos-2 [=>]98.0 | \[ {\left(s \cdot \left(x \cdot c\right)\right)}^{-2} \cdot \color{blue}{\left(\cos x \cdot \cos x - \sin x \cdot \sin x\right)}
\] |
cos-sum [<=]97.7 | \[ {\left(s \cdot \left(x \cdot c\right)\right)}^{-2} \cdot \color{blue}{\cos \left(x + x\right)}
\] |
if 4.00000000000000007e198 < s Initial program 68.5%
Simplified68.4%
[Start]68.5 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
associate-*r* [=>]68.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right) \cdot x}}
\] |
*-commutative [=>]68.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{x \cdot \left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right)}}
\] |
associate-*r* [=>]68.4 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \color{blue}{\left(\left({c}^{2} \cdot x\right) \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]68.4 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(\left(\color{blue}{\left(c \cdot c\right)} \cdot x\right) \cdot {s}^{2}\right)}
\] |
unpow2 [=>]68.4 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(\left(\left(c \cdot c\right) \cdot x\right) \cdot \color{blue}{\left(s \cdot s\right)}\right)}
\] |
Taylor expanded in x around inf 63.9%
Simplified99.7%
[Start]63.9 | \[ \frac{\cos \left(2 \cdot x\right)}{{s}^{2} \cdot \left({c}^{2} \cdot {x}^{2}\right)}
\] |
|---|---|
count-2 [<=]63.9 | \[ \frac{\cos \color{blue}{\left(x + x\right)}}{{s}^{2} \cdot \left({c}^{2} \cdot {x}^{2}\right)}
\] |
associate-*r* [=>]63.9 | \[ \frac{\cos \left(x + x\right)}{\color{blue}{\left({s}^{2} \cdot {c}^{2}\right) \cdot {x}^{2}}}
\] |
unpow2 [=>]63.9 | \[ \frac{\cos \left(x + x\right)}{\left(\color{blue}{\left(s \cdot s\right)} \cdot {c}^{2}\right) \cdot {x}^{2}}
\] |
unpow2 [=>]63.9 | \[ \frac{\cos \left(x + x\right)}{\left(\left(s \cdot s\right) \cdot \color{blue}{\left(c \cdot c\right)}\right) \cdot {x}^{2}}
\] |
unswap-sqr [=>]86.5 | \[ \frac{\cos \left(x + x\right)}{\color{blue}{\left(\left(s \cdot c\right) \cdot \left(s \cdot c\right)\right)} \cdot {x}^{2}}
\] |
unpow2 [=>]86.5 | \[ \frac{\cos \left(x + x\right)}{\left(\left(s \cdot c\right) \cdot \left(s \cdot c\right)\right) \cdot \color{blue}{\left(x \cdot x\right)}}
\] |
swap-sqr [<=]99.7 | \[ \frac{\cos \left(x + x\right)}{\color{blue}{\left(\left(s \cdot c\right) \cdot x\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)}}
\] |
rem-square-sqrt [<=]27.2 | \[ \frac{\cos \left(x + x\right)}{\left(\left(s \cdot c\right) \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)}
\] |
associate-*l* [<=]27.2 | \[ \frac{\cos \left(x + x\right)}{\color{blue}{\left(\left(\left(s \cdot c\right) \cdot \sqrt{x}\right) \cdot \sqrt{x}\right)} \cdot \left(\left(s \cdot c\right) \cdot x\right)}
\] |
associate-*r* [<=]27.2 | \[ \frac{\cos \left(x + x\right)}{\left(\color{blue}{\left(s \cdot \left(c \cdot \sqrt{x}\right)\right)} \cdot \sqrt{x}\right) \cdot \left(\left(s \cdot c\right) \cdot x\right)}
\] |
rem-square-sqrt [<=]27.2 | \[ \frac{\cos \left(x + x\right)}{\left(\left(s \cdot \left(c \cdot \sqrt{x}\right)\right) \cdot \sqrt{x}\right) \cdot \left(\left(s \cdot c\right) \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}\right)}
\] |
associate-*l* [<=]27.2 | \[ \frac{\cos \left(x + x\right)}{\left(\left(s \cdot \left(c \cdot \sqrt{x}\right)\right) \cdot \sqrt{x}\right) \cdot \color{blue}{\left(\left(\left(s \cdot c\right) \cdot \sqrt{x}\right) \cdot \sqrt{x}\right)}}
\] |
associate-*r* [<=]27.2 | \[ \frac{\cos \left(x + x\right)}{\left(\left(s \cdot \left(c \cdot \sqrt{x}\right)\right) \cdot \sqrt{x}\right) \cdot \left(\color{blue}{\left(s \cdot \left(c \cdot \sqrt{x}\right)\right)} \cdot \sqrt{x}\right)}
\] |
unpow2 [<=]27.2 | \[ \frac{\cos \left(x + x\right)}{\color{blue}{{\left(\left(s \cdot \left(c \cdot \sqrt{x}\right)\right) \cdot \sqrt{x}\right)}^{2}}}
\] |
associate-*r* [=>]27.2 | \[ \frac{\cos \left(x + x\right)}{{\left(\color{blue}{\left(\left(s \cdot c\right) \cdot \sqrt{x}\right)} \cdot \sqrt{x}\right)}^{2}}
\] |
associate-*l* [=>]27.1 | \[ \frac{\cos \left(x + x\right)}{{\color{blue}{\left(\left(s \cdot c\right) \cdot \left(\sqrt{x} \cdot \sqrt{x}\right)\right)}}^{2}}
\] |
rem-square-sqrt [=>]99.7 | \[ \frac{\cos \left(x + x\right)}{{\left(\left(s \cdot c\right) \cdot \color{blue}{x}\right)}^{2}}
\] |
Final simplification97.9%
| Alternative 1 | |
|---|---|
| Accuracy | 97.5% |
| Cost | 13572 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.1% |
| Cost | 7888 |
| Alternative 3 | |
|---|---|
| Accuracy | 95.7% |
| Cost | 7625 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.3% |
| Cost | 7492 |
| Alternative 5 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 7360 |
| Alternative 6 | |
|---|---|
| Accuracy | 78.2% |
| Cost | 960 |
| Alternative 7 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 832 |
| Alternative 8 | |
|---|---|
| Accuracy | 75.2% |
| Cost | 832 |
| Alternative 9 | |
|---|---|
| Accuracy | 78.1% |
| Cost | 832 |
herbie shell --seed 2023160
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))