Average Error: 0.1 → 0.1
Time: 11.5s
Precision: binary64
Cost: 19584
\[x \cdot \cos y - z \cdot \sin y \]
\[\mathsf{fma}\left(\cos y, x, \left(-z\right) \cdot \sin y\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(Float64(-z) * 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, \left(-z\right) \cdot \sin y\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
    (fma.f64 (cos.f64 y) x (*.f64 (neg.f64 z) (sin.f64 y))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (cos.f64 y) x (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 z (sin.f64 y))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (cos.f64 y) x (Rewrite<= distribute-rgt-neg-out_binary64 (*.f64 z (neg.f64 (sin.f64 y))))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> fma-udef_binary64 (+.f64 (*.f64 (cos.f64 y) x) (*.f64 z (neg.f64 (sin.f64 y))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (cos.f64 y) x) (Rewrite=> distribute-rgt-neg-out_binary64 (neg.f64 (*.f64 z (sin.f64 y))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (cos.f64 y) x) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 z (sin.f64 y))))): 7 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (*.f64 z (sin.f64 y))) (*.f64 (cos.f64 y) x))): 0 points increase in error, 7 points decrease in error
  4. Final simplification0.1

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

Alternatives

Alternative 1
Error0.1
Cost13248
\[\cos y \cdot x - z \cdot \sin y \]
Alternative 2
Error9.4
Cost7890
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6 \cdot 10^{+110} \lor \neg \left(x \leq 2 \cdot 10^{-155} \lor \neg \left(x \leq 5 \cdot 10^{+30}\right) \land x \leq 6.6 \cdot 10^{+45}\right):\\ \;\;\;\;\frac{x}{\frac{1}{\cos y}} - \frac{z}{\frac{1}{y} + y \cdot 0.16666666666666666}\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \sin y\\ \end{array} \]
Alternative 3
Error15.7
Cost7253
\[\begin{array}{l} t_0 := \left(-z\right) \cdot \sin y\\ t_1 := \cos y \cdot x\\ \mathbf{if}\;y \leq -2.9 \cdot 10^{+235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -9.8 \cdot 10^{+26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -0.032:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-6} \lor \neg \left(y \leq 8.5 \cdot 10^{-6}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot z\\ \end{array} \]
Alternative 4
Error9.1
Cost6985
\[\begin{array}{l} \mathbf{if}\;x \leq -1.75 \cdot 10^{+110} \lor \neg \left(x \leq 2.6 \cdot 10^{+87}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \sin y\\ \end{array} \]
Alternative 5
Error15.7
Cost6857
\[\begin{array}{l} \mathbf{if}\;y \leq -0.17 \lor \neg \left(y \leq 8.5 \cdot 10^{-6}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot z\\ \end{array} \]
Alternative 6
Error36.6
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -2.45 \cdot 10^{+215} \lor \neg \left(z \leq 7.2 \cdot 10^{+175}\right):\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error30.0
Cost320
\[x - y \cdot z \]
Alternative 8
Error38.4
Cost64
\[x \]

Error

Reproduce

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