Average Error: 0.2 → 0.0
Time: 6.0s
Precision: binary64
Cost: 576
\[\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z} \]
\[4 \cdot \frac{x - y}{z} + -2 \]
(FPCore (x y z) :precision binary64 (/ (* 4.0 (- (- x y) (* z 0.5))) z))
(FPCore (x y z) :precision binary64 (+ (* 4.0 (/ (- x y) 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 * ((x - y) / 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 * ((x - y) / 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 * ((x - y) / 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 * ((x - y) / 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(4.0 * Float64(Float64(x - y) / 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 * ((x - y) / 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[(4.0 * N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision]
\frac{4 \cdot \left(\left(x - y\right) - z \cdot 0.5\right)}{z}
4 \cdot \frac{x - y}{z} + -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}{\frac{4}{z} \cdot \left(\left(x - y\right) + z \cdot -0.5\right)} \]
    Proof
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (*.f64 z -1/2))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (*.f64 z (Rewrite<= metadata-eval (neg.f64 1/2))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 z 1/2))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (neg.f64 (Rewrite<= /-rgt-identity_binary64 (/.f64 (*.f64 z 1/2) 1))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (neg.f64 (/.f64 (*.f64 z 1/2) (Rewrite<= metadata-eval (neg.f64 -1)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (Rewrite<= distribute-frac-neg_binary64 (/.f64 (neg.f64 (*.f64 z 1/2)) (neg.f64 -1))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (/.f64 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (*.f64 z 1/2))) (neg.f64 -1)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 z 1/2) -1)) (neg.f64 -1)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (Rewrite=> associate-/l*_binary64 (/.f64 (*.f64 z 1/2) (/.f64 (neg.f64 -1) -1))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (/.f64 (*.f64 z 1/2) (/.f64 (Rewrite=> metadata-eval 1) -1)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (/.f64 (*.f64 z 1/2) (Rewrite=> metadata-eval -1)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 (/.f64 4 z) (-.f64 x y)) (*.f64 (/.f64 4 z) (/.f64 (*.f64 z 1/2) -1)))): 1 points increase in error, 4 points decrease in error
    (+.f64 (*.f64 (/.f64 4 z) (-.f64 x y)) (*.f64 (/.f64 4 z) (/.f64 (*.f64 z 1/2) (Rewrite<= metadata-eval (/.f64 1 -1))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 4 z) (-.f64 x y)) (*.f64 (/.f64 4 z) (/.f64 (*.f64 z 1/2) (/.f64 (Rewrite<= metadata-eval (neg.f64 -1)) -1)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 4 z) (-.f64 x y)) (*.f64 (/.f64 4 z) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (*.f64 z 1/2) -1) (neg.f64 -1))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 4 z) (-.f64 x y)) (*.f64 (/.f64 4 z) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 (*.f64 z 1/2))) (neg.f64 -1)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 4 z) (-.f64 x y)) (*.f64 (/.f64 4 z) (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (*.f64 z 1/2))) (neg.f64 -1)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 4 z) (-.f64 x y)) (*.f64 (/.f64 4 z) (/.f64 (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 z) 1/2)) (neg.f64 -1)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 4 z) (-.f64 x y)) (*.f64 (/.f64 4 z) (/.f64 (*.f64 (neg.f64 z) 1/2) (Rewrite=> metadata-eval 1)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 4 z) (-.f64 x y)) (*.f64 (/.f64 4 z) (Rewrite=> /-rgt-identity_binary64 (*.f64 (neg.f64 z) 1/2)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 4 z) (+.f64 (-.f64 x y) (*.f64 (neg.f64 z) 1/2)))): 4 points increase in error, 1 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)): 1 points increase in error, 57 points decrease in error
  3. Taylor expanded in z around 0 0.0

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

    \[\leadsto 4 \cdot \frac{x - y}{z} + -2 \]

Alternatives

Alternative 1
Error32.7
Cost1112
\[\begin{array}{l} t_0 := 4 \cdot \frac{x}{z}\\ t_1 := y \cdot \frac{-4}{z}\\ \mathbf{if}\;x \leq -9 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-99}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.8 \cdot 10^{-302}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{-208}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-17}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 1.95 \cdot 10^{+139}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error32.7
Cost1112
\[\begin{array}{l} t_0 := 4 \cdot \frac{x}{z}\\ t_1 := y \cdot \frac{-4}{z}\\ \mathbf{if}\;x \leq -5.4 \cdot 10^{+73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-301}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{-208}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-17}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{+141}:\\ \;\;\;\;\frac{-4}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error32.7
Cost1112
\[\begin{array}{l} t_0 := 4 \cdot \frac{x}{z}\\ t_1 := \frac{y \cdot -4}{z}\\ \mathbf{if}\;x \leq -4.1 \cdot 10^{+73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{-98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{-300}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{-208}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-17}:\\ \;\;\;\;-2\\ \mathbf{elif}\;x \leq 2.05 \cdot 10^{+141}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error16.7
Cost976
\[\begin{array}{l} t_0 := 4 \cdot \frac{x - y}{z}\\ \mathbf{if}\;z \leq -3.5 \cdot 10^{+212}:\\ \;\;\;\;-2\\ \mathbf{elif}\;z \leq -2.85 \cdot 10^{+194}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{+152}:\\ \;\;\;\;-2\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+177}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \]
Alternative 5
Error11.4
Cost712
\[\begin{array}{l} t_0 := 4 \cdot \frac{x - y}{z}\\ \mathbf{if}\;x \leq -1.65 \cdot 10^{+75}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.0001:\\ \;\;\;\;-4 \cdot \frac{y}{z} + -2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error10.5
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{+71}:\\ \;\;\;\;4 \cdot \frac{x}{z} + -2\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-9}:\\ \;\;\;\;-4 \cdot \frac{y}{z} + -2\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x - y}{z}\\ \end{array} \]
Alternative 7
Error29.6
Cost584
\[\begin{array}{l} t_0 := 4 \cdot \frac{x}{z}\\ \mathbf{if}\;x \leq -6 \cdot 10^{+63}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.00017:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error36.8
Cost64
\[-2 \]

Error

Reproduce

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