ENA, Section 1.4, Exercise 1

Percentage Accurate: 94.5% → 99.4%
Time: 8.3s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[1.99 \leq x \land x \leq 2.01\]
\[\begin{array}{l} \\ \cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \end{array} \]
(FPCore (x) :precision binary64 (* (cos x) (exp (* 10.0 (* x x)))))
double code(double x) {
	return cos(x) * exp((10.0 * (x * x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = cos(x) * exp((10.0d0 * (x * x)))
end function
public static double code(double x) {
	return Math.cos(x) * Math.exp((10.0 * (x * x)));
}
def code(x):
	return math.cos(x) * math.exp((10.0 * (x * x)))
function code(x)
	return Float64(cos(x) * exp(Float64(10.0 * Float64(x * x))))
end
function tmp = code(x)
	tmp = cos(x) * exp((10.0 * (x * x)));
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Exp[N[(10.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos x \cdot e^{10 \cdot \left(x \cdot x\right)}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 94.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \end{array} \]
(FPCore (x) :precision binary64 (* (cos x) (exp (* 10.0 (* x x)))))
double code(double x) {
	return cos(x) * exp((10.0 * (x * x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = cos(x) * exp((10.0d0 * (x * x)))
end function
public static double code(double x) {
	return Math.cos(x) * Math.exp((10.0 * (x * x)));
}
def code(x):
	return math.cos(x) * math.exp((10.0 * (x * x)))
function code(x)
	return Float64(cos(x) * exp(Float64(10.0 * Float64(x * x))))
end
function tmp = code(x)
	tmp = cos(x) * exp((10.0 * (x * x)));
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Exp[N[(10.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos x \cdot e^{10 \cdot \left(x \cdot x\right)}
\end{array}

Alternative 1: 99.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \cos x \cdot {\left({\left(e^{20}\right)}^{x}\right)}^{\left(x \cdot 0.5\right)} \end{array} \]
(FPCore (x) :precision binary64 (* (cos x) (pow (pow (exp 20.0) x) (* x 0.5))))
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(20.0d0) ** x) ** (x * 0.5d0))
end function
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.pow(math.pow(math.exp(20.0), x), (x * 0.5))
function code(x)
	return Float64(cos(x) * ((exp(20.0) ^ x) ^ Float64(x * 0.5)))
end
function tmp = code(x)
	tmp = cos(x) * ((exp(20.0) ^ x) ^ (x * 0.5));
end
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]
\begin{array}{l}

\\
\cos x \cdot {\left({\left(e^{20}\right)}^{x}\right)}^{\left(x \cdot 0.5\right)}
\end{array}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. pow-exp95.2%

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{10}\right)}^{\left(x \cdot x\right)}} \]
    2. *-commutative95.2%

      \[\leadsto \color{blue}{{\left(e^{10}\right)}^{\left(x \cdot x\right)} \cdot \cos x} \]
    3. pow-exp94.5%

      \[\leadsto \color{blue}{e^{10 \cdot \left(x \cdot x\right)}} \cdot \cos x \]
    4. associate-*r*94.3%

      \[\leadsto e^{\color{blue}{\left(10 \cdot x\right) \cdot x}} \cdot \cos x \]
    5. add-log-exp94.3%

      \[\leadsto e^{\left(10 \cdot x\right) \cdot \color{blue}{\log \left(e^{x}\right)}} \cdot \cos x \]
    6. log-pow94.3%

      \[\leadsto e^{\color{blue}{\log \left({\left(e^{x}\right)}^{\left(10 \cdot x\right)}\right)}} \cdot \cos x \]
    7. pow-pow94.8%

      \[\leadsto e^{\log \color{blue}{\left({\left({\left(e^{x}\right)}^{10}\right)}^{x}\right)}} \cdot \cos x \]
    8. add-exp-log96.9%

      \[\leadsto \color{blue}{{\left({\left(e^{x}\right)}^{10}\right)}^{x}} \cdot \cos x \]
    9. add-cbrt-cube96.8%

      \[\leadsto \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 \]
    10. add-cbrt-cube96.8%

      \[\leadsto \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}} \]
    11. cbrt-unprod96.8%

      \[\leadsto \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)}} \]
  3. Applied egg-rr98.9%

    \[\leadsto \color{blue}{\sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot {\cos x}^{3}}} \]
  4. Step-by-step derivation
    1. add-cube-cbrt98.9%

      \[\leadsto \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)}} \]
    2. rem-cbrt-cube98.9%

      \[\leadsto \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)} \]
    3. rem-cbrt-cube98.9%

      \[\leadsto \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)} \]
    4. pow298.9%

      \[\leadsto \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \left(\color{blue}{{\cos x}^{2}} \cdot \sqrt[3]{{\cos x}^{3}}\right)} \]
    5. rem-cbrt-cube98.9%

      \[\leadsto \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \left({\cos x}^{2} \cdot \color{blue}{\cos x}\right)} \]
  5. Applied egg-rr98.9%

    \[\leadsto \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \color{blue}{\left({\cos x}^{2} \cdot \cos x\right)}} \]
  6. Taylor expanded in x around inf 94.0%

    \[\leadsto \color{blue}{{\left({\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot 1\right)}^{0.3333333333333333} \cdot \cos x} \]
  7. Step-by-step derivation
    1. *-commutative94.0%

      \[\leadsto \color{blue}{\cos x \cdot {\left({\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot 1\right)}^{0.3333333333333333}} \]
    2. unpow1/398.8%

      \[\leadsto \cos x \cdot \color{blue}{\sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot 1}} \]
    3. *-rgt-identity98.8%

      \[\leadsto \cos x \cdot \sqrt[3]{\color{blue}{{\left({\left(e^{30}\right)}^{x}\right)}^{x}}} \]
    4. exp-prod95.4%

      \[\leadsto \cos x \cdot \sqrt[3]{{\color{blue}{\left(e^{30 \cdot x}\right)}}^{x}} \]
    5. *-commutative95.4%

      \[\leadsto \cos x \cdot \sqrt[3]{{\left(e^{\color{blue}{x \cdot 30}}\right)}^{x}} \]
    6. exp-prod95.2%

      \[\leadsto \cos x \cdot \sqrt[3]{\color{blue}{e^{\left(x \cdot 30\right) \cdot x}}} \]
    7. *-commutative95.2%

      \[\leadsto \cos x \cdot \sqrt[3]{e^{\color{blue}{x \cdot \left(x \cdot 30\right)}}} \]
    8. exp-prod95.5%

      \[\leadsto \cos x \cdot \sqrt[3]{\color{blue}{{\left(e^{x}\right)}^{\left(x \cdot 30\right)}}} \]
  8. Simplified95.5%

    \[\leadsto \color{blue}{\cos x \cdot \sqrt[3]{{\left(e^{x}\right)}^{\left(x \cdot 30\right)}}} \]
  9. Step-by-step derivation
    1. add-exp-log94.6%

      \[\leadsto \cos x \cdot \color{blue}{e^{\log \left(\sqrt[3]{{\left(e^{x}\right)}^{\left(x \cdot 30\right)}}\right)}} \]
    2. pow1/394.1%

      \[\leadsto \cos x \cdot e^{\log \color{blue}{\left({\left({\left(e^{x}\right)}^{\left(x \cdot 30\right)}\right)}^{0.3333333333333333}\right)}} \]
    3. pow-pow93.7%

      \[\leadsto \cos x \cdot e^{\log \color{blue}{\left({\left(e^{x}\right)}^{\left(\left(x \cdot 30\right) \cdot 0.3333333333333333\right)}\right)}} \]
    4. log-pow93.9%

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(\left(x \cdot 30\right) \cdot 0.3333333333333333\right) \cdot \log \left(e^{x}\right)}} \]
    5. add-log-exp93.9%

      \[\leadsto \cos x \cdot e^{\left(\left(x \cdot 30\right) \cdot 0.3333333333333333\right) \cdot \color{blue}{x}} \]
    6. pow-exp94.0%

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{\left(x \cdot 30\right) \cdot 0.3333333333333333}\right)}^{x}} \]
    7. pow-exp94.5%

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{x \cdot 30}\right)}^{0.3333333333333333}\right)}}^{x} \]
    8. *-commutative94.5%

      \[\leadsto \cos x \cdot {\left({\left(e^{\color{blue}{30 \cdot x}}\right)}^{0.3333333333333333}\right)}^{x} \]
    9. pow-exp94.0%

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left({\left(e^{30}\right)}^{x}\right)}}^{0.3333333333333333}\right)}^{x} \]
  10. Applied egg-rr99.4%

    \[\leadsto \cos x \cdot \color{blue}{{\left({\left(e^{20}\right)}^{x}\right)}^{\left(x \cdot 0.5\right)}} \]
  11. Final simplification99.4%

    \[\leadsto \cos x \cdot {\left({\left(e^{20}\right)}^{x}\right)}^{\left(x \cdot 0.5\right)} \]

