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

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

    \[\leadsto \color{blue}{-0.5 \cdot y + 1.5 \cdot x} \]
  4. Simplified0

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

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

Alternatives

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

Error

Reproduce

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