?

Average Error: 0.02% → 0%
Time: 7.1s
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.02%
Target0.01%
Herbie0%
\[\left(\frac{x}{8} + t\right) - \frac{z}{2} \cdot y \]

Derivation?

  1. Initial program 0.02

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

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

    [Start]0.02

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

    sub-neg [=>]0.02

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

    +-commutative [=>]0.02

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

    associate-+l+ [=>]0.02

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

    neg-mul-1 [=>]0.02

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

    associate-*l/ [<=]0.01

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

    associate-*r* [=>]0.01

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

    *-commutative [=>]0.01

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

    +-commutative [<=]0.01

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

    fma-def [=>]0

    \[ \color{blue}{\mathsf{fma}\left(z, -1 \cdot \frac{y}{2}, t + \frac{1}{8} \cdot x\right)} \]

    associate-*r/ [=>]0

    \[ \mathsf{fma}\left(z, \color{blue}{\frac{-1 \cdot y}{2}}, t + \frac{1}{8} \cdot x\right) \]

    associate-/l* [=>]0.06

    \[ \mathsf{fma}\left(z, \color{blue}{\frac{-1}{\frac{2}{y}}}, t + \frac{1}{8} \cdot x\right) \]

    associate-/r/ [=>]0

    \[ \mathsf{fma}\left(z, \color{blue}{\frac{-1}{2} \cdot y}, t + \frac{1}{8} \cdot x\right) \]

    metadata-eval [=>]0

    \[ \mathsf{fma}\left(z, \color{blue}{-0.5} \cdot y, t + \frac{1}{8} \cdot x\right) \]

    +-commutative [=>]0

    \[ \mathsf{fma}\left(z, -0.5 \cdot y, \color{blue}{\frac{1}{8} \cdot x + t}\right) \]

    fma-def [=>]0

    \[ \mathsf{fma}\left(z, -0.5 \cdot y, \color{blue}{\mathsf{fma}\left(\frac{1}{8}, x, t\right)}\right) \]

    metadata-eval [=>]0

    \[ \mathsf{fma}\left(z, -0.5 \cdot y, \mathsf{fma}\left(\color{blue}{0.125}, x, t\right)\right) \]
  3. Final simplification0

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

Alternatives

Alternative 1
Error0.01%
Cost7040
\[0.125 \cdot x - \mathsf{fma}\left(y \cdot 0.5, z, -t\right) \]
Alternative 2
Error22.83%
Cost1500
\[\begin{array}{l} t_1 := t + 0.125 \cdot x\\ t_2 := -0.5 \cdot \left(z \cdot y\right)\\ t_3 := t + t_2\\ \mathbf{if}\;z \leq -4 \cdot 10^{-42}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 8 \cdot 10^{-70}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-13}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.42 \cdot 10^{+113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.18 \cdot 10^{+126}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+150}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{+181}:\\ \;\;\;\;0.125 \cdot x + t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error23.59%
Cost1243
\[\begin{array}{l} \mathbf{if}\;z \leq -3.3 \cdot 10^{-44} \lor \neg \left(z \leq 1.12 \cdot 10^{-69}\right) \land \left(z \leq 1.02 \cdot 10^{-12} \lor \neg \left(z \leq 2 \cdot 10^{+112}\right) \land \left(z \leq 1.65 \cdot 10^{+126} \lor \neg \left(z \leq 2.05 \cdot 10^{+194}\right)\right)\right):\\ \;\;\;\;t + -0.5 \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + 0.125 \cdot x\\ \end{array} \]
Alternative 4
Error47.14%
Cost1116
\[\begin{array}{l} \mathbf{if}\;t \leq -3.5 \cdot 10^{+83}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq -370000000:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{elif}\;t \leq -4.1 \cdot 10^{-47}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq -7 \cdot 10^{-181}:\\ \;\;\;\;-0.5 \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;t \leq 45:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{elif}\;t \leq 1.8 \cdot 10^{+50}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 9 \cdot 10^{+150}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 5
Error46.5%
Cost984
\[\begin{array}{l} \mathbf{if}\;t \leq -1.05 \cdot 10^{+83}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq -30000000:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{elif}\;t \leq -5.5 \cdot 10^{-60}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 1950000:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{elif}\;t \leq 5 \cdot 10^{+51}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 9 \cdot 10^{+150}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 6
Error18.73%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \cdot y \leq -5.5 \cdot 10^{+107} \lor \neg \left(z \cdot y \leq 7.2 \cdot 10^{+143}\right):\\ \;\;\;\;-0.5 \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + 0.125 \cdot x\\ \end{array} \]
Alternative 7
Error0.01%
Cost704
\[t + \left(0.125 \cdot x - z \cdot \frac{y}{2}\right) \]
Alternative 8
Error62.62%
Cost64
\[t \]

Error

Reproduce?

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