Alternative 2: 97.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \cos x \cdot {\left({\left(e^{10}\right)}^{x}\right)}^{x} \end{array} \]
(FPCore (x) :precision binary64 (* (cos x) (pow (pow (exp 10.0) x) x)))
double code(double x) {
	return cos(x) * pow(pow(exp(10.0), x), x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = cos(x) * ((exp(10.0d0) ** x) ** x)
end function
public static double code(double x) {
	return Math.cos(x) * Math.pow(Math.pow(Math.exp(10.0), x), x);
}
def code(x):
	return math.cos(x) * math.pow(math.pow(math.exp(10.0), x), x)
function code(x)
	return Float64(cos(x) * ((exp(10.0) ^ x) ^ x))
end
function tmp = code(x)
	tmp = cos(x) * ((exp(10.0) ^ x) ^ x);
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Power[N[Exp[10.0], $MachinePrecision], x], $MachinePrecision], x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos x \cdot {\left({\left(e^{10}\right)}^{x}\right)}^{x}
\end{array}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. associate-*r*94.3%

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(10 \cdot x\right) \cdot x}} \]
    2. exp-prod95.0%

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{10 \cdot x}\right)}^{x}} \]
    3. sqr-pow94.9%

      \[\leadsto \cos x \cdot \color{blue}{\left({\left(e^{10 \cdot x}\right)}^{\left(\frac{x}{2}\right)} \cdot {\left(e^{10 \cdot x}\right)}^{\left(\frac{x}{2}\right)}\right)} \]
    4. sqr-pow95.0%

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{10 \cdot x}\right)}^{x}} \]
    5. exp-prod98.0%

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{10}\right)}^{x}\right)}}^{x} \]
  3. Simplified98.0%

    \[\leadsto \color{blue}{\cos x \cdot {\left({\left(e^{10}\right)}^{x}\right)}^{x}} \]
  4. Final simplification98.0%

    \[\leadsto \cos x \cdot {\left({\left(e^{10}\right)}^{x}\right)}^{x} \]

