Average Error: 0.1 → 0.1
Time: 12.7s
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.1

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)} \]
    Proof
    (fma.f64 (cos.f64 y) z (*.f64 (sin.f64 y) x)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (cos.f64 y) z) (*.f64 (sin.f64 y) x))): 1 points increase in error, 0 points decrease in error
  4. Final simplification0.1

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

Alternatives

Alternative 1
Error9.0
Cost13256
\[\begin{array}{l} t_0 := \cos y \cdot z\\ \mathbf{if}\;z \leq -1.0534156578752266 \cdot 10^{+85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.6296287302526506 \cdot 10^{-145}:\\ \;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\ \mathbf{elif}\;z \leq 3.300257962750949 \cdot 10^{-115}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.4244920644270548 \cdot 10^{+91}:\\ \;\;\;\;z + \sin y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.1
Cost13248
\[\sin y \cdot x + \cos y \cdot z \]
Alternative 3
Error17.7
Cost7384
\[\begin{array}{l} t_0 := \cos y \cdot z\\ t_1 := \sin y \cdot x\\ \mathbf{if}\;z \leq -1.0534156578752266 \cdot 10^{+85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -0.0006250749902912553:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.2450670409105932 \cdot 10^{-118}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.6296287302526506 \cdot 10^{-145}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.300257962750949 \cdot 10^{-115}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.127550276082568 \cdot 10^{-66}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error9.0
Cost7248
\[\begin{array}{l} t_0 := \cos y \cdot z\\ t_1 := z + \sin y \cdot x\\ \mathbf{if}\;z \leq -1.0534156578752266 \cdot 10^{+85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.6296287302526506 \cdot 10^{-145}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.300257962750949 \cdot 10^{-115}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.4244920644270548 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error16.1
Cost6856
\[\begin{array}{l} t_0 := \sin y \cdot x\\ \mathbf{if}\;y \leq -4.773562577435384 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.9709589350215084 \cdot 10^{-6}:\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error16.1
Cost6856
\[\begin{array}{l} t_0 := \sin y \cdot x\\ \mathbf{if}\;y \leq -4.773562577435384 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.9709589350215084 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error37.5
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -4.7191401098301497 \cdot 10^{+129}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 5.656141293262609 \cdot 10^{+127}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 8
Error30.4
Cost320
\[z + y \cdot x \]
Alternative 9
Error38.8
Cost64
\[z \]

Error

Reproduce

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