Average Error: 0.1 → 0.0
Time: 12.9s
Precision: binary64
Cost: 6848
\[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
\[\mathsf{fma}\left(4, \frac{x - z}{y}, 2\right) \]
(FPCore (x y z)
 :precision binary64
 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))
(FPCore (x y z) :precision binary64 (fma 4.0 (/ (- x z) y) 2.0))
double code(double x, double y, double z) {
	return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
double code(double x, double y, double z) {
	return fma(4.0, ((x - z) / y), 2.0);
}
function code(x, y, z)
	return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.25)) - z)) / y))
end
function code(x, y, z)
	return fma(4.0, Float64(Float64(x - z) / y), 2.0)
end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.25), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision] + 2.0), $MachinePrecision]
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y}
\mathsf{fma}\left(4, \frac{x - z}{y}, 2\right)

Error

Derivation

  1. Initial program 0.1

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(4, \frac{x - z}{y}, 2\right)} \]
    Proof
    (fma.f64 4 (/.f64 (-.f64 x z) y) 2): 0 points increase in error, 0 points decrease in error
    (fma.f64 4 (/.f64 (Rewrite<= unsub-neg_binary64 (+.f64 x (neg.f64 z))) y) 2): 0 points increase in error, 0 points decrease in error
    (fma.f64 4 (/.f64 (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 z) x)) y) 2): 0 points increase in error, 0 points decrease in error
    (fma.f64 4 (/.f64 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 z)) x) y) 2): 0 points increase in error, 0 points decrease in error
    (fma.f64 4 (/.f64 (Rewrite=> associate-+l-_binary64 (-.f64 0 (-.f64 z x))) y) 2): 0 points increase in error, 0 points decrease in error
    (fma.f64 4 (/.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 z x))) y) 2): 0 points increase in error, 0 points decrease in error
    (fma.f64 4 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 (-.f64 z x) y))) 2): 0 points increase in error, 0 points decrease in error
    (fma.f64 4 (neg.f64 (/.f64 (-.f64 z x) y)) (Rewrite<= metadata-eval (+.f64 1 1))): 0 points increase in error, 0 points decrease in error
    (fma.f64 4 (neg.f64 (/.f64 (-.f64 z x) y)) (+.f64 1 (Rewrite<= lft-mult-inverse_binary64 (*.f64 (/.f64 1 y) y)))): 2 points increase in error, 0 points decrease in error
    (fma.f64 4 (neg.f64 (/.f64 (-.f64 z x) y)) (+.f64 1 (*.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 4 1/4)) y) y))): 0 points increase in error, 0 points decrease in error
    (fma.f64 4 (neg.f64 (/.f64 (-.f64 z x) y)) (+.f64 1 (*.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 4 y) 1/4)) y))): 0 points increase in error, 2 points decrease in error
    (fma.f64 4 (neg.f64 (/.f64 (-.f64 z x) y)) (+.f64 1 (Rewrite=> associate-*l*_binary64 (*.f64 (/.f64 4 y) (*.f64 1/4 y))))): 0 points increase in error, 1 points decrease in error
    (fma.f64 4 (neg.f64 (/.f64 (-.f64 z x) y)) (+.f64 1 (*.f64 (/.f64 4 y) (Rewrite<= *-commutative_binary64 (*.f64 y 1/4))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 4 (neg.f64 (/.f64 (-.f64 z x) y))) (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 4 (Rewrite=> distribute-neg-frac_binary64 (/.f64 (neg.f64 (-.f64 z x)) y))) (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 4 (/.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 (-.f64 z x))) y)) (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 4 (/.f64 (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 z) x)) y)) (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 4 (/.f64 (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 z)) x) y)) (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 4 (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (neg.f64 z))) y)) (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 4 (+.f64 x (neg.f64 z))) y)) (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 4 y) (+.f64 x (neg.f64 z)))) (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4)))): 39 points increase in error, 2 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y))) (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4))) (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 1/4))) (Rewrite=> *-commutative_binary64 (*.f64 (/.f64 4 y) (+.f64 x (neg.f64 z))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 1 (+.f64 (*.f64 (/.f64 4 y) (*.f64 y 1/4)) (*.f64 (/.f64 4 y) (+.f64 x (neg.f64 z)))))): 4 points increase in error, 0 points decrease in error
    (+.f64 1 (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 4 y) (+.f64 (*.f64 y 1/4) (+.f64 x (neg.f64 z)))))): 2 points increase in error, 2 points decrease in error
    (+.f64 1 (*.f64 (/.f64 4 y) (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 y 1/4) x) (neg.f64 z))))): 0 points increase in error, 0 points decrease in error
    (+.f64 1 (*.f64 (/.f64 4 y) (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y 1/4))) (neg.f64 z)))): 0 points increase in error, 0 points decrease in error
    (+.f64 1 (*.f64 (/.f64 4 y) (Rewrite<= sub-neg_binary64 (-.f64 (+.f64 x (*.f64 y 1/4)) z)))): 0 points increase in error, 0 points decrease in error
    (+.f64 1 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 4 (-.f64 (+.f64 x (*.f64 y 1/4)) z)) y))): 1 points increase in error, 40 points decrease in error
  3. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(4, \frac{x - z}{y}, 2\right) \]