Alternative 3: 95.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \cos x \cdot \sqrt[3]{e^{x \cdot \left(x \cdot 30\right)}} \end{array} \]
(FPCore (x) :precision binary64 (* (cos x) (cbrt (exp (* x (* x 30.0))))))
double code(double x) {
	return cos(x) * cbrt(exp((x * (x * 30.0))));
}
public static double code(double x) {
	return Math.cos(x) * Math.cbrt(Math.exp((x * (x * 30.0))));
}
function code(x)
	return Float64(cos(x) * cbrt(exp(Float64(x * Float64(x * 30.0)))))
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Exp[N[(x * N[(x * 30.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos x \cdot \sqrt[3]{e^{x \cdot \left(x \cdot 30\right)}}
\end{array}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. pow-exp95.2%

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{10}\right)}^{\left(x \cdot x\right)}} \]
    2. *-commutative95.2%

      \[\leadsto \color{blue}{{\left(e^{10}\right)}^{\left(x \cdot x\right)} \cdot \cos x} \]
    3. pow-exp94.5%

      \[\leadsto \color{blue}{e^{10 \cdot \left(x \cdot x\right)}} \cdot \cos x \]
    4. associate-*r*94.3%

      \[\leadsto e^{\color{blue}{\left(10 \cdot x\right) \cdot x}} \cdot \cos x \]
    5. add-log-exp94.3%

      \[\leadsto e^{\left(10 \cdot x\right) \cdot \color{blue}{\log \left(e^{x}\right)}} \cdot \cos x \]
    6. log-pow94.3%

      \[\leadsto e^{\color{blue}{\log \left({\left(e^{x}\right)}^{\left(10 \cdot x\right)}\right)}} \cdot \cos x \]
    7. pow-pow94.8%

      \[\leadsto e^{\log \color{blue}{\left({\left({\left(e^{x}\right)}^{10}\right)}^{x}\right)}} \cdot \cos x \]
    8. add-exp-log96.9%

      \[\leadsto \color{blue}{{\left({\left(e^{x}\right)}^{10}\right)}^{x}} \cdot \cos x \]
    9. add-cbrt-cube96.8%

      \[\leadsto \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 \]
    10. add-cbrt-cube96.8%

      \[\leadsto \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}} \]
    11. cbrt-unprod96.8%

      \[\leadsto \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)}} \]
  3. Applied egg-rr98.9%

    \[\leadsto \color{blue}{\sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot {\cos x}^{3}}} \]
  4. Step-by-step derivation
    1. add-cube-cbrt98.9%

      \[\leadsto \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)}} \]
    2. rem-cbrt-cube98.9%

      \[\leadsto \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)} \]
    3. rem-cbrt-cube98.9%

      \[\leadsto \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)} \]
    4. pow298.9%

      \[\leadsto \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \left(\color{blue}{{\cos x}^{2}} \cdot \sqrt[3]{{\cos x}^{3}}\right)} \]
    5. rem-cbrt-cube98.9%

      \[\leadsto \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \left({\cos x}^{2} \cdot \color{blue}{\cos x}\right)} \]
  5. Applied egg-rr98.9%

    \[\leadsto \sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot \color{blue}{\left({\cos x}^{2} \cdot \cos x\right)}} \]
  6. Taylor expanded in x around inf 94.0%

    \[\leadsto \color{blue}{{\left({\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot 1\right)}^{0.3333333333333333} \cdot \cos x} \]
  7. Step-by-step derivation
    1. *-commutative94.0%

      \[\leadsto \color{blue}{\cos x \cdot {\left({\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot 1\right)}^{0.3333333333333333}} \]
    2. unpow1/398.8%

      \[\leadsto \cos x \cdot \color{blue}{\sqrt[3]{{\left({\left(e^{30}\right)}^{x}\right)}^{x} \cdot 1}} \]
    3. *-rgt-identity98.8%

      \[\leadsto \cos x \cdot \sqrt[3]{\color{blue}{{\left({\left(e^{30}\right)}^{x}\right)}^{x}}} \]
    4. exp-prod95.4%

      \[\leadsto \cos x \cdot \sqrt[3]{{\color{blue}{\left(e^{30 \cdot x}\right)}}^{x}} \]
    5. *-commutative95.4%

      \[\leadsto \cos x \cdot \sqrt[3]{{\left(e^{\color{blue}{x \cdot 30}}\right)}^{x}} \]
    6. exp-prod95.2%

      \[\leadsto \cos x \cdot \sqrt[3]{\color{blue}{e^{\left(x \cdot 30\right) \cdot x}}} \]
    7. *-commutative95.2%

      \[\leadsto \cos x \cdot \sqrt[3]{e^{\color{blue}{x \cdot \left(x \cdot 30\right)}}} \]
    8. exp-prod95.5%

      \[\leadsto \cos x \cdot \sqrt[3]{\color{blue}{{\left(e^{x}\right)}^{\left(x \cdot 30\right)}}} \]
  8. Simplified95.5%

    \[\leadsto \color{blue}{\cos x \cdot \sqrt[3]{{\left(e^{x}\right)}^{\left(x \cdot 30\right)}}} \]
  9. Step-by-step derivation
    1. pow-exp95.2%

      \[\leadsto \cos x \cdot \sqrt[3]{\color{blue}{e^{x \cdot \left(x \cdot 30\right)}}} \]
  10. Applied egg-rr95.2%

    \[\leadsto \cos x \cdot \sqrt[3]{\color{blue}{e^{x \cdot \left(x \cdot 30\right)}}} \]
  11. Final simplification95.2%

    \[\leadsto \cos x \cdot \sqrt[3]{e^{x \cdot \left(x \cdot 30\right)}} \]

Alternative 4: 95.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \cos x \cdot {\left(e^{10}\right)}^{\left(x \cdot x\right)} \end{array} \]
(FPCore (x) :precision binary64 (* (cos x) (pow (exp 10.0) (* x x))))
double code(double x) {
	return cos(x) * pow(exp(10.0), (x * x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = cos(x) * (exp(10.0d0) ** (x * x))
end function
public static double code(double x) {
	return Math.cos(x) * Math.pow(Math.exp(10.0), (x * x));
}
def code(x):
	return math.cos(x) * math.pow(math.exp(10.0), (x * x))
function code(x)
	return Float64(cos(x) * (exp(10.0) ^ Float64(x * x)))
end
function tmp = code(x)
	tmp = cos(x) * (exp(10.0) ^ (x * x));
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Exp[10.0], $MachinePrecision], N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos x \cdot {\left(e^{10}\right)}^{\left(x \cdot x\right)}
\end{array}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. exp-prod95.2%

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{10}\right)}^{\left(x \cdot x\right)}} \]
  3. Simplified95.2%

    \[\leadsto \color{blue}{\cos x \cdot {\left(e^{10}\right)}^{\left(x \cdot x\right)}} \]
  4. Final simplification95.2%

    \[\leadsto \cos x \cdot {\left(e^{10}\right)}^{\left(x \cdot x\right)} \]

