-cos(w)*wp^2 - (sin(w)/w)*q

Percentage Accurate: 100.0% → 100.0%
Time: 5.4s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[\left(\left(-1 \leq w \land w \leq 1\right) \land \left(-1000 \leq wp \land wp \leq 1000\right)\right) \land \left(-1000 \leq q \land q \leq 1000\right)\]
\[\begin{array}{l} \\ \left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \end{array} \]
(FPCore (w wp q)
 :precision binary64
 (- (* (- (cos w)) (pow wp 2.0)) (* (/ (sin w) w) q)))
double code(double w, double wp, double q) {
	return (-cos(w) * pow(wp, 2.0)) - ((sin(w) / w) * q);
}
real(8) function code(w, wp, q)
    real(8), intent (in) :: w
    real(8), intent (in) :: wp
    real(8), intent (in) :: q
    code = (-cos(w) * (wp ** 2.0d0)) - ((sin(w) / w) * q)
end function
public static double code(double w, double wp, double q) {
	return (-Math.cos(w) * Math.pow(wp, 2.0)) - ((Math.sin(w) / w) * q);
}
def code(w, wp, q):
	return (-math.cos(w) * math.pow(wp, 2.0)) - ((math.sin(w) / w) * q)
function code(w, wp, q)
	return Float64(Float64(Float64(-cos(w)) * (wp ^ 2.0)) - Float64(Float64(sin(w) / w) * q))
end
function tmp = code(w, wp, q)
	tmp = (-cos(w) * (wp ^ 2.0)) - ((sin(w) / w) * q);
