?

Average Error: 0.2% → 0.19%
Time: 9.6s
Precision: binary64
Cost: 19520

?

\[x \cdot \sin y + z \cdot \cos y \]
\[\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right) \]
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
(FPCore (x y z) :precision binary64 (fma (cos y) z (* (sin y) x)))
double code(double x, double y, double z) {
	return (x * sin(y)) + (z * cos(y));
}
double code(double x, double y, double z) {
	return fma(cos(y), z, (sin(y) * x));
}
function code(x, y, z)
	return Float64(Float64(x * sin(y)) + Float64(z * cos(y)))
end
function code(x, y, z)
	return fma(cos(y), z, Float64(sin(y) * x))
end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
x \cdot \sin y + z \cdot \cos y
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)

Error?

Derivation?

  1. Initial program 0.2

    \[x \cdot \sin y + z \cdot \cos y \]
  2. Simplified0.19

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

    [Start]0.2

    \[ x \cdot \sin y + z \cdot \cos y \]

    fma-def [=>]0.19

    \[ \color{blue}{\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)} \]
  3. Taylor expanded in x around 0 0.2

    \[\leadsto \color{blue}{\cos y \cdot z + \sin y \cdot x} \]
  4. Simplified0.19

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

    [Start]0.2

    \[ \cos y \cdot z + \sin y \cdot x \]

    *-commutative [<=]0.2

    \[ \cos y \cdot z + \color{blue}{x \cdot \sin y} \]

    fma-def [=>]0.19

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

    *-commutative [=>]0.19

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

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

Alternatives

Alternative 1
Error0.2%
Cost13248
\[\sin y \cdot x + \cos y \cdot z \]
Alternative 2
Error15.92%
Cost7250
\[\begin{array}{l} \mathbf{if}\;x \leq -2.95 \cdot 10^{-33} \lor \neg \left(x \leq 1.65 \cdot 10^{-115} \lor \neg \left(x \leq 2.32 \cdot 10^{-29}\right) \land x \leq 6.5 \cdot 10^{+45}\right):\\ \;\;\;\;z + \sin y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot z\\ \end{array} \]
Alternative 3
Error25.51%
Cost7120
\[\begin{array}{l} t_0 := \sin y \cdot x\\ t_1 := \cos y \cdot z\\ \mathbf{if}\;y \leq -8.5 \cdot 10^{+67}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -0.0285:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 0.0052:\\ \;\;\;\;z + y \cdot x\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+146}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error26.44%
Cost6857
\[\begin{array}{l} \mathbf{if}\;y \leq -0.0049 \lor \neg \left(y \leq 8400000000\right):\\ \;\;\;\;\cos y \cdot z\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]
Alternative 5
Error59.4%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+75}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 3.45 \cdot 10^{+177}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 6
Error49.09%
Cost320
\[z + y \cdot x \]
Alternative 7
Error62.16%
Cost64
\[z \]

Error

Reproduce?

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