Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B

Percentage Accurate: 99.8% → 99.8%
Time: 9.0s
Alternatives: 5
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ x \cdot \sin y + z \cdot \cos y \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
	return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
	return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z):
	return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z)
	return Float64(Float64(x * sin(y)) + Float64(z * cos(y)))
end
function tmp = code(x, y, z)
	tmp = (x * sin(y)) + (z * cos(y));
end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \sin y + z \cdot \cos y
\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 5 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: 99.8% accurate, 1.0× speedup?

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

\\
x \cdot \sin y + z \cdot \cos y
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\cos y, z, \sin y \cdot x\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma (cos y) z (* (sin y) x)))
double code(double x, double y, double z) {
	return fma(cos(y), z, (sin(y) * x));
}
function code(x, y, z)
	return fma(cos(y), z, Float64(sin(y) * x))
end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[x \cdot \sin y + z \cdot \cos y \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{x \cdot \sin y + z \cdot \cos y} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{z \cdot \cos y + x \cdot \sin y} \]
    3. lift-*.f64N/A

      \[\leadsto \color{blue}{z \cdot \cos y} + x \cdot \sin y \]
    4. *-commutativeN/A

      \[\leadsto \color{blue}{\cos y \cdot z} + x \cdot \sin y \]
    5. lower-fma.f6499.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)} \]
    6. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\cos y, z, \color{blue}{x \cdot \sin y}\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\cos y, z, \color{blue}{\sin y \cdot x}\right) \]
    8. lower-*.f6499.8

      \[\leadsto \mathsf{fma}\left(\cos y, z, \color{blue}{\sin y \cdot x}\right) \]
  4. Applied rewrites99.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)} \]
  5. Add Preprocessing

