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

Error

Derivation

  1. Initial program 0.2

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{4}{y}, x - z, 4\right)} \]
    Proof
    (fma.f64 (/.f64 4 y) (-.f64 x z) 4): 0 points increase in error, 0 points decrease in error
    (fma.f64 (/.f64 4 y) (Rewrite<= unsub-neg_binary64 (+.f64 x (neg.f64 z))) 4): 0 points increase in error, 0 points decrease in error
    (Rewrite=> fma-udef_binary64 (+.f64 (*.f64 (/.f64 4 y) (+.f64 x (neg.f64 z))) 4)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y))) 4): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 4 (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= metadata-eval (+.f64 3 1)) (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= metadata-eval (*.f64 4 3/4)) 1) (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 (Rewrite<= metadata-eval (/.f64 4 1)) 3/4) 1) (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 (/.f64 4 (Rewrite<= *-inverses_binary64 (/.f64 y y))) 3/4) 1) (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 4 y) y)) 3/4) 1) (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y))): 2 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 4 y) y)) 3/4) 1) (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y))): 12 points increase in error, 2 points decrease in error
    (+.f64 (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 (/.f64 4 y) (*.f64 y 3/4))) 1) (*.f64 (+.f64 x (neg.f64 z)) (/.f64 4 y))): 13 points increase in error, 5 points decrease in error
    (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 1 (*.f64 (/.f64 4 y) (*.f64 y 3/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 3/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 3/4)) (*.f64 (/.f64 4 y) (+.f64 x (neg.f64 z)))))): 0 points increase in error, 1 points decrease in error
    (+.f64 1 (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 4 y) (+.f64 (*.f64 y 3/4) (+.f64 x (neg.f64 z)))))): 3 points increase in error, 1 points decrease in error
    (+.f64 1 (*.f64 (/.f64 4 y) (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 y 3/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 3/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 3/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 3/4)) z)) y))): 10 points increase in error, 49 points decrease in error
  3. Final simplification0.2

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

Alternatives

Alternative 1
Error31.8
Cost1640
\[\begin{array}{l} t_0 := -4 \cdot \frac{z}{y}\\ t_1 := \frac{4 \cdot x}{y}\\ \mathbf{if}\;x \leq -1.4959794045287318 \cdot 10^{+105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.4681720016314225 \cdot 10^{-92}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq -7.750173744281532 \cdot 10^{-199}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3072358521577175 \cdot 10^{-166}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 6.223394143289802 \cdot 10^{-139}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.0658758913738793 \cdot 10^{-15}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 2.561313660371476 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 7.707471917694893 \cdot 10^{+26}:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{+134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.8 \cdot 10^{+175}:\\ \;\;\;\;4\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error13.2
Cost1504
\[\begin{array}{l} t_0 := 4 + -4 \cdot \frac{z}{y}\\ t_1 := 4 + 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 3
Error17.1
Cost976
\[\begin{array}{l} t_0 := 4 \cdot \frac{x - z}{y}\\ \mathbf{if}\;y \leq -8.343911445290791 \cdot 10^{+141}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 1.0684095434469317 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.6382168105034965 \cdot 10^{+162}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 1.1273240255917176 \cdot 10^{+211}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
Alternative 4
Error12.9
Cost976
\[\begin{array}{l} t_0 := 4 + 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 5
Error31.1
Cost848
\[\begin{array}{l} t_0 := z \cdot \frac{-4}{y}\\ \mathbf{if}\;z \leq -2.3215100153730616 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.173309821691398 \cdot 10^{-59}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 6.069351854844009 \cdot 10^{+43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.543312130482361 \cdot 10^{+104}:\\ \;\;\;\;4\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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}:\\ \;\;\;\;4\\ \mathbf{elif}\;z \leq 6.069351854844009 \cdot 10^{+43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.543312130482361 \cdot 10^{+104}:\\ \;\;\;\;4\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.2
Cost832
\[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
Alternative 8
Error36.8
Cost64
\[4 \]

Error

Reproduce

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