Average Error: 0.1 → 0.1
Time: 12.9s
Precision: binary64
Cost: 19584
\[x \cdot \cos y - z \cdot \sin y \]
\[\mathsf{fma}\left(\cos y, x, \sin y \cdot \left(-z\right)\right) \]
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
(FPCore (x y z) :precision binary64 (fma (cos y) x (* (sin y) (- z))))
double code(double x, double y, double z) {
	return (x * cos(y)) - (z * sin(y));
}
double code(double x, double y, double z) {
	return fma(cos(y), x, (sin(y) * -z));
}
function code(x, y, z)
	return Float64(Float64(x * cos(y)) - Float64(z * sin(y)))
end
function code(x, y, z)
	return fma(cos(y), x, Float64(sin(y) * Float64(-z)))
end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]), $MachinePrecision]
x \cdot \cos y - z \cdot \sin y
\mathsf{fma}\left(\cos y, x, \sin y \cdot \left(-z\right)\right)

Error

Derivation

  1. Initial program 0.1

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Taylor expanded in x around 0 0.1

    \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sin y\right) + \cos y \cdot x} \]
  3. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(\cos y, x, \sin y \cdot \left(-z\right)\right)} \]
    Proof
    (fma.f64 (cos.f64 y) x (*.f64 (sin.f64 y) (neg.f64 z))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (cos.f64 y) x (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (sin.f64 y) z)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (cos.f64 y) x (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 z (sin.f64 y))))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> fma-udef_binary64 (+.f64 (*.f64 (cos.f64 y) x) (neg.f64 (*.f64 z (sin.f64 y))))): 1 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 (*.f64 z (sin.f64 y))) (*.f64 (cos.f64 y) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 z (sin.f64 y)))) (*.f64 (cos.f64 y) x)): 0 points increase in error, 0 points decrease in error
  4. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(\cos y, x, \sin y \cdot \left(-z\right)\right) \]

Alternatives

Alternative 1
Error0.1
Cost13248
\[\cos y \cdot x - \sin y \cdot z \]
Alternative 2
Error16.7
Cost7184
\[\begin{array}{l} t_0 := \cos y \cdot x\\ t_1 := \sin y \cdot \left(-z\right)\\ \mathbf{if}\;x \leq -7.966411202625937 \cdot 10^{-45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.945795117444892 \cdot 10^{-184}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.89864710493546 \cdot 10^{-158}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 6.508842443965079 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error8.5
Cost6984
\[\begin{array}{l} t_0 := \cos y \cdot x\\ \mathbf{if}\;x \leq -1.479569144424034 \cdot 10^{+93}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.1788711634310487 \cdot 10^{+96}:\\ \;\;\;\;x - \sin y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error16.5
Cost6856
\[\begin{array}{l} t_0 := \cos y \cdot x\\ \mathbf{if}\;y \leq -75.196613614836:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.655831883134953 \cdot 10^{-16}:\\ \;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5\right) - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error37.3
Cost520
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0392329434757393 \cdot 10^{-252}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.945795117444892 \cdot 10^{-184}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error30.4
Cost320
\[x - y \cdot z \]
Alternative 7
Error38.6
Cost64
\[x \]

Error

Reproduce

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