ENA, Section 1.4, Exercise 1

Percentage Accurate: 94.5% → 99.4%
Time: 8.1s
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.4× speedup?

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

\\
\cos x \cdot {\left(\sqrt{{\left(e^{80}\right)}^{x}}\right)}^{\left(\frac{x}{4}\right)}
\end{array}
Derivation
  1. Initial program 94.7%

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

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

    \[\leadsto \color{blue}{\cos x \cdot {\left(e^{10}\right)}^{\left(x \cdot x\right)}} \]
  4. Step-by-step derivation
    1. pow-exp94.7%

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

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

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

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

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

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

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

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

      \[\leadsto \cos x \cdot \color{blue}{e^{\left(x \cdot \frac{x \cdot 10}{2}\right) \cdot 2}} \]
    10. associate-/l*93.9%

      \[\leadsto \cos x \cdot e^{\left(x \cdot \color{blue}{\frac{x}{\frac{2}{10}}}\right) \cdot 2} \]
    11. metadata-eval93.9%

      \[\leadsto \cos x \cdot e^{\left(x \cdot \frac{x}{\color{blue}{0.2}}\right) \cdot 2} \]
  5. Applied egg-rr93.9%

    \[\leadsto \cos x \cdot \color{blue}{e^{\left(x \cdot \frac{x}{0.2}\right) \cdot 2}} \]
  6. Step-by-step derivation
    1. associate-*l*93.9%

      \[\leadsto \cos x \cdot e^{\color{blue}{x \cdot \left(\frac{x}{0.2} \cdot 2\right)}} \]
    2. *-commutative93.9%

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(\frac{x}{0.2} \cdot 2\right) \cdot x}} \]
    3. add-log-exp93.9%

      \[\leadsto \cos x \cdot e^{\color{blue}{\log \left(e^{\frac{x}{0.2} \cdot 2}\right)} \cdot x} \]
    4. div-inv94.5%

      \[\leadsto \cos x \cdot e^{\log \left(e^{\color{blue}{\left(x \cdot \frac{1}{0.2}\right)} \cdot 2}\right) \cdot x} \]
    5. associate-*l*94.5%

      \[\leadsto \cos x \cdot e^{\log \left(e^{\color{blue}{x \cdot \left(\frac{1}{0.2} \cdot 2\right)}}\right) \cdot x} \]
    6. metadata-eval94.5%

      \[\leadsto \cos x \cdot e^{\log \left(e^{x \cdot \left(\color{blue}{5} \cdot 2\right)}\right) \cdot x} \]
    7. metadata-eval94.5%

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

      \[\leadsto \cos x \cdot e^{\log \color{blue}{\left({\left(e^{x}\right)}^{10}\right)} \cdot x} \]
    9. metadata-eval94.4%

      \[\leadsto \cos x \cdot e^{\log \left({\left(e^{x}\right)}^{\color{blue}{\left(\frac{20}{2}\right)}}\right) \cdot x} \]
    10. sqrt-pow194.4%

      \[\leadsto \cos x \cdot e^{\log \color{blue}{\left(\sqrt{{\left(e^{x}\right)}^{20}}\right)} \cdot x} \]
    11. pow-to-exp96.8%

      \[\leadsto \cos x \cdot \color{blue}{{\left(\sqrt{{\left(e^{x}\right)}^{20}}\right)}^{x}} \]
    12. sqrt-pow296.8%

      \[\leadsto \cos x \cdot \color{blue}{{\left({\left(e^{x}\right)}^{20}\right)}^{\left(\frac{x}{2}\right)}} \]
    13. pow-to-exp94.4%

      \[\leadsto \cos x \cdot \color{blue}{e^{\log \left({\left(e^{x}\right)}^{20}\right) \cdot \frac{x}{2}}} \]
    14. log-pow94.5%

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(20 \cdot \log \left(e^{x}\right)\right)} \cdot \frac{x}{2}} \]
    15. rem-log-exp94.5%

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

      \[\leadsto \cos x \cdot e^{\left(\log \left(e^{20}\right) \cdot \color{blue}{x}\right) \cdot \frac{x}{2}} \]
    17. pow-exp95.3%

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{\log \left(e^{20}\right) \cdot x}\right)}^{\left(\frac{x}{2}\right)}} \]
    18. pow-to-exp99.4%

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{20}\right)}^{x}\right)}}^{\left(\frac{x}{2}\right)} \]
  7. Applied egg-rr99.2%

    \[\leadsto \cos x \cdot \color{blue}{{\left({\left(e^{40}\right)}^{x}\right)}^{\left(\frac{x}{4}\right)}} \]
  8. Step-by-step derivation
    1. add-sqr-sqrt99.2%

      \[\leadsto \cos x \cdot {\color{blue}{\left(\sqrt{{\left(e^{40}\right)}^{x}} \cdot \sqrt{{\left(e^{40}\right)}^{x}}\right)}}^{\left(\frac{x}{4}\right)} \]
    2. sqrt-unprod99.2%

      \[\leadsto \cos x \cdot {\color{blue}{\left(\sqrt{{\left(e^{40}\right)}^{x} \cdot {\left(e^{40}\right)}^{x}}\right)}}^{\left(\frac{x}{4}\right)} \]
    3. pow-prod-down99.3%

      \[\leadsto \cos x \cdot {\left(\sqrt{\color{blue}{{\left(e^{40} \cdot e^{40}\right)}^{x}}}\right)}^{\left(\frac{x}{4}\right)} \]
    4. prod-exp99.5%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\color{blue}{\left(e^{40 + 40}\right)}}^{x}}\right)}^{\left(\frac{x}{4}\right)} \]
    5. metadata-eval99.5%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\left(e^{\color{blue}{80}}\right)}^{x}}\right)}^{\left(\frac{x}{4}\right)} \]
  9. Applied egg-rr99.5%

    \[\leadsto \cos x \cdot {\color{blue}{\left(\sqrt{{\left(e^{80}\right)}^{x}}\right)}}^{\left(\frac{x}{4}\right)} \]
  10. Final simplification99.5%

    \[\leadsto \cos x \cdot {\left(\sqrt{{\left(e^{80}\right)}^{x}}\right)}^{\left(\frac{x}{4}\right)} \]

