Average Error: 0.2 → 0.0
Time: 7.8s
Precision: binary64
Cost: 832
\[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
\[\left(-4 \cdot \frac{y}{z} + 4 \cdot \frac{x}{z}\right) + -2 \]
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
(FPCore (x y z)
 :precision binary64
 (+ (+ (* -4.0 (/ y z)) (* 4.0 (/ x z))) -2.0))
double code(double x, double y, double z) {
	return (4.0 * ((x - y) - (z * 0.5))) / z;
}
double code(double x, double y, double z) {
	return ((-4.0 * (y / z)) + (4.0 * (x / z))) + -2.0;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (4.0d0 * ((x - y) - (z * 0.5d0))) / z
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (((-4.0d0) * (y / z)) + (4.0d0 * (x / z))) + (-2.0d0)
end function
public static double code(double x, double y, double z) {
	return (4.0 * ((x - y) - (z * 0.5))) / z;
}
public static double code(double x, double y, double z) {
	return ((-4.0 * (y / z)) + (4.0 * (x / z))) + -2.0;
}
def code(x, y, z):
	return (4.0 * ((x - y) - (z * 0.5))) / z
def code(x, y, z):
	return ((-4.0 * (y / z)) + (4.0 * (x / z))) + -2.0
function code(x, y, z)
	return Float64(Float64(4.0 * Float64(Float64(x - y) - Float64(z * 0.5))) / z)
end
function code(x, y, z)
	return Float64(Float64(Float64(-4.0 * Float64(y / z)) + Float64(4.0 * Float64(x / z))) + -2.0)
end
function tmp = code(x, y, z)
	tmp = (4.0 * ((x - y) - (z * 0.5))) / z;
end
function tmp = code(x, y, z)
	tmp = ((-4.0 * (y / z)) + (4.0 * (x / z))) + -2.0;
end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - y), $MachinePrecision] - N[(z * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := N[(N[(N[(-4.0 * N[(y / z), $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision]
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
\left(-4 \cdot \frac{y}{z} + 4 \cdot \frac{x}{z}\right) + -2

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.2
Target0.0
Herbie0.0
\[4 \cdot \frac{x}{z} - \left(2 + 4 \cdot \frac{y}{z}\right) \]

Derivation

  1. Initial program 0.2

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x - y, \frac{4}{z}, -2\right)} \]
    Proof
    (fma.f64 (-.f64 x y) (/.f64 4 z) -2): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (Rewrite<= metadata-eval (*.f64 1 -2))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (*.f64 (Rewrite<= *-inverses_binary64 (/.f64 (neg.f64 z) (neg.f64 z))) -2)): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (*.f64 (/.f64 (neg.f64 z) (neg.f64 z)) (Rewrite<= metadata-eval (/.f64 2 -1)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (*.f64 (/.f64 (neg.f64 z) (neg.f64 z)) (/.f64 (Rewrite<= metadata-eval (*.f64 1/2 4)) -1))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 (neg.f64 z) (*.f64 1/2 4)) (*.f64 (neg.f64 z) -1)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (/.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (neg.f64 z) 1/2) 4)) (*.f64 (neg.f64 z) -1))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (/.f64 (*.f64 (*.f64 (neg.f64 z) 1/2) 4) (Rewrite=> *-commutative_binary64 (*.f64 -1 (neg.f64 z))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (/.f64 (*.f64 (*.f64 (neg.f64 z) 1/2) 4) (Rewrite<= neg-mul-1_binary64 (neg.f64 (neg.f64 z))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (/.f64 (*.f64 (*.f64 (neg.f64 z) 1/2) 4) (Rewrite=> remove-double-neg_binary64 z))): 0 points increase in error, 0 points decrease in error
    (fma.f64 (-.f64 x y) (/.f64 4 z) (Rewrite<= associate-*r/_binary64 (*.f64 (*.f64 (neg.f64 z) 1/2) (/.f64 4 z)))): 18 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 x y) (/.f64 4 z)) (*.f64 (*.f64 (neg.f64 z) 1/2) (/.f64 4 z)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-rgt-in_binary64 (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (*.f64 (neg.f64 z) 1/2)))): 4 points increase in error, 3 points decrease in error
    (*.f64 (/.f64 4 z) (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (-.f64 x y) (*.f64 z 1/2)))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 4 (-.f64 (-.f64 x y) (*.f64 z 1/2))) z)): 0 points increase in error, 52 points decrease in error
  3. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{\left(-4 \cdot \frac{y}{z} + 4 \cdot \frac{x}{z}\right) - 2} \]
  4. Final simplification0.0

    \[\leadsto \left(-4 \cdot \frac{y}{z} + 4 \cdot \frac{x}{z}\right) + -2 \]

