| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 26048 |

(FPCore (x) :precision binary64 (* (cos x) (exp (* 10.0 (* x x)))))
(FPCore (x) :precision binary64 (* (cos x) (pow (pow (exp 20.0) x) (* x 0.5))))
double code(double x) {
return cos(x) * exp((10.0 * (x * x)));
}
double code(double x) {
return cos(x) * pow(pow(exp(20.0), x), (x * 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = cos(x) * exp((10.0d0 * (x * x)))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = cos(x) * ((exp(20.0d0) ** x) ** (x * 0.5d0))
end function
public static double code(double x) {
return Math.cos(x) * Math.exp((10.0 * (x * x)));
}
public static double code(double x) {
return Math.cos(x) * Math.pow(Math.pow(Math.exp(20.0), x), (x * 0.5));
}
def code(x): return math.cos(x) * math.exp((10.0 * (x * x)))
def code(x): return math.cos(x) * math.pow(math.pow(math.exp(20.0), x), (x * 0.5))
function code(x) return Float64(cos(x) * exp(Float64(10.0 * Float64(x * x)))) end
function code(x) return Float64(cos(x) * ((exp(20.0) ^ x) ^ Float64(x * 0.5))) end
function tmp = code(x) tmp = cos(x) * exp((10.0 * (x * x))); end
function tmp = code(x) tmp = cos(x) * ((exp(20.0) ^ x) ^ (x * 0.5)); end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Exp[N[(10.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Power[N[Exp[20.0], $MachinePrecision], x], $MachinePrecision], N[(x * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\cos x \cdot e^{10 \cdot \left(x \cdot x\right)}
\cos x \cdot {\left({\left(e^{20}\right)}^{x}\right)}^{\left(x \cdot 0.5\right)}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 94.5%
Applied egg-rr98.9%
[Start]94.5% | \[ \cos x \cdot e^{10 \cdot \left(x \cdot x\right)}
\] |
|---|---|
pow-exp [<=]95.2% | \[ \cos x \cdot \color{blue}{{\left(e^{10}\right)}^{\left(x \cdot x\right)}}
\] |
*-commutative [=>]95.2% | \[ \color{blue}{{\left(e^{10}\right)}^{\left(x \cdot x\right)} \cdot \cos x}
\] |
pow-exp [=>]94.5% | \[ \color{blue}{e^{10 \cdot \left(x \cdot x\right)}} \cdot \cos x
\] |
associate-*r* [=>]94.3% | \[ e^{\color{blue}{\left(10 \cdot x\right) \cdot x}} \cdot \cos x
\] |
add-log-exp [=>]94.3% | \[ e^{\left(10 \cdot x\right) \cdot \color{blue}{\log \left(e^{x}\right)}} \cdot \cos x
\] |
log-pow [<=]94.3% | \[ e^{\color{blue}{\log \left({\left(e^{x}\right)}^{\left(10 \cdot x\right)}\right)}} \cdot \cos x
\] |
pow-pow [<=]94.8% | \[ e^{\log \color{blue}{\left({\left({\left(e^{x}\right)}^{10}\right)}^{x}\right)}} \cdot \cos x
\] |
add-exp-log [<=]96.9% | \[ \color{blue}{{\left({\left(e^{x}\right)}^{10}\right)}^{x}} \cdot \cos x
\] |
add-cbrt-cube [=>]96.8% | \[ \color{blue}{\sqrt[3]{\left({\left({\left(e^{x}\right)}^{10}\right)}^{x} \cdot {\left({\left(e^{x}\right)}^{10}\right)}^{x}\right) \cdot {\left({\left(e^{x}\right)}^{10}\right)}^{x}}} \cdot \cos x
\] |
add-cbrt-cube [=>]96.8% | \[ \sqrt[3]{\left({\left({\left(e^{x}\right)}^{10}\right)}^{x} \cdot {\left({\left(e^{x}\right)}^{10}\right)}^{x}\right) \cdot {\left({\left(e^{x}\right)}^{10}\right)}^{x}} \cdot \color{blue}{\sqrt[3]{\left(\cos x \cdot \cos x\right) \cdot \cos x}}
\] |
cbrt-unprod [=>]96.8% | \[ \color{blue}{\sqrt[3]{\left(\left({\left({\left(e^{x}\right)}^{10}\right)}^{x} \cdot {\left({\left(e^{x}\right)}^{10}\right)}^{x}\right) \cdot {\left({\left(e^{x}\right)}^{10}\right)}^{x}\right) \cdot \left(\left(\cos x \cdot \cos x\right) \cdot \cos x\right)}}
\] |
Applied egg-rr98.9%
[Start]98.9% | \[ \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot {\cos x}^{3}}
\] |
|---|---|
add-cube-cbrt [=>]98.9% | \[ \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \color{blue}{\left(\left(\sqrt[3]{{\cos x}^{3}} \cdot \sqrt[3]{{\cos x}^{3}}\right) \cdot \sqrt[3]{{\cos x}^{3}}\right)}}
\] |
rem-cbrt-cube [=>]98.9% | \[ \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \left(\left(\color{blue}{\cos x} \cdot \sqrt[3]{{\cos x}^{3}}\right) \cdot \sqrt[3]{{\cos x}^{3}}\right)}
\] |
rem-cbrt-cube [=>]98.9% | \[ \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \left(\left(\cos x \cdot \color{blue}{\cos x}\right) \cdot \sqrt[3]{{\cos x}^{3}}\right)}
\] |
pow2 [=>]98.9% | \[ \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \left(\color{blue}{{\cos x}^{2}} \cdot \sqrt[3]{{\cos x}^{3}}\right)}
\] |
rem-cbrt-cube [=>]98.9% | \[ \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \left({\cos x}^{2} \cdot \color{blue}{\cos x}\right)}
\] |
Taylor expanded in x around inf 94.0%
Simplified95.5%
[Start]94.0% | \[ {\left({\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot 1\right)}^{0.3333333333333333} \cdot \cos x
\] |
|---|---|
*-commutative [=>]94.0% | \[ \color{blue}{\cos x \cdot {\left({\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot 1\right)}^{0.3333333333333333}}
\] |
unpow1/3 [=>]98.8% | \[ \cos x \cdot \color{blue}{\sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot 1}}
\] |
*-rgt-identity [=>]98.8% | \[ \cos x \cdot \sqrt[3]{\color{blue}{{\left({\left(e^{30}\right)}^{x}\right)}^{x}}}
\] |
exp-prod [<=]95.4% | \[ \cos x \cdot \sqrt[3]{{\color{blue}{\left(e^{30 \cdot x}\right)}}^{x}}
\] |
*-commutative [<=]95.4% | \[ \cos x \cdot \sqrt[3]{{\left(e^{\color{blue}{x \cdot 30}}\right)}^{x}}
\] |
exp-prod [<=]95.2% | \[ \cos x \cdot \sqrt[3]{\color{blue}{e^{\left(x \cdot 30\right) \cdot x}}}
\] |
*-commutative [<=]95.2% | \[ \cos x \cdot \sqrt[3]{e^{\color{blue}{x \cdot \left(x \cdot 30\right)}}}
\] |
exp-prod [=>]95.5% | \[ \cos x \cdot \sqrt[3]{\color{blue}{{\left(e^{x}\right)}^{\left(x \cdot 30\right)}}}
\] |
Applied egg-rr99.4%
[Start]95.5% | \[ \cos x \cdot \sqrt[3]{{\left(e^{x}\right)}^{\left(x \cdot 30\right)}}
\] |
|---|---|
add-exp-log [=>]94.6% | \[ \cos x \cdot \color{blue}{e^{\log \left(\sqrt[3]{{\left(e^{x}\right)}^{\left(x \cdot 30\right)}}\right)}}
\] |
pow1/3 [=>]94.1% | \[ \cos x \cdot e^{\log \color{blue}{\left({\left({\left(e^{x}\right)}^{\left(x \cdot 30\right)}\right)}^{0.3333333333333333}\right)}}
\] |
pow-pow [=>]93.7% | \[ \cos x \cdot e^{\log \color{blue}{\left({\left(e^{x}\right)}^{\left(\left(x \cdot 30\right) \cdot 0.3333333333333333\right)}\right)}}
\] |
log-pow [=>]93.9% | \[ \cos x \cdot e^{\color{blue}{\left(\left(x \cdot 30\right) \cdot 0.3333333333333333\right) \cdot \log \left(e^{x}\right)}}
\] |
add-log-exp [<=]93.9% | \[ \cos x \cdot e^{\left(\left(x \cdot 30\right) \cdot 0.3333333333333333\right) \cdot \color{blue}{x}}
\] |
pow-exp [<=]94.0% | \[ \cos x \cdot \color{blue}{{\left(e^{\left(x \cdot 30\right) \cdot 0.3333333333333333}\right)}^{x}}
\] |
pow-exp [<=]94.5% | \[ \cos x \cdot {\color{blue}{\left({\left(e^{x \cdot 30}\right)}^{0.3333333333333333}\right)}}^{x}
\] |
*-commutative [=>]94.5% | \[ \cos x \cdot {\left({\left(e^{\color{blue}{30 \cdot x}}\right)}^{0.3333333333333333}\right)}^{x}
\] |
pow-exp [<=]94.0% | \[ \cos x \cdot {\left({\color{blue}{\left({\left(e^{30}\right)}^{x}\right)}}^{0.3333333333333333}\right)}^{x}
\] |
Final simplification99.4%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 26048 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 25920 |
| Alternative 3 | |
|---|---|
| Accuracy | 95.2% |
| Cost | 19648 |
| Alternative 4 | |
|---|---|
| Accuracy | 95.3% |
| Cost | 19584 |
| Alternative 5 | |
|---|---|
| Accuracy | 95.2% |
| Cost | 19584 |
| Alternative 6 | |
|---|---|
| Accuracy | 94.5% |
| Cost | 13248 |
| Alternative 7 | |
|---|---|
| Accuracy | 9.6% |
| Cost | 6464 |
| Alternative 8 | |
|---|---|
| Accuracy | 1.5% |
| Cost | 448 |
herbie shell --seed 2023178
(FPCore (x)
:name "ENA, Section 1.4, Exercise 1"
:precision binary64
:pre (and (<= 1.99 x) (<= x 2.01))
(* (cos x) (exp (* 10.0 (* x x)))))