Alternative 5: 95.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \cos x \cdot {\left(e^{x \cdot x}\right)}^{10} \end{array} \]
(FPCore (x) :precision binary64 (* (cos x) (pow (exp (* x x)) 10.0)))
double code(double x) {
	return cos(x) * pow(exp((x * x)), 10.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = cos(x) * (exp((x * x)) ** 10.0d0)
end function
public static double code(double x) {
	return Math.cos(x) * Math.pow(Math.exp((x * x)), 10.0);
}
def code(x):
	return math.cos(x) * math.pow(math.exp((x * x)), 10.0)
function code(x)
	return Float64(cos(x) * (exp(Float64(x * x)) ^ 10.0))
end
function tmp = code(x)
	tmp = cos(x) * (exp((x * x)) ^ 10.0);
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision], 10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos x \cdot {\left(e^{x \cdot x}\right)}^{10}
\end{array}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. *-commutative94.5%

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(x \cdot x\right) \cdot 10}} \]
    2. exp-prod95.2%

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    3. exp-prod96.7%

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{x}\right)}^{x}\right)}}^{10} \]
  3. Applied egg-rr96.7%

    \[\leadsto \cos x \cdot \color{blue}{{\left({\left(e^{x}\right)}^{x}\right)}^{10}} \]
  4. Taylor expanded in x around inf 95.2%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{{x}^{2}}\right)}^{10}} \]
  5. Step-by-step derivation
    1. unpow295.2%

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{x \cdot x}}\right)}^{10} \]
  6. Simplified95.2%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
  7. Final simplification95.2%

    \[\leadsto \cos x \cdot {\left(e^{x \cdot x}\right)}^{10} \]

