(1-cos(x)^2)e^-x

Percentage Accurate: 100.0% → 100.0%
Time: 3.5s
Alternatives: 2
Speedup: 7.8×

Specification

?
\[\left(0 \leq x \land x \leq 1.79 \cdot 10^{+308}\right) \land \left(-1000 \leq e \land e \leq -1000\right)\]
\[\left(1 - {\cos x}^{2}\right) \cdot {e}^{\left(-x\right)} \]
(FPCore (x e)
  :precision binary64
  (* (- 1.0 (pow (cos x) 2.0)) (pow e (- x))))
double code(double x, double e) {
	return (1.0 - pow(cos(x), 2.0)) * pow(e, -x);
}
real(8) function code(x, e)
    real(8), intent (in) :: x
    real(8), intent (in) :: e
    code = (1.0d0 - (cos(x) ** 2.0d0)) * (e ** -x)
end function
public static double code(double x, double e) {
	return (1.0 - Math.pow(Math.cos(x), 2.0)) * Math.pow(e, -x);
}
def code(x, e):
	return (1.0 - math.pow(math.cos(x), 2.0)) * math.pow(e, -x)
function code(x, e)
	return Float64(Float64(1.0 - (cos(x) ^ 2.0)) * (e ^ Float64(-x)))
end
function tmp = code(x, e)
	tmp = (1.0 - (cos(x) ^ 2.0)) * (e ^ -x);