Alternative 2: 98.4% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{x}\right)}^{10}\right)}}^{x} \]
    4. metadata-eval96.8%

      \[\leadsto \cos x \cdot {\left({\left(e^{x}\right)}^{\color{blue}{\left(\frac{20}{2}\right)}}\right)}^{x} \]
    5. sqrt-pow196.8%

      \[\leadsto \cos x \cdot {\color{blue}{\left(\sqrt{{\left(e^{x}\right)}^{20}}\right)}}^{x} \]
  5. Applied egg-rr96.8%

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

      \[\leadsto \cos x \cdot {\left(\sqrt{\color{blue}{e^{\log \left({\left(e^{x}\right)}^{20}\right)}}}\right)}^{x} \]
    2. log-pow95.2%

      \[\leadsto \cos x \cdot {\left(\sqrt{e^{\color{blue}{20 \cdot \log \left(e^{x}\right)}}}\right)}^{x} \]
    3. add-log-exp95.2%

      \[\leadsto \cos x \cdot {\left(\sqrt{e^{20 \cdot \color{blue}{x}}}\right)}^{x} \]
    4. pow-exp99.1%

      \[\leadsto \cos x \cdot {\left(\sqrt{\color{blue}{{\left(e^{20}\right)}^{x}}}\right)}^{x} \]
    5. add-sqr-sqrt98.0%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\color{blue}{\left(\sqrt{e^{20}} \cdot \sqrt{e^{20}}\right)}}^{x}}\right)}^{x} \]
    6. unpow-prod-down98.0%

      \[\leadsto \cos x \cdot {\left(\sqrt{\color{blue}{{\left(\sqrt{e^{20}}\right)}^{x} \cdot {\left(\sqrt{e^{20}}\right)}^{x}}}\right)}^{x} \]
    7. metadata-eval98.0%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\left(\sqrt{e^{\color{blue}{10 + 10}}}\right)}^{x} \cdot {\left(\sqrt{e^{20}}\right)}^{x}}\right)}^{x} \]
    8. prod-exp98.0%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\left(\sqrt{\color{blue}{e^{10} \cdot e^{10}}}\right)}^{x} \cdot {\left(\sqrt{e^{20}}\right)}^{x}}\right)}^{x} \]
    9. sqrt-unprod98.9%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\color{blue}{\left(\sqrt{e^{10}} \cdot \sqrt{e^{10}}\right)}}^{x} \cdot {\left(\sqrt{e^{20}}\right)}^{x}}\right)}^{x} \]
    10. pow298.9%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\color{blue}{\left({\left(\sqrt{e^{10}}\right)}^{2}\right)}}^{x} \cdot {\left(\sqrt{e^{20}}\right)}^{x}}\right)}^{x} \]
    11. pow-unpow99.1%

      \[\leadsto \cos x \cdot {\left(\sqrt{\color{blue}{{\left(\sqrt{e^{10}}\right)}^{\left(2 \cdot x\right)}} \cdot {\left(\sqrt{e^{20}}\right)}^{x}}\right)}^{x} \]
    12. *-commutative99.1%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\left(\sqrt{e^{10}}\right)}^{\color{blue}{\left(x \cdot 2\right)}} \cdot {\left(\sqrt{e^{20}}\right)}^{x}}\right)}^{x} \]
    13. metadata-eval99.1%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\left(\sqrt{e^{10}}\right)}^{\left(x \cdot 2\right)} \cdot {\left(\sqrt{e^{\color{blue}{10 + 10}}}\right)}^{x}}\right)}^{x} \]
    14. prod-exp99.1%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\left(\sqrt{e^{10}}\right)}^{\left(x \cdot 2\right)} \cdot {\left(\sqrt{\color{blue}{e^{10} \cdot e^{10}}}\right)}^{x}}\right)}^{x} \]
    15. sqrt-unprod97.8%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\left(\sqrt{e^{10}}\right)}^{\left(x \cdot 2\right)} \cdot {\color{blue}{\left(\sqrt{e^{10}} \cdot \sqrt{e^{10}}\right)}}^{x}}\right)}^{x} \]
    16. pow297.8%

      \[\leadsto \cos x \cdot {\left(\sqrt{{\left(\sqrt{e^{10}}\right)}^{\left(x \cdot 2\right)} \cdot {\color{blue}{\left({\left(\sqrt{e^{10}}\right)}^{2}\right)}}^{x}}\right)}^{x} \]
    17. pow-unpow98.4%

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

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

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

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