Alternative 6: 94.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \end{array} \]
(FPCore (x) :precision binary64 (* (cos x) (exp (* 10.0 (* x x)))))
double code(double x) {
	return cos(x) * exp((10.0 * (x * x)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = cos(x) * exp((10.0d0 * (x * x)))
end function
public static double code(double x) {
	return Math.cos(x) * Math.exp((10.0 * (x * x)));
}
def code(x):
	return math.cos(x) * math.exp((10.0 * (x * x)))
function code(x)
	return Float64(cos(x) * exp(Float64(10.0 * Float64(x * x))))
end
function tmp = code(x)
	tmp = cos(x) * exp((10.0 * (x * x)));
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Exp[N[(10.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos x \cdot e^{10 \cdot \left(x \cdot x\right)}
\end{array}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Final simplification94.5%

    \[\leadsto \cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]

Alternative 7: 9.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \cos x \end{array} \]
(FPCore (x) :precision binary64 (cos x))
double code(double x) {
	return cos(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = cos(x)
end function
public static double code(double x) {
	return Math.cos(x);
}
def code(x):
	return math.cos(x)
function code(x)
	return cos(x)
end
function tmp = code(x)
	tmp = cos(x);
end
code[x_] := N[Cos[x], $MachinePrecision]
\begin{array}{l}

\\
\cos x
\end{array}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Taylor expanded in x around 0 9.6%

    \[\leadsto \cos x \cdot \color{blue}{1} \]
  3. Final simplification9.6%

    \[\leadsto \cos x \]

Alternative 8: 1.5% accurate, 29.6× speedup?

\[\begin{array}{l} \\ 1 + \left(x \cdot x\right) \cdot 9.5 \end{array} \]
(FPCore (x) :precision binary64 (+ 1.0 (* (* x x) 9.5)))
double code(double x) {
	return 1.0 + ((x * x) * 9.5);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 + ((x * x) * 9.5d0)
end function
public static double code(double x) {
	return 1.0 + ((x * x) * 9.5);
}
def code(x):
	return 1.0 + ((x * x) * 9.5)
function code(x)
	return Float64(1.0 + Float64(Float64(x * x) * 9.5))
end
function tmp = code(x)
	tmp = 1.0 + ((x * x) * 9.5);
end
code[x_] := N[(1.0 + N[(N[(x * x), $MachinePrecision] * 9.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 + \left(x \cdot x\right) \cdot 9.5
\end{array}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Taylor expanded in x around 0 1.5%

    \[\leadsto \color{blue}{1 + 9.5 \cdot {x}^{2}} \]
  3. Step-by-step derivation
    1. unpow21.5%

      \[\leadsto 1 + 9.5 \cdot \color{blue}{\left(x \cdot x\right)} \]
  4. Simplified1.5%

    \[\leadsto \color{blue}{1 + 9.5 \cdot \left(x \cdot x\right)} \]
  5. Final simplification1.5%

    \[\leadsto 1 + \left(x \cdot x\right) \cdot 9.5 \]

Reproduce

?
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)))))