Average Error: 0.1 → 0
Time: 4.3s
Precision: binary64
Cost: 6720
\[x + \frac{x - y}{2} \]
\[\mathsf{fma}\left(x, 1.5, y \cdot -0.5\right) \]
(FPCore (x y) :precision binary64 (+ x (/ (- x y) 2.0)))
(FPCore (x y) :precision binary64 (fma x 1.5 (* y -0.5)))
double code(double x, double y) {
	return x + ((x - y) / 2.0);
}
double code(double x, double y) {
	return fma(x, 1.5, (y * -0.5));
}
function code(x, y)
	return Float64(x + Float64(Float64(x - y) / 2.0))
end
function code(x, y)
	return fma(x, 1.5, Float64(y * -0.5))
end
code[x_, y_] := N[(x + N[(N[(x - y), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(x * 1.5 + N[(y * -0.5), $MachinePrecision]), $MachinePrecision]
x + \frac{x - y}{2}
\mathsf{fma}\left(x, 1.5, y \cdot -0.5\right)

Error

Target

Original0.1
Target0.1
Herbie0
\[1.5 \cdot x - 0.5 \cdot y \]

Derivation

  1. Initial program 0.1

    \[x + \frac{x - y}{2} \]
  2. Simplified0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 1.5, y \cdot -0.5\right)} \]
    Proof
    (fma.f64 x 3/2 (*.f64 y -1/2)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= metadata-eval (+.f64 1 1/2)) (*.f64 y -1/2)): 0 points increase in error, 19 points decrease in error
    (fma.f64 x (+.f64 (Rewrite<= metadata-eval (neg.f64 -1)) 1/2) (*.f64 y -1/2)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 (neg.f64 -1) (Rewrite<= metadata-eval (/.f64 1 2))) (*.f64 y -1/2)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 (neg.f64 -1) (/.f64 (Rewrite<= metadata-eval (neg.f64 -1)) 2)) (*.f64 y -1/2)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 (neg.f64 -1) (/.f64 (neg.f64 -1) 2)) (*.f64 y (Rewrite<= metadata-eval (/.f64 -1 2)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 (neg.f64 -1) (/.f64 (neg.f64 -1) 2)) (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 -1 2) y))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 (neg.f64 -1) (/.f64 (neg.f64 -1) 2)) (Rewrite<= associate-/r/_binary64 (/.f64 -1 (/.f64 2 y)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 (neg.f64 -1) (/.f64 (neg.f64 -1) 2)) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 -1 y) 2))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 (neg.f64 -1) (/.f64 (neg.f64 -1) 2)) (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 y)) 2)): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 (neg.f64 -1) (/.f64 (neg.f64 -1) 2)) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 y 2)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x (+.f64 (neg.f64 -1) (/.f64 (neg.f64 -1) 2))) (/.f64 y 2))): 18 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (neg.f64 -1) x) (*.f64 (/.f64 (neg.f64 -1) 2) x))) (/.f64 y 2)): 0 points increase in error, 18 points decrease in error
    (-.f64 (+.f64 (*.f64 (Rewrite=> metadata-eval 1) x) (*.f64 (/.f64 (neg.f64 -1) 2) x)) (/.f64 y 2)): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 (Rewrite=> *-lft-identity_binary64 x) (*.f64 (/.f64 (neg.f64 -1) 2) x)) (/.f64 y 2)): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 x (Rewrite<= associate-/r/_binary64 (/.f64 (neg.f64 -1) (/.f64 2 x)))) (/.f64 y 2)): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (neg.f64 -1) x) 2))) (/.f64 y 2)): 19 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 x (/.f64 (*.f64 (Rewrite=> metadata-eval 1) x) 2)) (/.f64 y 2)): 0 points increase in error, 19 points decrease in error
    (-.f64 (+.f64 x (/.f64 (Rewrite=> *-lft-identity_binary64 x) 2)) (/.f64 y 2)): 19 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= --rgt-identity_binary64 (-.f64 (+.f64 x (/.f64 x 2)) 0)) (/.f64 y 2)): 0 points increase in error, 19 points decrease in error
    (-.f64 (Rewrite=> associate--l+_binary64 (+.f64 x (-.f64 (/.f64 x 2) 0))) (/.f64 y 2)): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 (-.f64 (/.f64 x 2) 0) x)) (/.f64 y 2)): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= associate--r-_binary64 (-.f64 (/.f64 x 2) (-.f64 0 x))) (/.f64 y 2)): 0 points increase in error, 0 points decrease in error
    (-.f64 (-.f64 (/.f64 x 2) (Rewrite<= neg-sub0_binary64 (neg.f64 x))) (/.f64 y 2)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate--r+_binary64 (-.f64 (/.f64 x 2) (+.f64 (neg.f64 x) (/.f64 y 2)))): 0 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x 2) (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 y 2) (neg.f64 x)))): 19 points increase in error, 0 points decrease in error
    (-.f64 (/.f64 x 2) (Rewrite<= sub-neg_binary64 (-.f64 (/.f64 y 2) x))): 1 points increase in error, 19 points decrease in error
    (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 (/.f64 x 2) (/.f64 y 2)) x)): 0 points increase in error, 1 points decrease in error
    (+.f64 (Rewrite<= div-sub_binary64 (/.f64 (-.f64 x y) 2)) x): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (-.f64 x y) 2))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0

    \[\leadsto \mathsf{fma}\left(x, 1.5, y \cdot -0.5\right) \]

Alternatives

Alternative 1
Error16.5
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.5 \cdot 10^{+45}:\\ \;\;\;\;x \cdot 1.5\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-35}:\\ \;\;\;\;y \cdot -0.5\\ \mathbf{else}:\\ \;\;\;\;x \cdot 1.5\\ \end{array} \]
Alternative 2
Error0.1
Cost448
\[x + \frac{x - y}{2} \]
Alternative 3
Error31.3
Cost192
\[y \cdot -0.5 \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y)
  :name "Graphics.Rendering.Chart.Axis.Types:hBufferRect from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (- (* 1.5 x) (* 0.5 y))

  (+ x (/ (- x y) 2.0)))