Alternative 2: 86.5% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-91} \lor \neg \left(x \leq 2 \cdot 10^{-94}\right):\\ \;\;\;\;\mathsf{fma}\left(1, z, \sin y \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -7.5e-91) (not (<= x 2e-94)))
   (fma 1.0 z (* (sin y) x))
   (* (cos y) z)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -7.5e-91) || !(x <= 2e-94)) {
		tmp = fma(1.0, z, (sin(y) * x));
	} else {
		tmp = cos(y) * z;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((x <= -7.5e-91) || !(x <= 2e-94))
		tmp = fma(1.0, z, Float64(sin(y) * x));
	else
		tmp = Float64(cos(y) * z);
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e-91], N[Not[LessEqual[x, 2e-94]], $MachinePrecision]], N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-91} \lor \neg \left(x \leq 2 \cdot 10^{-94}\right):\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.50000000000000051e-91 or 1.9999999999999999e-94 < x

    1. Initial program 99.7%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x \cdot \sin y + z \cdot \cos y} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{z \cdot \cos y + x \cdot \sin y} \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{z \cdot \cos y} + x \cdot \sin y \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\cos y \cdot z} + x \cdot \sin y \]
      5. lower-fma.f6499.7

        \[\leadsto \color{blue}{\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)} \]
      6. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\cos y, z, \color{blue}{x \cdot \sin y}\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos y, z, \color{blue}{\sin y \cdot x}\right) \]
      8. lower-*.f6499.7

        \[\leadsto \mathsf{fma}\left(\cos y, z, \color{blue}{\sin y \cdot x}\right) \]
    4. Applied rewrites99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)} \]
    5. Taylor expanded in y around 0

      \[\leadsto \mathsf{fma}\left(\color{blue}{1}, z, \sin y \cdot x\right) \]
    6. Step-by-step derivation
      1. Applied rewrites89.0%

        \[\leadsto \mathsf{fma}\left(\color{blue}{1}, z, \sin y \cdot x\right) \]

      if -7.50000000000000051e-91 < x < 1.9999999999999999e-94

      1. Initial program 99.8%

        \[x \cdot \sin y + z \cdot \cos y \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{z \cdot \cos y} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\cos y \cdot z} \]
        2. lower-*.f64N/A

          \[\leadsto \color{blue}{\cos y \cdot z} \]
        3. lower-cos.f6491.6

          \[\leadsto \color{blue}{\cos y} \cdot z \]
      5. Applied rewrites91.6%

        \[\leadsto \color{blue}{\cos y \cdot z} \]
    7. Recombined 2 regimes into one program.
    8. Final simplification89.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-91} \lor \neg \left(x \leq 2 \cdot 10^{-94}\right):\\ \;\;\;\;\mathsf{fma}\left(1, z, \sin y \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot z\\ \end{array} \]
    9. Add Preprocessing

    Alternative 3: 75.4% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.7 \lor \neg \left(y \leq 0.5\right):\\ \;\;\;\;\cos y \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right), y \cdot y, x\right) \cdot y + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, y \cdot y, 0.041666666666666664\right), y \cdot y, -0.5\right), y \cdot y, 1\right)\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (or (<= y -1.7) (not (<= y 0.5)))
       (* (cos y) z)
       (+
        (*
         (fma
          (* x (fma 0.008333333333333333 (* y y) -0.16666666666666666))
          (* y y)
          x)
         y)
        (*
         z
         (fma
          (fma
           (fma -0.001388888888888889 (* y y) 0.041666666666666664)
           (* y y)
           -0.5)
          (* y y)
          1.0)))))
    double code(double x, double y, double z) {
    	double tmp;
    	if ((y <= -1.7) || !(y <= 0.5)) {
    		tmp = cos(y) * z;
    	} else {
    		tmp = (fma((x * fma(0.008333333333333333, (y * y), -0.16666666666666666)), (y * y), x) * y) + (z * fma(fma(fma(-0.001388888888888889, (y * y), 0.041666666666666664), (y * y), -0.5), (y * y), 1.0));
    	}
    	return tmp;
    }
    
    function code(x, y, z)
    	tmp = 0.0
    	if ((y <= -1.7) || !(y <= 0.5))
    		tmp = Float64(cos(y) * z);
    	else
    		tmp = Float64(Float64(fma(Float64(x * fma(0.008333333333333333, Float64(y * y), -0.16666666666666666)), Float64(y * y), x) * y) + Float64(z * fma(fma(fma(-0.001388888888888889, Float64(y * y), 0.041666666666666664), Float64(y * y), -0.5), Float64(y * y), 1.0)));
    	end
    	return tmp
    end
    
    code[x_, y_, z_] := If[Or[LessEqual[y, -1.7], N[Not[LessEqual[y, 0.5]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(N[(N[(x * N[(0.008333333333333333 * N[(y * y), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[(y * y), $MachinePrecision] + x), $MachinePrecision] * y), $MachinePrecision] + N[(z * N[(N[(N[(-0.001388888888888889 * N[(y * y), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] * N[(y * y), $MachinePrecision] + -0.5), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;y \leq -1.7 \lor \neg \left(y \leq 0.5\right):\\
    \;\;\;\;\cos y \cdot z\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(x \cdot \mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right), y \cdot y, x\right) \cdot y + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, y \cdot y, 0.041666666666666664\right), y \cdot y, -0.5\right), y \cdot y, 1\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if y < -1.69999999999999996 or 0.5 < y

      1. Initial program 99.6%

        \[x \cdot \sin y + z \cdot \cos y \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{z \cdot \cos y} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\cos y \cdot z} \]
        2. lower-*.f64N/A

          \[\leadsto \color{blue}{\cos y \cdot z} \]
        3. lower-cos.f6447.7

          \[\leadsto \color{blue}{\cos y} \cdot z \]
      5. Applied rewrites47.7%

        \[\leadsto \color{blue}{\cos y \cdot z} \]

      if -1.69999999999999996 < y < 0.5

      1. Initial program 100.0%

        \[x \cdot \sin y + z \cdot \cos y \]
      2. Add Preprocessing
      3. Taylor expanded in y around 0

        \[\leadsto \color{blue}{x \cdot y} + z \cdot \cos y \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{y \cdot x} + z \cdot \cos y \]
        2. lower-*.f6499.5

          \[\leadsto \color{blue}{y \cdot x} + z \cdot \cos y \]
      5. Applied rewrites99.5%

        \[\leadsto \color{blue}{y \cdot x} + z \cdot \cos y \]
      6. Taylor expanded in y around 0

        \[\leadsto y \cdot x + z \cdot \color{blue}{\left(1 + {y}^{2} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right)\right)} \]
      7. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto y \cdot x + z \cdot \color{blue}{\left({y}^{2} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right) + 1\right)} \]
        2. *-commutativeN/A

          \[\leadsto y \cdot x + z \cdot \left(\color{blue}{\left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right) \cdot {y}^{2}} + 1\right) \]
        3. lower-fma.f64N/A

          \[\leadsto y \cdot x + z \cdot \color{blue}{\mathsf{fma}\left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}, {y}^{2}, 1\right)} \]
        4. sub-negN/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\color{blue}{{y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}, {y}^{2}, 1\right) \]
        5. *-commutativeN/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\color{blue}{\left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) \cdot {y}^{2}} + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right), {y}^{2}, 1\right) \]
        6. metadata-evalN/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) \cdot {y}^{2} + \color{blue}{\frac{-1}{2}}, {y}^{2}, 1\right) \]
        7. lower-fma.f64N/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}, {y}^{2}, \frac{-1}{2}\right)}, {y}^{2}, 1\right) \]
        8. +-commutativeN/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\frac{-1}{720} \cdot {y}^{2} + \frac{1}{24}}, {y}^{2}, \frac{-1}{2}\right), {y}^{2}, 1\right) \]
        9. lower-fma.f64N/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(\frac{-1}{720}, {y}^{2}, \frac{1}{24}\right)}, {y}^{2}, \frac{-1}{2}\right), {y}^{2}, 1\right) \]
        10. unpow2N/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{720}, \color{blue}{y \cdot y}, \frac{1}{24}\right), {y}^{2}, \frac{-1}{2}\right), {y}^{2}, 1\right) \]
        11. lower-*.f64N/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{720}, \color{blue}{y \cdot y}, \frac{1}{24}\right), {y}^{2}, \frac{-1}{2}\right), {y}^{2}, 1\right) \]
        12. unpow2N/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{720}, y \cdot y, \frac{1}{24}\right), \color{blue}{y \cdot y}, \frac{-1}{2}\right), {y}^{2}, 1\right) \]
        13. lower-*.f64N/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{720}, y \cdot y, \frac{1}{24}\right), \color{blue}{y \cdot y}, \frac{-1}{2}\right), {y}^{2}, 1\right) \]
        14. unpow2N/A

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{720}, y \cdot y, \frac{1}{24}\right), y \cdot y, \frac{-1}{2}\right), \color{blue}{y \cdot y}, 1\right) \]
        15. lower-*.f6499.5

          \[\leadsto y \cdot x + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, y \cdot y, 0.041666666666666664\right), y \cdot y, -0.5\right), \color{blue}{y \cdot y}, 1\right) \]
      8. Applied rewrites99.5%

        \[\leadsto y \cdot x + z \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, y \cdot y, 0.041666666666666664\right), y \cdot y, -0.5\right), y \cdot y, 1\right)} \]
      9. Taylor expanded in y around 0

        \[\leadsto \color{blue}{y \cdot \left(x + {y}^{2} \cdot \left(\frac{-1}{6} \cdot x + \frac{1}{120} \cdot \left(x \cdot {y}^{2}\right)\right)\right)} + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{720}, y \cdot y, \frac{1}{24}\right), y \cdot y, \frac{-1}{2}\right), y \cdot y, 1\right) \]
      10. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{\left(x + {y}^{2} \cdot \left(\frac{-1}{6} \cdot x + \frac{1}{120} \cdot \left(x \cdot {y}^{2}\right)\right)\right) \cdot y} + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{720}, y \cdot y, \frac{1}{24}\right), y \cdot y, \frac{-1}{2}\right), y \cdot y, 1\right) \]
        2. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(x + {y}^{2} \cdot \left(\frac{-1}{6} \cdot x + \frac{1}{120} \cdot \left(x \cdot {y}^{2}\right)\right)\right) \cdot y} + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{720}, y \cdot y, \frac{1}{24}\right), y \cdot y, \frac{-1}{2}\right), y \cdot y, 1\right) \]
      11. Applied rewrites100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot \mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right), y \cdot y, x\right) \cdot y} + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, y \cdot y, 0.041666666666666664\right), y \cdot y, -0.5\right), y \cdot y, 1\right) \]
    3. Recombined 2 regimes into one program.
    4. Final simplification73.4%

      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.7 \lor \neg \left(y \leq 0.5\right):\\ \;\;\;\;\cos y \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right), y \cdot y, x\right) \cdot y + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, y \cdot y, 0.041666666666666664\right), y \cdot y, -0.5\right), y \cdot y, 1\right)\\ \end{array} \]
    5. Add Preprocessing

    Alternative 4: 53.5% accurate, 30.6× speedup?

    \[\begin{array}{l} \\ \mathsf{fma}\left(y, x, z\right) \end{array} \]
    (FPCore (x y z) :precision binary64 (fma y x z))
    double code(double x, double y, double z) {
    	return fma(y, x, z);
    }
    
    function code(x, y, z)
    	return fma(y, x, z)
    end
    
    code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \mathsf{fma}\left(y, x, z\right)
    \end{array}
    
    Derivation
    1. Initial program 99.8%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

      \[\leadsto \color{blue}{z + x \cdot y} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{x \cdot y + z} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} + z \]
      3. lower-fma.f6451.2

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, z\right)} \]
    5. Applied rewrites51.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, z\right)} \]
    6. Add Preprocessing

    Alternative 5: 39.4% accurate, 35.7× speedup?

    \[\begin{array}{l} \\ 1 \cdot z \end{array} \]
    (FPCore (x y z) :precision binary64 (* 1.0 z))
    double code(double x, double y, double z) {
    	return 1.0 * z;
    }
    
    real(8) function code(x, y, z)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8), intent (in) :: z
        code = 1.0d0 * z
    end function
    
    public static double code(double x, double y, double z) {
    	return 1.0 * z;
    }
    
    def code(x, y, z):
    	return 1.0 * z
    
    function code(x, y, z)
    	return Float64(1.0 * z)
    end
    
    function tmp = code(x, y, z)
    	tmp = 1.0 * z;
    end
    
    code[x_, y_, z_] := N[(1.0 * z), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    1 \cdot z
    \end{array}
    
    Derivation
    1. Initial program 99.8%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x \cdot \sin y + z \cdot \cos y} \]
      2. flip-+N/A

        \[\leadsto \color{blue}{\frac{\left(x \cdot \sin y\right) \cdot \left(x \cdot \sin y\right) - \left(z \cdot \cos y\right) \cdot \left(z \cdot \cos y\right)}{x \cdot \sin y - z \cdot \cos y}} \]
      3. div-subN/A

        \[\leadsto \color{blue}{\frac{\left(x \cdot \sin y\right) \cdot \left(x \cdot \sin y\right)}{x \cdot \sin y - z \cdot \cos y} - \frac{\left(z \cdot \cos y\right) \cdot \left(z \cdot \cos y\right)}{x \cdot \sin y - z \cdot \cos y}} \]
      4. sub-negN/A

        \[\leadsto \color{blue}{\frac{\left(x \cdot \sin y\right) \cdot \left(x \cdot \sin y\right)}{x \cdot \sin y - z \cdot \cos y} + \left(\mathsf{neg}\left(\frac{\left(z \cdot \cos y\right) \cdot \left(z \cdot \cos y\right)}{x \cdot \sin y - z \cdot \cos y}\right)\right)} \]
      5. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\left(x \cdot \sin y\right)} \cdot \left(x \cdot \sin y\right)}{x \cdot \sin y - z \cdot \cos y} + \left(\mathsf{neg}\left(\frac{\left(z \cdot \cos y\right) \cdot \left(z \cdot \cos y\right)}{x \cdot \sin y - z \cdot \cos y}\right)\right) \]
      6. associate-*l*N/A

        \[\leadsto \frac{\color{blue}{x \cdot \left(\sin y \cdot \left(x \cdot \sin y\right)\right)}}{x \cdot \sin y - z \cdot \cos y} + \left(\mathsf{neg}\left(\frac{\left(z \cdot \cos y\right) \cdot \left(z \cdot \cos y\right)}{x \cdot \sin y - z \cdot \cos y}\right)\right) \]
      7. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\left(\sin y \cdot \left(x \cdot \sin y\right)\right) \cdot x}}{x \cdot \sin y - z \cdot \cos y} + \left(\mathsf{neg}\left(\frac{\left(z \cdot \cos y\right) \cdot \left(z \cdot \cos y\right)}{x \cdot \sin y - z \cdot \cos y}\right)\right) \]
      8. associate-/l*N/A

        \[\leadsto \color{blue}{\left(\sin y \cdot \left(x \cdot \sin y\right)\right) \cdot \frac{x}{x \cdot \sin y - z \cdot \cos y}} + \left(\mathsf{neg}\left(\frac{\left(z \cdot \cos y\right) \cdot \left(z \cdot \cos y\right)}{x \cdot \sin y - z \cdot \cos y}\right)\right) \]
      9. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y \cdot \left(x \cdot \sin y\right), \frac{x}{x \cdot \sin y - z \cdot \cos y}, \mathsf{neg}\left(\frac{\left(z \cdot \cos y\right) \cdot \left(z \cdot \cos y\right)}{x \cdot \sin y - z \cdot \cos y}\right)\right)} \]
    4. Applied rewrites69.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left({\sin y}^{2} \cdot x, \frac{x}{\mathsf{fma}\left(-z, \cos y, \sin y \cdot x\right)}, -\frac{{\left(\cos y \cdot z\right)}^{2}}{\mathsf{fma}\left(-z, \cos y, \sin y \cdot x\right)}\right)} \]
    5. Taylor expanded in z around inf

      \[\leadsto \color{blue}{z \cdot \left(\frac{x \cdot \sin y}{z} - -1 \cdot \cos y\right)} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{x \cdot \sin y}{z} - -1 \cdot \cos y\right) \cdot z} \]
      2. sub-negN/A

        \[\leadsto \color{blue}{\left(\frac{x \cdot \sin y}{z} + \left(\mathsf{neg}\left(-1 \cdot \cos y\right)\right)\right)} \cdot z \]
      3. mul-1-negN/A

        \[\leadsto \left(\frac{x \cdot \sin y}{z} + \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(\cos y\right)\right)}\right)\right)\right) \cdot z \]
      4. remove-double-negN/A

        \[\leadsto \left(\frac{x \cdot \sin y}{z} + \color{blue}{\cos y}\right) \cdot z \]
      5. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\cos y + \frac{x \cdot \sin y}{z}\right)} \cdot z \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\cos y + \frac{x \cdot \sin y}{z}\right) \cdot z} \]
      7. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{x \cdot \sin y}{z} + \cos y\right)} \cdot z \]
      8. associate-/l*N/A

        \[\leadsto \left(\color{blue}{x \cdot \frac{\sin y}{z}} + \cos y\right) \cdot z \]
      9. *-commutativeN/A

        \[\leadsto \left(\color{blue}{\frac{\sin y}{z} \cdot x} + \cos y\right) \cdot z \]
      10. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin y}{z}, x, \cos y\right)} \cdot z \]
      11. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{\sin y}{z}}, x, \cos y\right) \cdot z \]
      12. lower-sin.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\sin y}}{z}, x, \cos y\right) \cdot z \]
      13. lower-cos.f6490.5

        \[\leadsto \mathsf{fma}\left(\frac{\sin y}{z}, x, \color{blue}{\cos y}\right) \cdot z \]
    7. Applied rewrites90.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sin y}{z}, x, \cos y\right) \cdot z} \]
    8. Taylor expanded in x around inf

      \[\leadsto \frac{x \cdot \sin y}{z} \cdot z \]
    9. Step-by-step derivation
      1. Applied rewrites32.4%

        \[\leadsto \frac{\sin y \cdot x}{z} \cdot z \]
      2. Taylor expanded in y around 0

        \[\leadsto 1 \cdot z \]
      3. Step-by-step derivation
        1. Applied rewrites39.3%

          \[\leadsto 1 \cdot z \]
        2. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 2024323 
        (FPCore (x y z)
          :name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
          :precision binary64
          (+ (* x (sin y)) (* z (cos y))))