Average Error: 0.1 → 0.0
Time: 6.6s
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, 0 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, 2 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)))): 36 points increase in error, 0 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)))))): 1 points increase in error, 1 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)))))): 5 points increase in error, 1 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))): 4 points increase in error, 38 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error31.8
Cost1508
\[\begin{array}{l} t_0 := -4 \cdot \frac{z}{y}\\ t_1 := 4 \cdot \frac{x}{y}\\ \mathbf{if}\;x \leq -1.4959794045287318 \cdot 10^{+105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.4681720016314225 \cdot 10^{-92}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq -7.750173744281532 \cdot 10^{-199}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3072358521577175 \cdot 10^{-166}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 6.223394143289802 \cdot 10^{-139}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.0658758913738793 \cdot 10^{-15}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 7.8906902107839725 \cdot 10^{+31}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.8 \cdot 10^{+175}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error31.1
Cost1508
\[\begin{array}{l} t_0 := 1 + z \cdot \frac{-4}{y}\\ t_1 := 4 \cdot \frac{x}{y}\\ \mathbf{if}\;x \leq -1.4959794045287318 \cdot 10^{+105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.4681720016314225 \cdot 10^{-92}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq -1.7452995820544977 \cdot 10^{-225}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3072358521577175 \cdot 10^{-166}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 6.223394143289802 \cdot 10^{-139}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.0658758913738793 \cdot 10^{-15}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 7.8906902107839725 \cdot 10^{+31}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.8 \cdot 10^{+175}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error13.2
Cost1504
\[\begin{array}{l} t_0 := 2 + -4 \cdot \frac{z}{y}\\ t_1 := 2 + 4 \cdot \frac{x}{y}\\ t_2 := 4 \cdot \frac{x - z}{y}\\ \mathbf{if}\;y \leq -3.9913364410382756 \cdot 10^{+98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -8.045502531107272 \cdot 10^{-8}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.5 \cdot 10^{-55}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{-100}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.607746740903345 \cdot 10^{+42}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 3.609789188594275 \cdot 10^{+59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.0684095434469317 \cdot 10^{+123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 4.343291097166859 \cdot 10^{+167}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error17.1
Cost976
\[\begin{array}{l} t_0 := 4 \cdot \frac{x - z}{y}\\ \mathbf{if}\;y \leq -8.343911445290791 \cdot 10^{+141}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq 1.0684095434469317 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.6382168105034965 \cdot 10^{+162}:\\ \;\;\;\;2\\ \mathbf{elif}\;y \leq 1.1273240255917176 \cdot 10^{+211}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]
Alternative 5
Error12.9
Cost976
\[\begin{array}{l} t_0 := 2 + 4 \cdot \frac{x}{y}\\ t_1 := 4 \cdot \frac{x - z}{y}\\ \mathbf{if}\;z \leq -2.3215100153730616 \cdot 10^{+27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.173309821691398 \cdot 10^{-59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.069351854844009 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.24678093690221 \cdot 10^{+101}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error31.1
Cost848
\[\begin{array}{l} t_0 := -4 \cdot \frac{z}{y}\\ \mathbf{if}\;z \leq -2.3215100153730616 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.173309821691398 \cdot 10^{-59}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 6.069351854844009 \cdot 10^{+43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.543312130482361 \cdot 10^{+104}:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.1
Cost832
\[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
Alternative 8
Error36.9
Cost64
\[2 \]

Error

Reproduce

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