Average Error: 0.2 → 0.1
Time: 6.6s
Precision: binary64
Cost: 7232
\[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
\[1 + \mathsf{fma}\left(-4, \frac{z}{y}, \frac{4}{\frac{y}{x}} + 3\right) \]
(FPCore (x y z)
 :precision binary64
 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
(FPCore (x y z)
 :precision binary64
 (+ 1.0 (fma -4.0 (/ z y) (+ (/ 4.0 (/ y x)) 3.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 1.0 + fma(-4.0, (z / y), ((4.0 / (y / x)) + 3.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 Float64(1.0 + fma(-4.0, Float64(z / y), Float64(Float64(4.0 / Float64(y / x)) + 3.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[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision] + N[(N[(4.0 / N[(y / x), $MachinePrecision]), $MachinePrecision] + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
1 + \mathsf{fma}\left(-4, \frac{z}{y}, \frac{4}{\frac{y}{x}} + 3\right)

Error

Derivation

  1. Initial program 0.2

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
  2. Taylor expanded in z around inf 0.0

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

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

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

Alternatives

Alternative 1
Error30.1
Cost716
\[\begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+115}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 1.32 \cdot 10^{-221}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 5 \cdot 10^{+95}:\\ \;\;\;\;\frac{-4}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
Alternative 2
Error30.1
Cost716
\[\begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+115}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-206}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+96}:\\ \;\;\;\;\frac{z}{\frac{y}{-4}}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
Alternative 3
Error12.2
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -5.3 \cdot 10^{+115} \lor \neg \left(y \leq 6.8 \cdot 10^{+106}\right):\\ \;\;\;\;4 + -4 \cdot \frac{z}{y}\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{z - x}{y}\\ \end{array} \]
Alternative 4
Error8.5
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -8600000000 \lor \neg \left(z \leq 6.8 \cdot 10^{+29}\right):\\ \;\;\;\;4 + -4 \cdot \frac{z}{y}\\ \mathbf{else}:\\ \;\;\;\;4 + 4 \cdot \frac{x}{y}\\ \end{array} \]
Alternative 5
Error16.2
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{+115}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{+106}:\\ \;\;\;\;-4 \cdot \frac{z - x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
Alternative 6
Error30.4
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+115}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+91}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]
Alternative 7
Error0.2
Cost576
\[4 + \frac{-4}{y} \cdot \left(z - x\right) \]
Alternative 8
Error36.0
Cost64
\[4 \]

Error

Reproduce

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