end
code[w_, wp_, q_] := N[(N[((-N[Cos[w], $MachinePrecision]) * N[Power[wp, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[w], $MachinePrecision] / w), $MachinePrecision] * q), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q
\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: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \end{array} \]
(FPCore (w wp q)
 :precision binary64
 (- (* (- (cos w)) (pow wp 2.0)) (* (/ (sin w) w) q)))
double code(double w, double wp, double q) {
	return (-cos(w) * pow(wp, 2.0)) - ((sin(w) / w) * q);
}
real(8) function code(w, wp, q)
    real(8), intent (in) :: w
    real(8), intent (in) :: wp
    real(8), intent (in) :: q
    code = (-cos(w) * (wp ** 2.0d0)) - ((sin(w) / w) * q)
end function
public static double code(double w, double wp, double q) {
	return (-Math.cos(w) * Math.pow(wp, 2.0)) - ((Math.sin(w) / w) * q);
}
def code(w, wp, q):
	return (-math.cos(w) * math.pow(wp, 2.0)) - ((math.sin(w) / w) * q)
function code(w, wp, q)
	return Float64(Float64(Float64(-cos(w)) * (wp ^ 2.0)) - Float64(Float64(sin(w) / w) * q))
end
function tmp = code(w, wp, q)
	tmp = (-cos(w) * (wp ^ 2.0)) - ((sin(w) / w) * q);
end
code[w_, wp_, q_] := N[(N[((-N[Cos[w], $MachinePrecision]) * N[Power[wp, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[w], $MachinePrecision] / w), $MachinePrecision] * q), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \end{array} \]
(FPCore (w wp q)
 :precision binary64
 (- (* (- (cos w)) (pow wp 2.0)) (* (/ (sin w) w) q)))
double code(double w, double wp, double q) {
	return (-cos(w) * pow(wp, 2.0)) - ((sin(w) / w) * q);
}
real(8) function code(w, wp, q)
    real(8), intent (in) :: w
    real(8), intent (in) :: wp
    real(8), intent (in) :: q
    code = (-cos(w) * (wp ** 2.0d0)) - ((sin(w) / w) * q)
end function
public static double code(double w, double wp, double q) {
	return (-Math.cos(w) * Math.pow(wp, 2.0)) - ((Math.sin(w) / w) * q);
}
def code(w, wp, q):
	return (-math.cos(w) * math.pow(wp, 2.0)) - ((math.sin(w) / w) * q)
function code(w, wp, q)
	return Float64(Float64(Float64(-cos(w)) * (wp ^ 2.0)) - Float64(Float64(sin(w) / w) * q))
end
function tmp = code(w, wp, q)
	tmp = (-cos(w) * (wp ^ 2.0)) - ((sin(w) / w) * q);
end
code[w_, wp_, q_] := N[(N[((-N[Cos[w], $MachinePrecision]) * N[Power[wp, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Sin[w], $MachinePrecision] / w), $MachinePrecision] * q), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 85.1% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{wp}^{2} \leq 2 \cdot 10^{-102}:\\ \;\;\;\;-q\\ \mathbf{else}:\\ \;\;\;\;-wp \cdot wp\\ \end{array} \end{array} \]
(FPCore (w wp q)
 :precision binary64
 (if (<= (pow wp 2.0) 2e-102) (- q) (- (* wp wp))))
double code(double w, double wp, double q) {
	double tmp;
	if (pow(wp, 2.0) <= 2e-102) {
		tmp = -q;
	} else {
		tmp = -(wp * wp);
	}
	return tmp;
}
real(8) function code(w, wp, q)
    real(8), intent (in) :: w
    real(8), intent (in) :: wp
    real(8), intent (in) :: q
    real(8) :: tmp
    if ((wp ** 2.0d0) <= 2d-102) then
        tmp = -q
    else
        tmp = -(wp * wp)
    end if
    code = tmp
end function
public static double code(double w, double wp, double q) {
	double tmp;
	if (Math.pow(wp, 2.0) <= 2e-102) {
		tmp = -q;
	} else {
		tmp = -(wp * wp);
	}
	return tmp;
}
def code(w, wp, q):
	tmp = 0
	if math.pow(wp, 2.0) <= 2e-102:
		tmp = -q
	else:
		tmp = -(wp * wp)
	return tmp
function code(w, wp, q)
	tmp = 0.0
	if ((wp ^ 2.0) <= 2e-102)
		tmp = Float64(-q);
	else
		tmp = Float64(-Float64(wp * wp));
	end
	return tmp
end
function tmp_2 = code(w, wp, q)
	tmp = 0.0;
	if ((wp ^ 2.0) <= 2e-102)
		tmp = -q;
	else
		tmp = -(wp * wp);
	end
	tmp_2 = tmp;
end
code[w_, wp_, q_] := If[LessEqual[N[Power[wp, 2.0], $MachinePrecision], 2e-102], (-q), (-N[(wp * wp), $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;{wp}^{2} \leq 2 \cdot 10^{-102}:\\
\;\;\;\;-q\\

\mathbf{else}:\\
\;\;\;\;-wp \cdot wp\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (pow.f64 wp #s(literal 2 binary64)) < 1.99999999999999987e-102

    1. Initial program 100.0%

      \[\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \]
    2. Add Preprocessing
    3. Taylor expanded in w around 0

      \[\leadsto \color{blue}{-1 \cdot {wp}^{2} - q} \]
    4. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \color{blue}{-1 \cdot {wp}^{2} + \left(\mathsf{neg}\left(q\right)\right)} \]
      2. mul-1-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left({wp}^{2}\right)\right)} + \left(\mathsf{neg}\left(q\right)\right) \]
      3. distribute-neg-outN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\left({wp}^{2} + q\right)\right)} \]
      4. lower-neg.f64N/A

        \[\leadsto \color{blue}{-\left({wp}^{2} + q\right)} \]
      5. unpow2N/A

        \[\leadsto -\left(\color{blue}{wp \cdot wp} + q\right) \]
      6. lower-fma.f6499.4

        \[\leadsto -\color{blue}{\mathsf{fma}\left(wp, wp, q\right)} \]
    5. Applied rewrites99.4%

      \[\leadsto \color{blue}{-\mathsf{fma}\left(wp, wp, q\right)} \]
    6. Taylor expanded in wp around 0

      \[\leadsto -1 \cdot \color{blue}{q} \]
    7. Step-by-step derivation
      1. Applied rewrites86.9%

        \[\leadsto -q \]

      if 1.99999999999999987e-102 < (pow.f64 wp #s(literal 2 binary64))

      1. Initial program 99.9%

        \[\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \]
      2. Add Preprocessing
      3. Taylor expanded in w around 0

        \[\leadsto \color{blue}{-1 \cdot {wp}^{2} - q} \]
      4. Step-by-step derivation
        1. sub-negN/A

          \[\leadsto \color{blue}{-1 \cdot {wp}^{2} + \left(\mathsf{neg}\left(q\right)\right)} \]
        2. mul-1-negN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left({wp}^{2}\right)\right)} + \left(\mathsf{neg}\left(q\right)\right) \]
        3. distribute-neg-outN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(\left({wp}^{2} + q\right)\right)} \]
        4. lower-neg.f64N/A

          \[\leadsto \color{blue}{-\left({wp}^{2} + q\right)} \]
        5. unpow2N/A

          \[\leadsto -\left(\color{blue}{wp \cdot wp} + q\right) \]
        6. lower-fma.f6497.4

          \[\leadsto -\color{blue}{\mathsf{fma}\left(wp, wp, q\right)} \]
      5. Applied rewrites97.4%

        \[\leadsto \color{blue}{-\mathsf{fma}\left(wp, wp, q\right)} \]
      6. Taylor expanded in wp around inf

        \[\leadsto -{wp}^{2} \]
      7. Step-by-step derivation
        1. Applied rewrites83.0%

          \[\leadsto -wp \cdot wp \]
      8. Recombined 2 regimes into one program.
      9. Add Preprocessing

      Alternative 3: 99.9% accurate, 3.9× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, q, \mathsf{fma}\left(0.5 \cdot wp, wp, \mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, w \cdot w, -0.041666666666666664\right), wp \cdot wp, q \cdot \mathsf{fma}\left(w \cdot w, 0.0001984126984126984, -0.008333333333333333\right)\right) \cdot \left(w \cdot w\right)\right)\right) \cdot w, w, -\mathsf{fma}\left(wp, wp, q\right)\right) \end{array} \]
      (FPCore (w wp q)
       :precision binary64
       (fma
        (*
         (fma
          0.16666666666666666
          q
          (fma
           (* 0.5 wp)
           wp
           (*
            (fma
             (fma 0.001388888888888889 (* w w) -0.041666666666666664)
             (* wp wp)
             (* q (fma (* w w) 0.0001984126984126984 -0.008333333333333333)))
            (* w w))))
         w)
        w
        (- (fma wp wp q))))
      double code(double w, double wp, double q) {
      	return fma((fma(0.16666666666666666, q, fma((0.5 * wp), wp, (fma(fma(0.001388888888888889, (w * w), -0.041666666666666664), (wp * wp), (q * fma((w * w), 0.0001984126984126984, -0.008333333333333333))) * (w * w)))) * w), w, -fma(wp, wp, q));
      }
      
      function code(w, wp, q)
      	return fma(Float64(fma(0.16666666666666666, q, fma(Float64(0.5 * wp), wp, Float64(fma(fma(0.001388888888888889, Float64(w * w), -0.041666666666666664), Float64(wp * wp), Float64(q * fma(Float64(w * w), 0.0001984126984126984, -0.008333333333333333))) * Float64(w * w)))) * w), w, Float64(-fma(wp, wp, q)))
      end
      
      code[w_, wp_, q_] := N[(N[(N[(0.16666666666666666 * q + N[(N[(0.5 * wp), $MachinePrecision] * wp + N[(N[(N[(0.001388888888888889 * N[(w * w), $MachinePrecision] + -0.041666666666666664), $MachinePrecision] * N[(wp * wp), $MachinePrecision] + N[(q * N[(N[(w * w), $MachinePrecision] * 0.0001984126984126984 + -0.008333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(w * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * w), $MachinePrecision] * w + (-N[(wp * wp + q), $MachinePrecision])), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, q, \mathsf{fma}\left(0.5 \cdot wp, wp, \mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, w \cdot w, -0.041666666666666664\right), wp \cdot wp, q \cdot \mathsf{fma}\left(w \cdot w, 0.0001984126984126984, -0.008333333333333333\right)\right) \cdot \left(w \cdot w\right)\right)\right) \cdot w, w, -\mathsf{fma}\left(wp, wp, q\right)\right)
      \end{array}
      
      Derivation
      1. Initial program 100.0%

        \[\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \]
      2. Add Preprocessing
      3. Taylor expanded in w around 0

        \[\leadsto \color{blue}{\left(-1 \cdot {wp}^{2} + {w}^{2} \cdot \left(\left(\frac{1}{2} \cdot {wp}^{2} + {w}^{2} \cdot \left(\left(\frac{-1}{24} \cdot {wp}^{2} + {w}^{2} \cdot \left(\frac{1}{720} \cdot {wp}^{2} - \frac{-1}{5040} \cdot q\right)\right) - \frac{1}{120} \cdot q\right)\right) - \frac{-1}{6} \cdot q\right)\right) - q} \]
      4. Applied rewrites99.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, q, \mathsf{fma}\left(0.5 \cdot wp, wp, \mathsf{fma}\left(\mathsf{fma}\left(0.001388888888888889, w \cdot w, -0.041666666666666664\right), wp \cdot wp, q \cdot \mathsf{fma}\left(w \cdot w, 0.0001984126984126984, -0.008333333333333333\right)\right) \cdot \left(w \cdot w\right)\right)\right) \cdot w, w, -\mathsf{fma}\left(wp, wp, q\right)\right)} \]
      5. Add Preprocessing

      Alternative 4: 99.8% accurate, 5.7× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.041666666666666664, w \cdot w, 0.5\right), wp \cdot wp, q \cdot \mathsf{fma}\left(w \cdot w, -0.008333333333333333, 0.16666666666666666\right)\right) \cdot w, w, -\mathsf{fma}\left(wp, wp, q\right)\right) \end{array} \]
      (FPCore (w wp q)
       :precision binary64
       (fma
        (*
         (fma
          (fma -0.041666666666666664 (* w w) 0.5)
          (* wp wp)
          (* q (fma (* w w) -0.008333333333333333 0.16666666666666666)))
         w)
        w
        (- (fma wp wp q))))
      double code(double w, double wp, double q) {
      	return fma((fma(fma(-0.041666666666666664, (w * w), 0.5), (wp * wp), (q * fma((w * w), -0.008333333333333333, 0.16666666666666666))) * w), w, -fma(wp, wp, q));
      }
      
      function code(w, wp, q)
      	return fma(Float64(fma(fma(-0.041666666666666664, Float64(w * w), 0.5), Float64(wp * wp), Float64(q * fma(Float64(w * w), -0.008333333333333333, 0.16666666666666666))) * w), w, Float64(-fma(wp, wp, q)))
      end
      
      code[w_, wp_, q_] := N[(N[(N[(N[(-0.041666666666666664 * N[(w * w), $MachinePrecision] + 0.5), $MachinePrecision] * N[(wp * wp), $MachinePrecision] + N[(q * N[(N[(w * w), $MachinePrecision] * -0.008333333333333333 + 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * w), $MachinePrecision] * w + (-N[(wp * wp + q), $MachinePrecision])), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.041666666666666664, w \cdot w, 0.5\right), wp \cdot wp, q \cdot \mathsf{fma}\left(w \cdot w, -0.008333333333333333, 0.16666666666666666\right)\right) \cdot w, w, -\mathsf{fma}\left(wp, wp, q\right)\right)
      \end{array}
      
      Derivation
      1. Initial program 100.0%

        \[\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \]
      2. Add Preprocessing
      3. Taylor expanded in w around 0

        \[\leadsto \color{blue}{\left(-1 \cdot {wp}^{2} + {w}^{2} \cdot \left(\left(\frac{1}{2} \cdot {wp}^{2} + {w}^{2} \cdot \left(\frac{-1}{24} \cdot {wp}^{2} - \frac{1}{120} \cdot q\right)\right) - \frac{-1}{6} \cdot q\right)\right) - q} \]
      4. Applied rewrites99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.041666666666666664, w \cdot w, 0.5\right), wp \cdot wp, q \cdot \mathsf{fma}\left(w \cdot w, -0.008333333333333333, 0.16666666666666666\right)\right) \cdot w, w, -\mathsf{fma}\left(wp, wp, q\right)\right)} \]
      5. Add Preprocessing

      Alternative 5: 99.6% accurate, 9.1× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, q, 0.5 \cdot \left(wp \cdot wp\right)\right) \cdot w, w, -\mathsf{fma}\left(wp, wp, q\right)\right) \end{array} \]
      (FPCore (w wp q)
       :precision binary64
       (fma (* (fma 0.16666666666666666 q (* 0.5 (* wp wp))) w) w (- (fma wp wp q))))
      double code(double w, double wp, double q) {
      	return fma((fma(0.16666666666666666, q, (0.5 * (wp * wp))) * w), w, -fma(wp, wp, q));
      }
      
      function code(w, wp, q)
      	return fma(Float64(fma(0.16666666666666666, q, Float64(0.5 * Float64(wp * wp))) * w), w, Float64(-fma(wp, wp, q)))
      end
      
      code[w_, wp_, q_] := N[(N[(N[(0.16666666666666666 * q + N[(0.5 * N[(wp * wp), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * w), $MachinePrecision] * w + (-N[(wp * wp + q), $MachinePrecision])), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, q, 0.5 \cdot \left(wp \cdot wp\right)\right) \cdot w, w, -\mathsf{fma}\left(wp, wp, q\right)\right)
      \end{array}
      
      Derivation
      1. Initial program 100.0%

        \[\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \]
      2. Add Preprocessing
      3. Taylor expanded in w around 0

        \[\leadsto \color{blue}{\left(-1 \cdot {wp}^{2} + {w}^{2} \cdot \left(\frac{1}{2} \cdot {wp}^{2} - \frac{-1}{6} \cdot q\right)\right) - q} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{\left({w}^{2} \cdot \left(\frac{1}{2} \cdot {wp}^{2} - \frac{-1}{6} \cdot q\right) + -1 \cdot {wp}^{2}\right)} - q \]
        2. associate--l+N/A

          \[\leadsto \color{blue}{{w}^{2} \cdot \left(\frac{1}{2} \cdot {wp}^{2} - \frac{-1}{6} \cdot q\right) + \left(-1 \cdot {wp}^{2} - q\right)} \]
        3. *-commutativeN/A

          \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot {wp}^{2} - \frac{-1}{6} \cdot q\right) \cdot {w}^{2}} + \left(-1 \cdot {wp}^{2} - q\right) \]
        4. unpow2N/A

          \[\leadsto \left(\frac{1}{2} \cdot {wp}^{2} - \frac{-1}{6} \cdot q\right) \cdot \color{blue}{\left(w \cdot w\right)} + \left(-1 \cdot {wp}^{2} - q\right) \]
        5. associate-*r*N/A

          \[\leadsto \color{blue}{\left(\left(\frac{1}{2} \cdot {wp}^{2} - \frac{-1}{6} \cdot q\right) \cdot w\right) \cdot w} + \left(-1 \cdot {wp}^{2} - q\right) \]
        6. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\frac{1}{2} \cdot {wp}^{2} - \frac{-1}{6} \cdot q\right) \cdot w, w, -1 \cdot {wp}^{2} - q\right)} \]
        7. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\frac{1}{2} \cdot {wp}^{2} - \frac{-1}{6} \cdot q\right) \cdot w}, w, -1 \cdot {wp}^{2} - q\right) \]
        8. sub-negN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\frac{1}{2} \cdot {wp}^{2} + \left(\mathsf{neg}\left(\frac{-1}{6} \cdot q\right)\right)\right)} \cdot w, w, -1 \cdot {wp}^{2} - q\right) \]
        9. +-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\left(\mathsf{neg}\left(\frac{-1}{6} \cdot q\right)\right) + \frac{1}{2} \cdot {wp}^{2}\right)} \cdot w, w, -1 \cdot {wp}^{2} - q\right) \]
        10. distribute-lft-neg-inN/A

          \[\leadsto \mathsf{fma}\left(\left(\color{blue}{\left(\mathsf{neg}\left(\frac{-1}{6}\right)\right) \cdot q} + \frac{1}{2} \cdot {wp}^{2}\right) \cdot w, w, -1 \cdot {wp}^{2} - q\right) \]
        11. metadata-evalN/A

          \[\leadsto \mathsf{fma}\left(\left(\color{blue}{\frac{1}{6}} \cdot q + \frac{1}{2} \cdot {wp}^{2}\right) \cdot w, w, -1 \cdot {wp}^{2} - q\right) \]
        12. lower-fma.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{6}, q, \frac{1}{2} \cdot {wp}^{2}\right)} \cdot w, w, -1 \cdot {wp}^{2} - q\right) \]
        13. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, q, \color{blue}{\frac{1}{2} \cdot {wp}^{2}}\right) \cdot w, w, -1 \cdot {wp}^{2} - q\right) \]
        14. unpow2N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, q, \frac{1}{2} \cdot \color{blue}{\left(wp \cdot wp\right)}\right) \cdot w, w, -1 \cdot {wp}^{2} - q\right) \]
        15. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, q, \frac{1}{2} \cdot \color{blue}{\left(wp \cdot wp\right)}\right) \cdot w, w, -1 \cdot {wp}^{2} - q\right) \]
        16. sub-negN/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{1}{6}, q, \frac{1}{2} \cdot \left(wp \cdot wp\right)\right) \cdot w, w, \color{blue}{-1 \cdot {wp}^{2} + \left(\mathsf{neg}\left(q\right)\right)}\right) \]
      5. Applied rewrites99.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, q, 0.5 \cdot \left(wp \cdot wp\right)\right) \cdot w, w, -\mathsf{fma}\left(wp, wp, q\right)\right)} \]
      6. Add Preprocessing

      Alternative 6: 99.1% accurate, 36.4× speedup?

      \[\begin{array}{l} \\ -\mathsf{fma}\left(wp, wp, q\right) \end{array} \]
      (FPCore (w wp q) :precision binary64 (- (fma wp wp q)))
      double code(double w, double wp, double q) {
      	return -fma(wp, wp, q);
      }
      
      function code(w, wp, q)
      	return Float64(-fma(wp, wp, q))
      end
      
      code[w_, wp_, q_] := (-N[(wp * wp + q), $MachinePrecision])
      
      \begin{array}{l}
      
      \\
      -\mathsf{fma}\left(wp, wp, q\right)
      \end{array}
      
      Derivation
      1. Initial program 100.0%

        \[\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \]
      2. Add Preprocessing
      3. Taylor expanded in w around 0

        \[\leadsto \color{blue}{-1 \cdot {wp}^{2} - q} \]
      4. Step-by-step derivation
        1. sub-negN/A

          \[\leadsto \color{blue}{-1 \cdot {wp}^{2} + \left(\mathsf{neg}\left(q\right)\right)} \]
        2. mul-1-negN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left({wp}^{2}\right)\right)} + \left(\mathsf{neg}\left(q\right)\right) \]
        3. distribute-neg-outN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(\left({wp}^{2} + q\right)\right)} \]
        4. lower-neg.f64N/A

          \[\leadsto \color{blue}{-\left({wp}^{2} + q\right)} \]
        5. unpow2N/A

          \[\leadsto -\left(\color{blue}{wp \cdot wp} + q\right) \]
        6. lower-fma.f6499.0

          \[\leadsto -\color{blue}{\mathsf{fma}\left(wp, wp, q\right)} \]
      5. Applied rewrites99.0%

        \[\leadsto \color{blue}{-\mathsf{fma}\left(wp, wp, q\right)} \]
      6. Add Preprocessing

      Alternative 7: 74.4% accurate, 109.3× speedup?

      \[\begin{array}{l} \\ -q \end{array} \]
      (FPCore (w wp q) :precision binary64 (- q))
      double code(double w, double wp, double q) {
      	return -q;
      }
      
      real(8) function code(w, wp, q)
          real(8), intent (in) :: w
          real(8), intent (in) :: wp
          real(8), intent (in) :: q
          code = -q
      end function
      
      public static double code(double w, double wp, double q) {
      	return -q;
      }
      
      def code(w, wp, q):
      	return -q
      
      function code(w, wp, q)
      	return Float64(-q)
      end
      
      function tmp = code(w, wp, q)
      	tmp = -q;
      end
      
      code[w_, wp_, q_] := (-q)
      
      \begin{array}{l}
      
      \\
      -q
      \end{array}
      
      Derivation
      1. Initial program 100.0%

        \[\left(-\cos w\right) \cdot {wp}^{2} - \frac{\sin w}{w} \cdot q \]
      2. Add Preprocessing
      3. Taylor expanded in w around 0

        \[\leadsto \color{blue}{-1 \cdot {wp}^{2} - q} \]
      4. Step-by-step derivation
        1. sub-negN/A

          \[\leadsto \color{blue}{-1 \cdot {wp}^{2} + \left(\mathsf{neg}\left(q\right)\right)} \]
        2. mul-1-negN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left({wp}^{2}\right)\right)} + \left(\mathsf{neg}\left(q\right)\right) \]
        3. distribute-neg-outN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(\left({wp}^{2} + q\right)\right)} \]
        4. lower-neg.f64N/A

          \[\leadsto \color{blue}{-\left({wp}^{2} + q\right)} \]
        5. unpow2N/A

          \[\leadsto -\left(\color{blue}{wp \cdot wp} + q\right) \]
        6. lower-fma.f6499.0

          \[\leadsto -\color{blue}{\mathsf{fma}\left(wp, wp, q\right)} \]
      5. Applied rewrites99.0%

        \[\leadsto \color{blue}{-\mathsf{fma}\left(wp, wp, q\right)} \]
      6. Taylor expanded in wp around 0

        \[\leadsto -1 \cdot \color{blue}{q} \]
      7. Step-by-step derivation
        1. Applied rewrites72.9%

          \[\leadsto -q \]
        2. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 1 
        (FPCore (w wp q)
          :name " -cos(w)*wp^2 - (sin(w)/w)*q"
          :precision binary64
          :pre (and (and (and (<= -1.0 w) (<= w 1.0)) (and (<= -1000.0 wp) (<= wp 1000.0))) (and (<= -1000.0 q) (<= q 1000.0)))
          (- (* (- (cos w)) (pow wp 2.0)) (* (/ (sin w) w) q)))