Average Error: 0.0 → 0.0
Time: 5.5s
Precision: binary64
Cost: 13248
\[\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t \]
\[\mathsf{fma}\left(z, -0.5 \cdot y, \mathsf{fma}\left(0.125, x, t\right)\right) \]
(FPCore (x y z t)
 :precision binary64
 (+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))
(FPCore (x y z t) :precision binary64 (fma z (* -0.5 y) (fma 0.125 x t)))
double code(double x, double y, double z, double t) {
	return (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t;
}
double code(double x, double y, double z, double t) {
	return fma(z, (-0.5 * y), fma(0.125, x, t));
}
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(1.0 / 8.0) * x) - Float64(Float64(y * z) / 2.0)) + t)
end
function code(x, y, z, t)
	return fma(z, Float64(-0.5 * y), fma(0.125, x, t))
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(1.0 / 8.0), $MachinePrecision] * x), $MachinePrecision] - N[(N[(y * z), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := N[(z * N[(-0.5 * y), $MachinePrecision] + N[(0.125 * x + t), $MachinePrecision]), $MachinePrecision]
\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t
\mathsf{fma}\left(z, -0.5 \cdot y, \mathsf{fma}\left(0.125, x, t\right)\right)

Error

Target

Original0.0
Target0.0
Herbie0.0
\[\left(\frac{x}{8} + t\right) - \frac{z}{2} \cdot y \]

Derivation

  1. Initial program 0.0

    \[\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, -0.5 \cdot y, \mathsf{fma}\left(0.125, x, t\right)\right)} \]
    Proof
    (fma.f64 z (*.f64 -1/2 y) (fma.f64 1/8 x t)): 0 points increase in error, 0 points decrease in error
    (fma.f64 z (*.f64 (Rewrite<= metadata-eval (/.f64 -1 2)) y) (fma.f64 1/8 x t)): 0 points increase in error, 0 points decrease in error
    (fma.f64 z (Rewrite<= associate-/r/_binary64 (/.f64 -1 (/.f64 2 y))) (fma.f64 1/8 x t)): 0 points increase in error, 0 points decrease in error
    (fma.f64 z (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 -1 y) 2)) (fma.f64 1/8 x t)): 0 points increase in error, 0 points decrease in error
    (fma.f64 z (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 y 2))) (fma.f64 1/8 x t)): 0 points increase in error, 0 points decrease in error
    (fma.f64 z (*.f64 -1 (/.f64 y 2)) (fma.f64 (Rewrite<= metadata-eval (/.f64 1 8)) x t)): 0 points increase in error, 0 points decrease in error
    (fma.f64 z (*.f64 -1 (/.f64 y 2)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (/.f64 1 8) x) t))): 0 points increase in error, 0 points decrease in error
    (fma.f64 z (*.f64 -1 (/.f64 y 2)) (Rewrite<= +-commutative_binary64 (+.f64 t (*.f64 (/.f64 1 8) x)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (*.f64 -1 (/.f64 y 2))) (+.f64 t (*.f64 (/.f64 1 8) x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 -1 (/.f64 y 2)) z)) (+.f64 t (*.f64 (/.f64 1 8) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 -1 (*.f64 (/.f64 y 2) z))) (+.f64 t (*.f64 (/.f64 1 8) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 -1 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 y z) 2))) (+.f64 t (*.f64 (/.f64 1 8) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (/.f64 (*.f64 y z) 2))) (+.f64 t (*.f64 (/.f64 1 8) x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (neg.f64 (/.f64 (*.f64 y z) 2)) (Rewrite=> +-commutative_binary64 (+.f64 (*.f64 (/.f64 1 8) x) t))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (neg.f64 (/.f64 (*.f64 y z) 2)) (*.f64 (/.f64 1 8) x)) t)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 (/.f64 1 8) x) (neg.f64 (/.f64 (*.f64 y z) 2)))) t): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= sub-neg_binary64 (-.f64 (*.f64 (/.f64 1 8) x) (/.f64 (*.f64 y z) 2))) t): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost6976
\[t + \mathsf{fma}\left(z, -0.5 \cdot y, 0.125 \cdot x\right) \]
Alternative 2
Error8.9
Cost1108
\[\begin{array}{l} t_1 := -0.5 \cdot \left(z \cdot y\right)\\ t_2 := 0.125 \cdot x + t_1\\ t_3 := t + 0.125 \cdot x\\ t_4 := t + t_1\\ \mathbf{if}\;x \leq -8.6 \cdot 10^{+89}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -9.2 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-13}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -4.4 \cdot 10^{-41}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.4 \cdot 10^{+31}:\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error30.2
Cost852
\[\begin{array}{l} t_1 := z \cdot \left(-0.5 \cdot y\right)\\ \mathbf{if}\;t \leq -2.75 \cdot 10^{+42}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq -1.1 \cdot 10^{-162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 5.9 \cdot 10^{-291}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{elif}\;t \leq 1.75 \cdot 10^{-149}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.5 \cdot 10^{+116}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 4
Error20.2
Cost850
\[\begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{+244} \lor \neg \left(y \leq -1.8 \cdot 10^{+220} \lor \neg \left(y \leq -1.5 \cdot 10^{+187}\right) \land y \leq 10^{-47}\right):\\ \;\;\;\;z \cdot \left(-0.5 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + 0.125 \cdot x\\ \end{array} \]
Alternative 5
Error8.3
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{+36} \lor \neg \left(x \leq 4.2 \cdot 10^{+32}\right):\\ \;\;\;\;t + 0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t + -0.5 \cdot \left(z \cdot y\right)\\ \end{array} \]
Alternative 6
Error0.0
Cost704
\[t + \left(0.125 \cdot x - z \cdot \frac{y}{2}\right) \]
Alternative 7
Error28.4
Cost456
\[\begin{array}{l} \mathbf{if}\;t \leq -9.2 \cdot 10^{-8}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 2.05 \cdot 10^{+116}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 8
Error40.3
Cost64
\[t \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y z t)
  :name "Diagrams.Solve.Polynomial:quartForm  from diagrams-solve-0.1, B"
  :precision binary64

  :herbie-target
  (- (+ (/ x 8.0) t) (* (/ z 2.0) y))

  (+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))