Alternative 3: 99.4% accurate, 0.5× speedup?

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

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

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

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

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

      \[\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. pow-prod-down95.2%

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

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

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

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

      \[\leadsto \cos x \cdot {\left({\left(e^{x}\right)}^{10} \cdot \color{blue}{{\left(e^{x}\right)}^{10}}\right)}^{\left(\frac{x}{2}\right)} \]
    9. pow-prod-up96.8%

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{x}\right)}^{\left(10 + 10\right)}\right)}}^{\left(\frac{x}{2}\right)} \]
    10. metadata-eval96.8%

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

    \[\leadsto \cos x \cdot \color{blue}{{\left({\left(e^{x}\right)}^{20}\right)}^{\left(\frac{x}{2}\right)}} \]
  4. Step-by-step derivation
    1. expm1-log1p-u95.3%

      \[\leadsto \cos x \cdot {\color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left({\left(e^{x}\right)}^{20}\right)\right)\right)}}^{\left(\frac{x}{2}\right)} \]
    2. expm1-udef95.3%

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{\mathsf{log1p}\left({\left(e^{x}\right)}^{20}\right)} - 1\right)}}^{\left(\frac{x}{2}\right)} \]
  5. Applied egg-rr95.3%

    \[\leadsto \cos x \cdot {\color{blue}{\left(e^{\mathsf{log1p}\left({\left(e^{x}\right)}^{20}\right)} - 1\right)}}^{\left(\frac{x}{2}\right)} \]
  6. Step-by-step derivation
    1. expm1-def95.3%

      \[\leadsto \cos x \cdot {\color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left({\left(e^{x}\right)}^{20}\right)\right)\right)}}^{\left(\frac{x}{2}\right)} \]
    2. expm1-log1p96.8%

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

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

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{20 \cdot x}}\right)}^{\left(\frac{x}{2}\right)} \]
    5. exp-prod99.4%

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{20}\right)}^{x}\right)}}^{\left(\frac{x}{2}\right)} \]
  7. Simplified99.4%

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

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

