Average Error: 10.2 → 0.0
Time: 6.1s
Precision: binary64
Cost: 576
\[\frac{x + y \cdot \left(z - x\right)}{z} \]
\[y + \left(1 - y\right) \cdot \frac{x}{z} \]
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z) :precision binary64 (+ y (* (- 1.0 y) (/ x z))))
double code(double x, double y, double z) {
	return (x + (y * (z - x))) / z;
}
double code(double x, double y, double z) {
	return y + ((1.0 - y) * (x / z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x + (y * (z - x))) / 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 = y + ((1.0d0 - y) * (x / z))
end function
public static double code(double x, double y, double z) {
	return (x + (y * (z - x))) / z;
}
public static double code(double x, double y, double z) {
	return y + ((1.0 - y) * (x / z));
}
def code(x, y, z):
	return (x + (y * (z - x))) / z
def code(x, y, z):
	return y + ((1.0 - y) * (x / z))
function code(x, y, z)
	return Float64(Float64(x + Float64(y * Float64(z - x))) / z)
end
function code(x, y, z)
	return Float64(y + Float64(Float64(1.0 - y) * Float64(x / z)))
end
function tmp = code(x, y, z)
	tmp = (x + (y * (z - x))) / z;
end
function tmp = code(x, y, z)
	tmp = y + ((1.0 - y) * (x / z));
end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := N[(y + N[(N[(1.0 - y), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x + y \cdot \left(z - x\right)}{z}
y + \left(1 - y\right) \cdot \frac{x}{z}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 10.2

    \[\frac{x + y \cdot \left(z - x\right)}{z} \]
  2. Taylor expanded in x around 0 3.5

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(1 - y, \frac{x}{z}, y\right)} \]
    Proof
    (fma.f64 (-.f64 1 y) (/.f64 x z) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 (Rewrite<= unsub-neg_binary64 (+.f64 1 (neg.f64 y))) (/.f64 x z) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 (+.f64 1 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 y))) (/.f64 x z) y): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (+.f64 1 (*.f64 -1 y)) (/.f64 x z)) y)): 1 points increase in error, 3 points decrease in error
    (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (+.f64 1 (*.f64 -1 y)) x) z)) y): 23 points increase in error, 4 points decrease in error
    (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 (+.f64 1 (*.f64 -1 y)) z) x)) y): 38 points increase in error, 21 points decrease in error
    (+.f64 (*.f64 (/.f64 (+.f64 1 (Rewrite=> mul-1-neg_binary64 (neg.f64 y))) z) x) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (/.f64 (Rewrite=> unsub-neg_binary64 (-.f64 1 y)) z) x) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (Rewrite=> div-sub_binary64 (-.f64 (/.f64 1 z) (/.f64 y z))) x) y): 1 points increase in error, 1 points decrease in error
    (+.f64 (*.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 1 z) (neg.f64 (/.f64 y z)))) x) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (+.f64 (/.f64 1 z) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 y z)))) x) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 y z)) (/.f64 1 z))) x) y): 0 points increase in error, 0 points decrease in error
  4. Applied egg-rr0.0

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

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

Alternatives

Alternative 1
Error10.3
Cost912
\[\begin{array}{l} t_0 := \frac{x}{z} \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -5.8 \cdot 10^{+128}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -1.0430289301792878 \cdot 10^{+37}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 322.5046230008819:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;y \leq 1.1393337062156567 \cdot 10^{+49}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 2
Error3.6
Cost844
\[\begin{array}{l} t_0 := \frac{y}{z} \cdot \left(z - x\right)\\ \mathbf{if}\;y \leq -3 \cdot 10^{+205}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -88.03962237568854:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.000152785957582002:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.7
Cost712
\[\begin{array}{l} t_0 := y - y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -88.03962237568854:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.000152785957582002:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error19.8
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -8.63245224127955 \cdot 10^{-17}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 8.772376219524149 \cdot 10^{-18}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 5
Error8.6
Cost320
\[y + \frac{x}{z} \]
Alternative 6
Error30.9
Cost64
\[y \]

Error

Reproduce

herbie shell --seed 2022308 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
  :precision binary64

  :herbie-target
  (- (+ y (/ x z)) (/ y (/ z x)))

  (/ (+ x (* y (- z x))) z))