Average Error: 0.1 → 0.0
Time: 9.5s
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.1
Target0.0
Herbie0.0
\[4 \cdot \frac{x}{z} - \left(2 + 4 \cdot \frac{y}{z}\right) \]

Derivation

  1. Initial program 0.1

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

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

    [Start]0.1

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

    associate-*l/ [<=]0.2

    \[ \color{blue}{\frac{4}{z} \cdot \left(\left(x - y\right) - z \cdot 0.5\right)} \]

    distribute-rgt-out-- [<=]0.2

    \[ \color{blue}{\left(x - y\right) \cdot \frac{4}{z} - \left(z \cdot 0.5\right) \cdot \frac{4}{z}} \]

    cancel-sign-sub-inv [=>]0.2

    \[ \color{blue}{\left(x - y\right) \cdot \frac{4}{z} + \left(-z \cdot 0.5\right) \cdot \frac{4}{z}} \]

    associate-*r/ [=>]0.2

    \[ \color{blue}{\frac{\left(x - y\right) \cdot 4}{z}} + \left(-z \cdot 0.5\right) \cdot \frac{4}{z} \]

    associate-*l/ [<=]0.1

    \[ \color{blue}{\frac{x - y}{z} \cdot 4} + \left(-z \cdot 0.5\right) \cdot \frac{4}{z} \]

    *-commutative [=>]0.1

    \[ \color{blue}{4 \cdot \frac{x - y}{z}} + \left(-z \cdot 0.5\right) \cdot \frac{4}{z} \]

    fma-def [=>]0.1

    \[ \color{blue}{\mathsf{fma}\left(4, \frac{x - y}{z}, \left(-z \cdot 0.5\right) \cdot \frac{4}{z}\right)} \]

    associate-*r/ [=>]0.0

    \[ \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{\frac{\left(-z \cdot 0.5\right) \cdot 4}{z}}\right) \]

    *-commutative [<=]0.0

    \[ \mathsf{fma}\left(4, \frac{x - y}{z}, \frac{\color{blue}{4 \cdot \left(-z \cdot 0.5\right)}}{z}\right) \]

    *-commutative [=>]0.0

    \[ \mathsf{fma}\left(4, \frac{x - y}{z}, \frac{4 \cdot \left(-\color{blue}{0.5 \cdot z}\right)}{z}\right) \]

    distribute-lft-neg-in [=>]0.0

    \[ \mathsf{fma}\left(4, \frac{x - y}{z}, \frac{4 \cdot \color{blue}{\left(\left(-0.5\right) \cdot z\right)}}{z}\right) \]

    associate-*r* [=>]0.0

    \[ \mathsf{fma}\left(4, \frac{x - y}{z}, \frac{\color{blue}{\left(4 \cdot \left(-0.5\right)\right) \cdot z}}{z}\right) \]

    associate-/l* [=>]0.0

    \[ \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{\frac{4 \cdot \left(-0.5\right)}{\frac{z}{z}}}\right) \]

    metadata-eval [=>]0.0

    \[ \mathsf{fma}\left(4, \frac{x - y}{z}, \frac{4 \cdot \color{blue}{-0.5}}{\frac{z}{z}}\right) \]

    metadata-eval [=>]0.0

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

    *-inverses [=>]0.0

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

    metadata-eval [=>]0.0

    \[ \mathsf{fma}\left(4, \frac{x - y}{z}, \color{blue}{-2}\right) \]
  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
Error32.1
Cost1772
\[\begin{array}{l} t_0 := y \cdot \frac{-4}{z}\\ t_1 := 4 \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -2.45 \cdot 10^{+38}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1 \cdot 10^{+19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-73}:\\ \;\;\;\;-2\\ \mathbf{elif}\;y \leq -3.25 \cdot 10^{-83}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -8.4 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{-272}:\\ \;\;\;\;-2\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-301}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-20}:\\ \;\;\;\;-2\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.9 \cdot 10^{+134}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error32.0
Cost1772
\[\begin{array}{l} t_0 := \frac{-4 \cdot y}{z}\\ t_1 := 4 \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -2.5 \cdot 10^{+36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1 \cdot 10^{+19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-73}:\\ \;\;\;\;-2\\ \mathbf{elif}\;y \leq -3.7 \cdot 10^{-83}:\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{elif}\;y \leq -8.4 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4 \cdot 10^{-272}:\\ \;\;\;\;-2\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{-15}:\\ \;\;\;\;-2\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{+134}:\\ \;\;\;\;-2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error8.6
Cost977
\[\begin{array}{l} t_0 := -2 + 4 \cdot \frac{x}{z}\\ \mathbf{if}\;x \leq -2.2 \cdot 10^{+44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{+25}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{4}{z}\\ \mathbf{elif}\;x \leq -0.0031 \lor \neg \left(x \leq 2.5 \cdot 10^{+48}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{y}{z} + -2\\ \end{array} \]
Alternative 4
Error31.0
Cost850
\[\begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{-12} \lor \neg \left(y \leq 1.3 \cdot 10^{-25}\right) \land \left(y \leq 7 \cdot 10^{+49} \lor \neg \left(y \leq 3.05 \cdot 10^{+134}\right)\right):\\ \;\;\;\;y \cdot \frac{-4}{z}\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \]
Alternative 5
Error13.4
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -35000 \lor \neg \left(z \leq 2.8 \cdot 10^{+160}\right):\\ \;\;\;\;-4 \cdot \frac{y}{z} + -2\\ \mathbf{else}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{4}{z}\\ \end{array} \]
Alternative 6
Error17.2
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{+49}:\\ \;\;\;\;-2\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+162}:\\ \;\;\;\;\left(x - y\right) \cdot \frac{4}{z}\\ \mathbf{else}:\\ \;\;\;\;-2\\ \end{array} \]
Alternative 7
Error0.2
Cost704
\[\left(\left(x - y\right) + z \cdot -0.5\right) \cdot \frac{4}{z} \]
Alternative 8
Error0.2
Cost704
\[\frac{4}{\frac{z}{\left(x - y\right) + z \cdot -0.5}} \]
Alternative 9
Error0.1
Cost704
\[\frac{4 \cdot \left(\left(x - y\right) + z \cdot -0.5\right)}{z} \]
Alternative 10
Error36.7
Cost64
\[-2 \]

Error

Reproduce

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