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

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 10.4

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

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}} \]
    Proof
    (/.f64 (fma.f64 y (-.f64 z x) x) z): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (-.f64 z x)) x)) z): 3 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y (-.f64 z x)))) z): 0 points increase in error, 3 points decrease in error
  3. Taylor expanded in z around 0 3.5

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

    \[\leadsto \color{blue}{y + \frac{x}{z} \cdot \left(1 - y\right)} \]
    Proof
    (+.f64 y (*.f64 (/.f64 x z) (-.f64 1 y))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (*.f64 (/.f64 x z) (Rewrite<= unsub-neg_binary64 (+.f64 1 (neg.f64 y))))): 14 points increase in error, 9 points decrease in error
    (+.f64 y (*.f64 (/.f64 x z) (+.f64 1 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 y))))): 9 points increase in error, 14 points decrease in error
    (+.f64 y (Rewrite<= associate-/r/_binary64 (/.f64 x (/.f64 z (+.f64 1 (*.f64 -1 y)))))): 1 points increase in error, 0 points decrease in error
    (+.f64 y (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x (+.f64 1 (*.f64 -1 y))) z))): 0 points increase in error, 13 points decrease in error
    (+.f64 y (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 (+.f64 1 (*.f64 -1 y)) x)) z)): 0 points increase in error, 1 points decrease in error
    (+.f64 y (Rewrite=> associate-/l*_binary64 (/.f64 (+.f64 1 (*.f64 -1 y)) (/.f64 z x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (/.f64 (Rewrite=> +-commutative_binary64 (+.f64 (*.f64 -1 y) 1)) (/.f64 z x))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (/.f64 (+.f64 (*.f64 -1 y) (Rewrite<= metadata-eval (*.f64 -1 -1))) (/.f64 z x))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (/.f64 (Rewrite<= distribute-lft-in_binary64 (*.f64 -1 (+.f64 y -1))) (/.f64 z x))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (/.f64 (*.f64 -1 (+.f64 y (Rewrite<= metadata-eval (neg.f64 1)))) (/.f64 z x))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (/.f64 (*.f64 -1 (Rewrite<= sub-neg_binary64 (-.f64 y 1))) (/.f64 z x))): 18 points increase in error, 0 points decrease in error
    (+.f64 y (Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 (-.f64 y 1) (/.f64 z x))))): 0 points increase in error, 18 points decrease in error
    (+.f64 y (*.f64 -1 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (-.f64 y 1) x) z)))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (Rewrite=> mul-1-neg_binary64 (neg.f64 (/.f64 (*.f64 (-.f64 y 1) x) z)))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (Rewrite=> neg-sub0_binary64 (-.f64 0 (/.f64 (*.f64 (-.f64 y 1) x) z)))): 31 points increase in error, 0 points decrease in error
    (+.f64 y (-.f64 0 (Rewrite=> associate-/l*_binary64 (/.f64 (-.f64 y 1) (/.f64 z x))))): 0 points increase in error, 31 points decrease in error
    (+.f64 y (-.f64 0 (Rewrite=> div-sub_binary64 (-.f64 (/.f64 y (/.f64 z x)) (/.f64 1 (/.f64 z x)))))): 13 points increase in error, 0 points decrease in error
    (+.f64 y (-.f64 0 (-.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y x) z)) (/.f64 1 (/.f64 z x))))): 0 points increase in error, 13 points decrease in error
    (+.f64 y (Rewrite=> associate--r-_binary64 (+.f64 (-.f64 0 (/.f64 (*.f64 y x) z)) (/.f64 1 (/.f64 z x))))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 (/.f64 (*.f64 y x) z))) (/.f64 1 (/.f64 z x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (+.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 y x) z))) (/.f64 1 (/.f64 z x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) z)) (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 1 z) x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) z)) (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 1 x) z)))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) z)) (/.f64 (*.f64 (Rewrite<= metadata-eval (neg.f64 -1)) x) z))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) z)) (/.f64 (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 -1 x))) z))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) z)) (/.f64 (neg.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 x))) z))): 0 points increase in error, 0 points decrease in error
    (+.f64 y (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) z)) (/.f64 (Rewrite=> remove-double-neg_binary64 x) z))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) z)) (/.f64 x z)) y)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) z)) (+.f64 (/.f64 x z) y))): 1 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 -1 (/.f64 (*.f64 y x) z)) (Rewrite<= +-commutative_binary64 (+.f64 y (/.f64 x z)))): 0 points increase in error, 1 points decrease in error
  5. Final simplification0.0

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

Alternatives

Alternative 1
Error8.6
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{-245} \lor \neg \left(z \leq 4.4 \cdot 10^{-63}\right):\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \left(1 - y\right)\\ \end{array} \]
Alternative 2
Error0.7
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -9 \lor \neg \left(y \leq 2.05 \cdot 10^{-8}\right):\\ \;\;\;\;y - \frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{z}\\ \end{array} \]
Alternative 3
Error0.7
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -9:\\ \;\;\;\;y - \frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{-8}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \end{array} \]
Alternative 4
Error11.0
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq 4.2 \cdot 10^{+174}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+258}:\\ \;\;\;\;y \cdot \left(-\frac{x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 5
Error21.4
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{-179}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-47}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 6
Error8.9
Cost320
\[y + \frac{x}{z} \]
Alternative 7
Error31.2
Cost64
\[y \]

Error

Reproduce

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