Alternatives

Alternative 1
Error33.3
Cost1772
\[\begin{array}{l} t_0 := y \cdot \frac{-4}{z}\\ t_1 := \frac{4}{\frac{z}{x}}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.359400899941993 \cdot 10^{+76}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -2.866137834190853 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.3735639269101106 \cdot 10^{-216}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.4073695202489786 \cdot 10^{-238}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.6560159831744695 \cdot 10^{-269}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.972726047352174 \cdot 10^{-55}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 5.77354202753819 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 0.44812270334897025:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 2.4416640114888558 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+134}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error33.2
Cost1772
\[\begin{array}{l} t_0 := \frac{-4 \cdot y}{z}\\ t_1 := \frac{4}{\frac{z}{x}}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.359400899941993 \cdot 10^{+76}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -2.866137834190853 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.3735639269101106 \cdot 10^{-216}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.4073695202489786 \cdot 10^{-238}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.6560159831744695 \cdot 10^{-269}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.972726047352174 \cdot 10^{-55}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 5.77354202753819 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 0.44812270334897025:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 2.4416640114888558 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+134}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error33.2
Cost1772
\[\begin{array}{l} t_0 := \frac{-4 \cdot y}{z}\\ t_1 := 4 \cdot \frac{x}{z}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.359400899941993 \cdot 10^{+76}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -2.866137834190853 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.3735639269101106 \cdot 10^{-216}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.4073695202489786 \cdot 10^{-238}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -1.6560159831744695 \cdot 10^{-269}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.972726047352174 \cdot 10^{-55}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 5.77354202753819 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 0.44812270334897025:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 2.4416640114888558 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+134}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error12.5
Cost1240
\[\begin{array}{l} t_0 := -4 \cdot \frac{y}{z} + -2\\ t_1 := 4 \cdot \frac{x - y}{z}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.359400899941993 \cdot 10^{+76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -8.178691016987147 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.972726047352174 \cdot 10^{-55}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.77354202753819 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+134}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error30.4
Cost1112
\[\begin{array}{l} t_0 := \frac{4}{\frac{z}{x}}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+124}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -4.359400899941993 \cdot 10^{+76}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq -8.178691016987147 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.972726047352174 \cdot 10^{-55}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 5.77354202753819 \cdot 10^{-15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{+134}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error9.0
Cost976
\[\begin{array}{l} t_0 := -4 \cdot \frac{y}{z} + -2\\ t_1 := 4 \cdot \frac{x}{z} + -2\\ \mathbf{if}\;x \leq -1.9910808473400473 \cdot 10^{-17}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.972726047352174 \cdot 10^{-55}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.77354202753819 \cdot 10^{-15}:\\ \;\;\;\;4 \cdot \frac{x - y}{z}\\ \mathbf{elif}\;x \leq 6.044343347285061 \cdot 10^{+63}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error13.4
Cost712
\[\begin{array}{l} t_0 := 4 \cdot \frac{x}{z}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+124}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+150}:\\ \;\;\;\;-4 \cdot \frac{y}{z} + -2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error0.2
Cost704
\[\frac{4 \cdot \left(\left(x - y\right) + z \cdot -0.5\right)}{z} \]
Alternative 9
Error36.5
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, B"
  :precision binary64

  :herbie-target
  (- (* 4.0 (/ x z)) (+ 2.0 (* 4.0 (/ y z))))

  (/ (* 4.0 (- (- x y) (* z 0.5))) z))