?

Average Error: 0.1 → 0.1
Time: 13.0s
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.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, \left(-z\right) \cdot \sin y\right)} \]
    Proof

    [Start]0.1

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

    +-commutative [=>]0.1

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

    mul-1-neg [=>]0.1

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

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

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

    fma-udef [<=]0.1

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

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

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

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

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

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

Alternatives

Alternative 1
Error0.1
Cost13248
\[\cos y \cdot x - z \cdot \sin y \]
Alternative 2
Error16.1
Cost7317
\[\begin{array}{l} t_0 := z \cdot \left(-\sin y\right)\\ t_1 := \cos y \cdot x\\ \mathbf{if}\;y \leq -3.5 \cdot 10^{+203}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -0.0074:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 0.00013:\\ \;\;\;\;\left(x + -0.5 \cdot \left(y \cdot \left(y \cdot x\right)\right)\right) - y \cdot z\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{+182} \lor \neg \left(y \leq 2.7 \cdot 10^{+274}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error16.2
Cost7317
\[\begin{array}{l} t_0 := z \cdot \left(-\sin y\right)\\ t_1 := \cos y \cdot x\\ \mathbf{if}\;y \leq -9.2 \cdot 10^{+208}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.65 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(-y, z, x\right)\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+182} \lor \neg \left(y \leq 1.5 \cdot 10^{+273}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error8.8
Cost6985
\[\begin{array}{l} \mathbf{if}\;x \leq -7.7 \cdot 10^{-25} \lor \neg \left(x \leq 8.6 \cdot 10^{+46}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \sin y\\ \end{array} \]
Alternative 5
Error16.0
Cost6857
\[\begin{array}{l} \mathbf{if}\;y \leq -0.015 \lor \neg \left(y \leq 0.00013\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(x + -0.5 \cdot \left(y \cdot \left(y \cdot x\right)\right)\right) - y \cdot z\\ \end{array} \]
Alternative 6
Error37.2
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -6.5 \cdot 10^{+165} \lor \neg \left(z \leq 4.4 \cdot 10^{+87}\right):\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error30.7
Cost320
\[x - y \cdot z \]
Alternative 8
Error38.7
Cost64
\[x \]

Error

Reproduce?

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