?

Average Error: 0.2% → 0.2%
Time: 11.8s
Precision: binary64
Cost: 19584

?

\[x \cdot \cos y - z \cdot \sin y \]
\[\mathsf{fma}\left(\cos y, x, z \cdot \left(-\sin y\right)\right) \]
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* z (sin y))))
(FPCore (x y z) :precision binary64 (fma (cos y) x (* z (- (sin y)))))
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, (z * -sin(y)));
}
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(z * Float64(-sin(y))))
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[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
x \cdot \cos y - z \cdot \sin y
\mathsf{fma}\left(\cos y, x, z \cdot \left(-\sin y\right)\right)

Error?

Derivation?

  1. Initial program 0.2

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

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

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

    [Start]0.2

    \[ -1 \cdot \left(z \cdot \sin y\right) + \cos y \cdot x \]

    +-commutative [=>]0.2

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

    mul-1-neg [=>]0.2

    \[ \cos y \cdot x + \color{blue}{\left(-z \cdot \sin y\right)} \]

    distribute-rgt-neg-out [<=]0.2

    \[ \cos y \cdot x + \color{blue}{z \cdot \left(-\sin y\right)} \]

    fma-udef [<=]0.2

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

    distribute-rgt-neg-out [=>]0.2

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

    distribute-lft-neg-in [=>]0.2

    \[ \mathsf{fma}\left(\cos y, x, \color{blue}{\left(-z\right) \cdot \sin y}\right) \]
  4. Final simplification0.2

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

Alternatives

Alternative 1
Error0.2%
Cost13248
\[\cos y \cdot x - z \cdot \sin y \]
Alternative 2
Error13.79%
Cost7890
\[\begin{array}{l} \mathbf{if}\;z \leq -1.25 \cdot 10^{+16} \lor \neg \left(z \leq 6 \cdot 10^{-99}\right) \land \left(z \leq 0.039 \lor \neg \left(z \leq 3.7 \cdot 10^{+97}\right)\right):\\ \;\;\;\;x - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{1}{\cos y}} - \frac{z}{\frac{1}{y} + y \cdot 0.16666666666666666}\\ \end{array} \]
Alternative 3
Error29.41%
Cost7451
\[\begin{array}{l} \mathbf{if}\;x \leq -1.96 \cdot 10^{+33} \lor \neg \left(x \leq -8 \cdot 10^{-5} \lor \neg \left(x \leq -3.6 \cdot 10^{-211}\right) \land \left(x \leq 9.5 \cdot 10^{-190} \lor \neg \left(x \leq 5.6 \cdot 10^{-155}\right) \land x \leq 2.2 \cdot 10^{-32}\right)\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-\sin y\right)\\ \end{array} \]
Alternative 4
Error16.27%
Cost7250
\[\begin{array}{l} \mathbf{if}\;z \leq -2.8 \cdot 10^{+15} \lor \neg \left(z \leq 4.6 \cdot 10^{-101}\right) \land \left(z \leq 0.45 \lor \neg \left(z \leq 3.7 \cdot 10^{+97}\right)\right):\\ \;\;\;\;x - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot x\\ \end{array} \]
Alternative 5
Error25.44%
Cost6857
\[\begin{array}{l} \mathbf{if}\;y \leq -7.4 \cdot 10^{-6} \lor \neg \left(y \leq 0.00014\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot z\\ \end{array} \]
Alternative 6
Error59.97%
Cost520
\[\begin{array}{l} \mathbf{if}\;x \leq 5 \cdot 10^{-308}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{-198}:\\ \;\;\;\;z \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error49.06%
Cost320
\[x - y \cdot z \]
Alternative 8
Error60.73%
Cost64
\[x \]

Error

Reproduce?

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