?

Average Error: 16.29% → 0.22%
Time: 6.7s
Precision: binary64
Cost: 576

?

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

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original16.29%
Target0.07%
Herbie0.22%
\[\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}} \]

Derivation?

  1. Initial program 16.29

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

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

    \[\leadsto \color{blue}{y - \frac{y + -1}{\frac{z}{x}}} \]
    Proof

    [Start]5.25

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

    associate-/l* [=>]0.22

    \[ y + \color{blue}{\frac{1 + -1 \cdot y}{\frac{z}{x}}} \]

    +-commutative [=>]0.22

    \[ y + \frac{\color{blue}{-1 \cdot y + 1}}{\frac{z}{x}} \]

    metadata-eval [<=]0.22

    \[ y + \frac{-1 \cdot y + \color{blue}{-1 \cdot -1}}{\frac{z}{x}} \]

    distribute-lft-in [<=]0.22

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

    metadata-eval [<=]0.22

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

    sub-neg [<=]0.22

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

    mul-1-neg [=>]0.22

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

    distribute-neg-frac [<=]0.22

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

    associate-/l* [<=]5.25

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

    unsub-neg [=>]5.25

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

    associate-/l* [=>]0.22

    \[ y - \color{blue}{\frac{y - 1}{\frac{z}{x}}} \]

    sub-neg [=>]0.22

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

    metadata-eval [=>]0.22

    \[ y - \frac{y + \color{blue}{-1}}{\frac{z}{x}} \]
  4. Final simplification0.22

    \[\leadsto y - \frac{y + -1}{\frac{z}{x}} \]

Alternatives

Alternative 1
Error2.14%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{+37} \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y \cdot \frac{z - x}{z}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{z}\\ \end{array} \]
Alternative 2
Error2.13%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{+37} \lor \neg \left(y \leq 1\right):\\ \;\;\;\;y - \frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{z}\\ \end{array} \]
Alternative 3
Error2.14%
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{+37}:\\ \;\;\;\;y - \frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \end{array} \]
Alternative 4
Error31.69%
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -4.7 \cdot 10^{-94}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{-26}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 5
Error14.11%
Cost320
\[y + \frac{x}{z} \]
Alternative 6
Error49.28%
Cost64
\[y \]

Error

Reproduce?

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