Average Error: 0.0 → 0.0
Time: 5.7s
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)): 1 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, 1 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
Error30.8
Cost1380
\[\begin{array}{l} t_1 := -0.5 \cdot \left(z \cdot y\right)\\ \mathbf{if}\;t \leq -4.5 \cdot 10^{+58}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq -2.6 \cdot 10^{-110}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.72 \cdot 10^{-277}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{elif}\;t \leq 4.3 \cdot 10^{-287}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 8.2 \cdot 10^{-51}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{elif}\;t \leq 3.9 \cdot 10^{+55}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.7 \cdot 10^{+99}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{elif}\;t \leq 2.1 \cdot 10^{+144}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{+205}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 3
Error9.4
Cost969
\[\begin{array}{l} \mathbf{if}\;z \cdot y \leq -3.3 \cdot 10^{+147} \lor \neg \left(z \cdot y \leq 4.2 \cdot 10^{+42}\right):\\ \;\;\;\;t + -0.5 \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + 0.125 \cdot x\\ \end{array} \]
Alternative 4
Error9.2
Cost968
\[\begin{array}{l} t_1 := -0.5 \cdot \left(z \cdot y\right)\\ \mathbf{if}\;z \cdot y \leq -8.5 \cdot 10^{+122}:\\ \;\;\;\;0.125 \cdot x + t_1\\ \mathbf{elif}\;z \cdot y \leq 3 \cdot 10^{+41}:\\ \;\;\;\;t + 0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t + t_1\\ \end{array} \]
Alternative 5
Error11.8
Cost841
\[\begin{array}{l} \mathbf{if}\;z \cdot y \leq -1.4 \cdot 10^{+148} \lor \neg \left(z \cdot y \leq 6.2 \cdot 10^{+97}\right):\\ \;\;\;\;-0.5 \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + 0.125 \cdot x\\ \end{array} \]
Alternative 6
Error30.6
Cost720
\[\begin{array}{l} \mathbf{if}\;t \leq -9.8 \cdot 10^{-93}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 2.2 \cdot 10^{+100}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{elif}\;t \leq 2.1 \cdot 10^{+144}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{+205}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 7
Error0.0
Cost704
\[t + \left(0.125 \cdot x - z \cdot \frac{y}{2}\right) \]
Alternative 8
Error39.9
Cost64
\[t \]

Error

Reproduce

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