Alternatives

Alternative 1
Error30.9
Cost1244
\[\begin{array}{l} t_0 := \frac{4}{\frac{y}{x}}\\ t_1 := \frac{-4}{\frac{y}{z}}\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+118}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.698167023026617 \cdot 10^{-297}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 6.871744156316401 \cdot 10^{-250}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 151526.55504133544:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 1.4595013669838024 \cdot 10^{+50}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+159}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+196}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error30.9
Cost1244
\[\begin{array}{l} t_0 := \frac{4}{\frac{y}{x}}\\ t_1 := -4 \cdot \frac{z}{y}\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+118}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.698167023026617 \cdot 10^{-297}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 6.871744156316401 \cdot 10^{-250}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 151526.55504133544:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 1.4595013669838024 \cdot 10^{+50}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+159}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+196}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error30.9
Cost1244
\[\begin{array}{l} t_0 := 4 \cdot \frac{x}{y}\\ t_1 := -4 \cdot \frac{z}{y}\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+118}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.698167023026617 \cdot 10^{-297}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 6.871744156316401 \cdot 10^{-250}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 151526.55504133544:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 1.4595013669838024 \cdot 10^{+50}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+159}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+196}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error14.0
Cost976
\[\begin{array}{l} t_0 := -4 \cdot \frac{z}{y}\\ t_1 := 2 + x \cdot \frac{4}{y}\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+118}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+196}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error12.4
Cost976
\[\begin{array}{l} t_0 := 2 + x \cdot \frac{4}{y}\\ t_1 := \frac{-4}{y} \cdot \left(z - x\right)\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+118}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.088932561440322 \cdot 10^{-11}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+159}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+196}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error12.3
Cost976
\[\begin{array}{l} t_0 := \frac{-4}{y} \cdot \left(z - x\right)\\ \mathbf{if}\;z \leq -3.1 \cdot 10^{+118}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.088932561440322 \cdot 10^{-11}:\\ \;\;\;\;2 + 4 \cdot \frac{x}{y}\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+159}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{+196}:\\ \;\;\;\;2 + x \cdot \frac{4}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error10.2
Cost976
\[\begin{array}{l} t_0 := 2 + -4 \cdot \frac{z}{y}\\ t_1 := \frac{-4}{y} \cdot \left(z - x\right)\\ \mathbf{if}\;x \leq -1.230591218195955 \cdot 10^{-39}:\\ \;\;\;\;2 + 4 \cdot \frac{x}{y}\\ \mathbf{elif}\;x \leq 30730905.084224764:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.253271266196283 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+128}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error10.2
Cost976
\[\begin{array}{l} t_0 := 2 + -4 \cdot \frac{z}{y}\\ t_1 := 4 \cdot \frac{x - z}{y}\\ \mathbf{if}\;x \leq -1.230591218195955 \cdot 10^{-39}:\\ \;\;\;\;2 + 4 \cdot \frac{x}{y}\\ \mathbf{elif}\;x \leq 30730905.084224764:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.253271266196283 \cdot 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+128}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error0.1
Cost832
\[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
Alternative 10
Error30.8
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -4.7 \cdot 10^{-39}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq 5.4230047677309 \cdot 10^{+96}:\\ \;\;\;\;\frac{4}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]
Alternative 11
Error36.9
Cost64
\[2 \]

Error

Reproduce

herbie shell --seed 2022290 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, C"
  :precision binary64
  (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))