end
code[x_, e_] := N[(N[(1.0 - N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[Power[e, (-x)], $MachinePrecision]), $MachinePrecision]
\left(1 - {\cos x}^{2}\right) \cdot {e}^{\left(-x\right)}

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 2 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: 100.0% accurate, 1.0× speedup?

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

Alternative 1: 100.0% accurate, 7.8× speedup?

\[1 - \left(1 \cdot 1\right) \cdot 1 \]
(FPCore (x e)
  :precision binary64
  (- 1.0 (* (* 1.0 1.0) 1.0)))
double code(double x, double e) {
	return 1.0 - ((1.0 * 1.0) * 1.0);
}
real(8) function code(x, e)
    real(8), intent (in) :: x
    real(8), intent (in) :: e
    code = 1.0d0 - ((1.0d0 * 1.0d0) * 1.0d0)
end function
public static double code(double x, double e) {
	return 1.0 - ((1.0 * 1.0) * 1.0);
}
def code(x, e):
	return 1.0 - ((1.0 * 1.0) * 1.0)
function code(x, e)
	return Float64(1.0 - Float64(Float64(1.0 * 1.0) * 1.0))
end
function tmp = code(x, e)
	tmp = 1.0 - ((1.0 * 1.0) * 1.0);
end
code[x_, e_] := N[(1.0 - N[(N[(1.0 * 1.0), $MachinePrecision] * 1.0), $MachinePrecision]), $MachinePrecision]
1 - \left(1 \cdot 1\right) \cdot 1
Derivation
  1. Initial program 100.0%

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

    \[\leadsto \left(1 - {\color{blue}{1}}^{2}\right) \cdot {e}^{\left(-x\right)} \]
  3. Step-by-step derivation
    1. Applied rewrites100.0%

      \[\leadsto \left(1 - {\color{blue}{1}}^{2}\right) \cdot {e}^{\left(-x\right)} \]
    2. Taylor expanded in x around 0

      \[\leadsto \left(1 - {1}^{2}\right) \cdot \color{blue}{1} \]
    3. Step-by-step derivation
      1. Applied rewrites100.0%

        \[\leadsto \left(1 - {1}^{2}\right) \cdot \color{blue}{1} \]
      2. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \color{blue}{\left(1 - {1}^{2}\right) \cdot 1} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{1 \cdot \left(1 - {1}^{2}\right)} \]
        3. lift--.f64N/A

          \[\leadsto 1 \cdot \color{blue}{\left(1 - {1}^{2}\right)} \]
        4. sub-flipN/A

          \[\leadsto 1 \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left({1}^{2}\right)\right)\right)} \]
        5. distribute-rgt-inN/A

          \[\leadsto \color{blue}{1 \cdot 1 + \left(\mathsf{neg}\left({1}^{2}\right)\right) \cdot 1} \]
        6. fp-cancel-sub-signN/A

          \[\leadsto \color{blue}{1 \cdot 1 - {1}^{2} \cdot 1} \]
        7. *-lft-identityN/A

          \[\leadsto \color{blue}{1} - {1}^{2} \cdot 1 \]
        8. lower--.f64N/A

          \[\leadsto \color{blue}{1 - {1}^{2} \cdot 1} \]
        9. lower-*.f64100.0%

          \[\leadsto 1 - \color{blue}{{1}^{2} \cdot 1} \]
        10. lift-pow.f64N/A

          \[\leadsto 1 - \color{blue}{{1}^{2}} \cdot 1 \]
        11. unpow2N/A

          \[\leadsto 1 - \color{blue}{\left(1 \cdot 1\right)} \cdot 1 \]
        12. lower-*.f64100.0%

          \[\leadsto 1 - \color{blue}{\left(1 \cdot 1\right)} \cdot 1 \]
      3. Applied rewrites100.0%

        \[\leadsto \color{blue}{1 - \left(1 \cdot 1\right) \cdot 1} \]
      4. Add Preprocessing

      Alternative 2: 1.8% accurate, 10.7× speedup?

      \[1 \cdot \left(x \cdot x\right) \]
      (FPCore (x e)
        :precision binary64
        (* 1.0 (* x x)))
      double code(double x, double e) {
      	return 1.0 * (x * x);
      }
      
      real(8) function code(x, e)
          real(8), intent (in) :: x
          real(8), intent (in) :: e
          code = 1.0d0 * (x * x)
      end function
      
      public static double code(double x, double e) {
      	return 1.0 * (x * x);
      }
      
      def code(x, e):
      	return 1.0 * (x * x)
      
      function code(x, e)
      	return Float64(1.0 * Float64(x * x))
      end
      
      function tmp = code(x, e)
      	tmp = 1.0 * (x * x);
      end
      
      code[x_, e_] := N[(1.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]
      
      1 \cdot \left(x \cdot x\right)
      
      Derivation
      1. Initial program 100.0%

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

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

          \[\leadsto {x}^{\color{blue}{2}} \cdot {e}^{\left(-x\right)} \]
      4. Applied rewrites47.4%

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

        \[\leadsto {x}^{2} \cdot \color{blue}{1} \]
      6. Step-by-step derivation
        1. Applied rewrites1.8%

          \[\leadsto {x}^{2} \cdot \color{blue}{1} \]
        2. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \color{blue}{{x}^{2} \cdot 1} \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{1 \cdot {x}^{2}} \]
          3. lower-*.f641.8%

            \[\leadsto \color{blue}{1 \cdot {x}^{2}} \]
          4. lift-pow.f64N/A

            \[\leadsto 1 \cdot {x}^{\color{blue}{2}} \]
          5. unpow2N/A

            \[\leadsto 1 \cdot \left(x \cdot \color{blue}{x}\right) \]
          6. lower-*.f641.8%

            \[\leadsto 1 \cdot \left(x \cdot \color{blue}{x}\right) \]
        3. Applied rewrites1.8%

          \[\leadsto \color{blue}{1 \cdot \left(x \cdot x\right)} \]
        4. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 1 
        (FPCore (x e)
          :name "(1-cos(x)^2)e^-x"
          :precision binary64
          :pre (and (and (<= 0.0 x) (<= x 1.79e+308)) (and (<= -1000.0 e) (<= e -1000.0)))
          (* (- 1.0 (pow (cos x) 2.0)) (pow e (- x))))