Average Error: 0.1 → 0.1
Time: 9.8s
Precision: binary64
Cost: 19520
\[x \cdot \sin y + z \cdot \cos y \]
\[\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right) \]
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
(FPCore (x y z) :precision binary64 (fma x (sin y) (* z (cos y))))
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(x, sin(y), (z * cos(y)));
}
function code(x, y, z)
	return Float64(Float64(x * sin(y)) + Float64(z * cos(y)))
end
function code(x, y, z)
	return fma(x, sin(y), Float64(z * cos(y)))
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[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x \cdot \sin y + z \cdot \cos y
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)

Error

Derivation

  1. Initial program 0.1

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

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

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

Alternatives

Alternative 1
Error0.1
Cost19520
\[\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right) \]
Alternative 2
Error0.1
Cost13248
\[x \cdot \sin y + z \cdot \cos y \]
Alternative 3
Error16.6
Cost7384
\[\begin{array}{l} t_0 := x \cdot \sin y\\ t_1 := z \cdot \cos y\\ \mathbf{if}\;y \leq -7.47855548357234 \cdot 10^{+139}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.0334180033719905 \cdot 10^{+58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.8631468672212416 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -3.511397279149462:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.236350086383115 \cdot 10^{-18}:\\ \;\;\;\;\left(z \cdot \left(y \cdot y\right)\right) \cdot -0.5 + \left(z + x \cdot y\right)\\ \mathbf{elif}\;y \leq 3.0838474813585634 \cdot 10^{+193}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error10.0
Cost7248
\[\begin{array}{l} t_0 := z \cdot \cos y\\ t_1 := z + x \cdot \sin y\\ \mathbf{if}\;z \leq -1.1041014529716775 \cdot 10^{+25}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.384120464137304 \cdot 10^{-170}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.6218222859138105 \cdot 10^{-133}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 87716725260.12997:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error16.7
Cost6856
\[\begin{array}{l} t_0 := x \cdot \sin y\\ \mathbf{if}\;y \leq -196821.13922514336:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.236350086383115 \cdot 10^{-18}:\\ \;\;\;\;\left(z \cdot \left(y \cdot y\right)\right) \cdot -0.5 + \left(z + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error38.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.953974486164688 \cdot 10^{+88}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 3.609989251816531 \cdot 10^{+78}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 7
Error30.8
Cost320
\[z + x \cdot y \]
Alternative 8
Error39.2
Cost64
\[z \]

Error

Reproduce

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