Average Error: 0.1 → 0
Time: 4.4s
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. Taylor expanded in x around 0 0.1

    \[\leadsto \color{blue}{-0.5 \cdot y + 1.5 \cdot x} \]
  3. 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))): 18 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (Rewrite<= metadata-eval (+.f64 1/2 1)) x) (*.f64 -1/2 y)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-lft1-in_binary64 (+.f64 (*.f64 1/2 x) x)) (*.f64 -1/2 y)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1/2 y) (+.f64 (*.f64 1/2 x) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 -1/2 y) (Rewrite=> distribute-lft1-in_binary64 (*.f64 (+.f64 1/2 1) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 -1/2 y) (*.f64 (Rewrite=> metadata-eval 3/2) x)): 0 points increase in error, 0 points decrease in error
  4. Final simplification0

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

Alternatives

Alternative 1
Error16.8
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -4.554913430096951 \cdot 10^{-13}:\\ \;\;\;\;-0.5 \cdot y\\ \mathbf{elif}\;y \leq 4.648570085008161 \cdot 10^{-24}:\\ \;\;\;\;1.5 \cdot x\\ \mathbf{elif}\;y \leq 14421863947182.963:\\ \;\;\;\;-0.5 \cdot y\\ \mathbf{elif}\;y \leq 2.865447946667378 \cdot 10^{+83}:\\ \;\;\;\;1.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot y\\ \end{array} \]
Alternative 2
Error0.1
Cost448
\[-0.5 \cdot y + 1.5 \cdot x \]
Alternative 3
Error31.8
Cost192
\[1.5 \cdot x \]

Error

Reproduce

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