Average Error: 0.1 → 0.1
Time: 12.8s
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

    [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, \left(-z\right) \cdot \sin y\right) \]

Alternatives

Alternative 1
Error0.1
Cost13248
\[\cos y \cdot x - z \cdot \sin y \]
Alternative 2
Error16.6
Cost7714
\[\begin{array}{l} t_0 := \cos y \cdot x\\ t_1 := \left(-z\right) \cdot \sin y\\ \mathbf{if}\;y \leq -5.4 \cdot 10^{+212}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -4.4 \cdot 10^{+104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -0.066:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-6}:\\ \;\;\;\;x - y \cdot z\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+100} \lor \neg \left(y \leq 3.7 \cdot 10^{+133} \lor \neg \left(y \leq 1.7 \cdot 10^{+272}\right) \land y \leq 5.5 \cdot 10^{+302}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error8.4
Cost7625
\[\begin{array}{l} \mathbf{if}\;z \leq -1.8 \cdot 10^{+74} \lor \neg \left(z \leq 1.65 \cdot 10^{+47}\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 4
Error10.3
Cost7380
\[\begin{array}{l} t_0 := x - z \cdot \sin y\\ t_1 := \cos y \cdot x\\ \mathbf{if}\;z \leq -1.4 \cdot 10^{-37}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-103}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.8 \cdot 10^{-111}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-198}:\\ \;\;\;\;t_1 - y \cdot z\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error9.9
Cost6985
\[\begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{-39} \lor \neg \left(z \leq 8 \cdot 10^{+46}\right):\\ \;\;\;\;x - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot x\\ \end{array} \]
Alternative 6
Error16.3
Cost6857
\[\begin{array}{l} \mathbf{if}\;y \leq -0.066 \lor \neg \left(y \leq 2.8 \cdot 10^{-6}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot z\\ \end{array} \]
Alternative 7
Error38.0
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -2.6 \cdot 10^{+101} \lor \neg \left(z \leq 1.76 \cdot 10^{+164}\right):\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error31.1
Cost320
\[x - y \cdot z \]
Alternative 9
Error39.4
Cost64
\[x \]

Error

Reproduce

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