Average Error: 5.7 → 0.2
Time: 3.2s
Precision: binary64
\[\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3} \]
\[\left(1 - x\right) \cdot \frac{\mathsf{fma}\left(-0.3333333333333333, x, 1\right)}{y} \]
(FPCore (x y) :precision binary64 (/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))
(FPCore (x y)
 :precision binary64
 (* (- 1.0 x) (/ (fma -0.3333333333333333 x 1.0) y)))
double code(double x, double y) {
	return ((1.0 - x) * (3.0 - x)) / (y * 3.0);
}
double code(double x, double y) {
	return (1.0 - x) * (fma(-0.3333333333333333, x, 1.0) / y);
}
function code(x, y)
	return Float64(Float64(Float64(1.0 - x) * Float64(3.0 - x)) / Float64(y * 3.0))
end
function code(x, y)
	return Float64(Float64(1.0 - x) * Float64(fma(-0.3333333333333333, x, 1.0) / y))
end
code[x_, y_] := N[(N[(N[(1.0 - x), $MachinePrecision] * N[(3.0 - x), $MachinePrecision]), $MachinePrecision] / N[(y * 3.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] * N[(N[(-0.3333333333333333 * x + 1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3}
\left(1 - x\right) \cdot \frac{\mathsf{fma}\left(-0.3333333333333333, x, 1\right)}{y}

Error

Target

Original5.7
Target0.1
Herbie0.2
\[\frac{1 - x}{y} \cdot \frac{3 - x}{3} \]

Derivation

  1. Initial program 5.7

    \[\frac{\left(1 - x\right) \cdot \left(3 - x\right)}{y \cdot 3} \]
  2. Simplified0.4

    \[\leadsto \color{blue}{\left(1 - x\right) \cdot \left(\left(3 - x\right) \cdot \frac{0.3333333333333333}{y}\right)} \]
  3. Taylor expanded in x around 0 0.2

    \[\leadsto \left(1 - x\right) \cdot \color{blue}{\left(-0.3333333333333333 \cdot \frac{x}{y} + \frac{1}{y}\right)} \]
  4. Simplified0.2

    \[\leadsto \left(1 - x\right) \cdot \color{blue}{\frac{\mathsf{fma}\left(-0.3333333333333333, x, 1\right)}{y}} \]
  5. Final simplification0.2

    \[\leadsto \left(1 - x\right) \cdot \frac{\mathsf{fma}\left(-0.3333333333333333, x, 1\right)}{y} \]

Reproduce

herbie shell --seed 2022211 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:bezierFromSweepQ1 from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (* (/ (- 1.0 x) y) (/ (- 3.0 x) 3.0))

  (/ (* (- 1.0 x) (- 3.0 x)) (* y 3.0)))