ENA, Section 1.4, Exercise 1

Percentage Accurate: 94.5% → 99.4%
Time: 8.7s
Alternatives: 7
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 7 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(\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.4%

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

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

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

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

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

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

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

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

    \[\leadsto \cos x \cdot \color{blue}{{\left({\left(e^{20}\right)}^{x}\right)}^{\left(\frac{x}{2}\right)}} \]
  5. Add Preprocessing

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

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Add Preprocessing
  3. 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}} \]
  4. Applied egg-rr98.0%

    \[\leadsto \cos x \cdot \color{blue}{{\left({\left(e^{10}\right)}^{x}\right)}^{x}} \]
  5. Add Preprocessing

Alternative 3: 95.3% accurate, 0.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos x \cdot \sqrt{{\left({\left(e^{80}\right)}^{x}\right)}^{\left(\frac{x \cdot \color{blue}{0.5}}{2}\right)}} \]
    11. associate-/l*99.4%

      \[\leadsto \cos x \cdot \sqrt{{\left({\left(e^{80}\right)}^{x}\right)}^{\color{blue}{\left(x \cdot \frac{0.5}{2}\right)}}} \]
    12. metadata-eval99.4%

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

    \[\leadsto \cos x \cdot \color{blue}{\sqrt{{\left({\left(e^{80}\right)}^{x}\right)}^{\left(x \cdot 0.25\right)}}} \]
  9. Step-by-step derivation
    1. sqrt-pow199.4%

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

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

      \[\leadsto \cos x \cdot {\left(e^{80}\right)}^{\left(x \cdot \color{blue}{\left(x \cdot \frac{0.25}{2}\right)}\right)} \]
    4. metadata-eval95.4%

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

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{80}\right)}^{\left(x \cdot \left(x \cdot 0.125\right)\right)}} \]
  11. Add Preprocessing

Alternative 4: 95.3% accurate, 0.7× speedup?

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

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

    \[\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. Add Preprocessing
  5. Step-by-step derivation
    1. pow-exp94.4%

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

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

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

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

      \[\leadsto \cos x \cdot {\left(e^{1}\right)}^{\log \color{blue}{\left({\left(e^{10}\right)}^{\left(x \cdot x\right)}\right)}} \]
    6. add-cube-cbrt94.4%

      \[\leadsto \cos x \cdot {\left(e^{1}\right)}^{\log \color{blue}{\left(\left(\sqrt[3]{{\left(e^{10}\right)}^{\left(x \cdot x\right)}} \cdot \sqrt[3]{{\left(e^{10}\right)}^{\left(x \cdot x\right)}}\right) \cdot \sqrt[3]{{\left(e^{10}\right)}^{\left(x \cdot x\right)}}\right)}} \]
    7. log-prod94.1%

      \[\leadsto \cos x \cdot {\left(e^{1}\right)}^{\color{blue}{\left(\log \left(\sqrt[3]{{\left(e^{10}\right)}^{\left(x \cdot x\right)}} \cdot \sqrt[3]{{\left(e^{10}\right)}^{\left(x \cdot x\right)}}\right) + \log \left(\sqrt[3]{{\left(e^{10}\right)}^{\left(x \cdot x\right)}}\right)\right)}} \]
    8. unpow-prod-up94.3%

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

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

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

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

      \[\leadsto \cos x \cdot \left({e}^{\left(\color{blue}{0.6666666666666666} \cdot \left({x}^{2} \cdot 10\right)\right)} \cdot {\left(e^{1}\right)}^{\left(0.3333333333333333 \cdot \left({x}^{2} \cdot 10\right)\right)}\right) \]
    4. *-commutative93.2%

      \[\leadsto \cos x \cdot \left({e}^{\left(0.6666666666666666 \cdot \color{blue}{\left(10 \cdot {x}^{2}\right)}\right)} \cdot {\left(e^{1}\right)}^{\left(0.3333333333333333 \cdot \left({x}^{2} \cdot 10\right)\right)}\right) \]
    5. associate-*r*92.5%

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

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

      \[\leadsto \cos x \cdot \left({e}^{\color{blue}{\left({x}^{2} \cdot 6.666666666666667\right)}} \cdot {\left(e^{1}\right)}^{\left(0.3333333333333333 \cdot \left({x}^{2} \cdot 10\right)\right)}\right) \]
    8. exp-1-e94.5%

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

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

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

      \[\leadsto \cos x \cdot \left({e}^{\left({x}^{2} \cdot 6.666666666666667\right)} \cdot {e}^{\left({x}^{2} \cdot \color{blue}{3.3333333333333335}\right)}\right) \]
  8. Simplified94.7%

    \[\leadsto \cos x \cdot \color{blue}{\left({e}^{\left({x}^{2} \cdot 6.666666666666667\right)} \cdot {e}^{\left({x}^{2} \cdot 3.3333333333333335\right)}\right)} \]
  9. Applied egg-rr95.4%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{20}\right)}^{\left(x \cdot \left(x \cdot 0.5\right)\right)}} \]
  10. Add Preprocessing

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

    \[\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. Add Preprocessing
  5. Add Preprocessing

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

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Add Preprocessing
  3. Add Preprocessing

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{1} \]
  6. Add Preprocessing

Reproduce

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