Alternative 4: 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.7%

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

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

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

    \[\leadsto \cos x \cdot \color{blue}{{\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 5: 95.2% 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.7%

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

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

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

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

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.7%

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

    \[\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.7%

    \[\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, 207.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (x) :precision binary64 1.0)
double code(double x) {
	return 1.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0
end function
public static double code(double x) {
	return 1.0;
}
def code(x):
	return 1.0
function code(x)
	return 1.0
end
function tmp = code(x)
	tmp = 1.0;
end
code[x_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 94.7%

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

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

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

      \[\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. pow-prod-down95.2%

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

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

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

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

      \[\leadsto \cos x \cdot {\left({\left(e^{x}\right)}^{10} \cdot \color{blue}{{\left(e^{x}\right)}^{10}}\right)}^{\left(\frac{x}{2}\right)} \]
    9. pow-prod-up96.8%

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{x}\right)}^{\left(10 + 10\right)}\right)}}^{\left(\frac{x}{2}\right)} \]
    10. metadata-eval96.8%

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

    \[\leadsto \cos x \cdot \color{blue}{{\left({\left(e^{x}\right)}^{20}\right)}^{\left(\frac{x}{2}\right)}} \]
  4. Step-by-step derivation
    1. expm1-log1p-u95.3%

      \[\leadsto \cos x \cdot {\color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left({\left(e^{x}\right)}^{20}\right)\right)\right)}}^{\left(\frac{x}{2}\right)} \]
    2. expm1-udef95.3%

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{\mathsf{log1p}\left({\left(e^{x}\right)}^{20}\right)} - 1\right)}}^{\left(\frac{x}{2}\right)} \]
  5. Applied egg-rr95.3%

    \[\leadsto \cos x \cdot {\color{blue}{\left(e^{\mathsf{log1p}\left({\left(e^{x}\right)}^{20}\right)} - 1\right)}}^{\left(\frac{x}{2}\right)} \]
  6. Step-by-step derivation
    1. expm1-def95.3%

      \[\leadsto \cos x \cdot {\color{blue}{\left(\mathsf{expm1}\left(\mathsf{log1p}\left({\left(e^{x}\right)}^{20}\right)\right)\right)}}^{\left(\frac{x}{2}\right)} \]
    2. expm1-log1p96.8%

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

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

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{20 \cdot x}}\right)}^{\left(\frac{x}{2}\right)} \]
    5. exp-prod99.4%

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{20}\right)}^{x}\right)}}^{\left(\frac{x}{2}\right)} \]
  7. Simplified99.4%

    \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{20}\right)}^{x}\right)}}^{\left(\frac{x}{2}\right)} \]
  8. Taylor expanded in x around 0 1.5%

    \[\leadsto \color{blue}{1} \]
  9. Final simplification1.5%

    \[\leadsto 1 \]

Reproduce

?
herbie shell --seed 2023332 
(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)))))