Average Error: 12.6 → 2.5
Time: 6.3s
Precision: binary64
Cost: 1480
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{-230}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{+300}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* x (- y z)) y)))
   (if (<= t_0 2e-230)
     (/ x (/ y (- y z)))
     (if (<= t_0 4e+300) (- x (/ (* x z) y)) x))))
double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
	double t_0 = (x * (y - z)) / y;
	double tmp;
	if (t_0 <= 2e-230) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= 4e+300) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x;
	}
	return tmp;
}
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)) / y
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x * (y - z)) / y
    if (t_0 <= 2d-230) then
        tmp = x / (y / (y - z))
    else if (t_0 <= 4d+300) then
        tmp = x - ((x * z) / y)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
public static double code(double x, double y, double z) {
	double t_0 = (x * (y - z)) / y;
	double tmp;
	if (t_0 <= 2e-230) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= 4e+300) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y - z)) / y
def code(x, y, z):
	t_0 = (x * (y - z)) / y
	tmp = 0
	if t_0 <= 2e-230:
		tmp = x / (y / (y - z))
	elif t_0 <= 4e+300:
		tmp = x - ((x * z) / y)
	else:
		tmp = x
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(y - z)) / y)
end
function code(x, y, z)
	t_0 = Float64(Float64(x * Float64(y - z)) / y)
	tmp = 0.0
	if (t_0 <= 2e-230)
		tmp = Float64(x / Float64(y / Float64(y - z)));
	elseif (t_0 <= 4e+300)
		tmp = Float64(x - Float64(Float64(x * z) / y));
	else
		tmp = x;
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * (y - z)) / y;
end
function tmp_2 = code(x, y, z)
	t_0 = (x * (y - z)) / y;
	tmp = 0.0;
	if (t_0 <= 2e-230)
		tmp = x / (y / (y - z));
	elseif (t_0 <= 4e+300)
		tmp = x - ((x * z) / y);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-230], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e+300], N[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], x]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-230}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\

\mathbf{elif}\;t_0 \leq 4 \cdot 10^{+300}:\\
\;\;\;\;x - \frac{x \cdot z}{y}\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.6
Target3.0
Herbie2.5
\[\begin{array}{l} \mathbf{if}\;z < -2.060202331921739 \cdot 10^{+104}:\\ \;\;\;\;x - \frac{z \cdot x}{y}\\ \mathbf{elif}\;z < 1.6939766013828526 \cdot 10^{+213}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < 2.00000000000000009e-230

    1. Initial program 13.8

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Applied egg-rr13.4

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \left(y - z\right)} \]
    3. Applied egg-rr2.7

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

    if 2.00000000000000009e-230 < (/.f64 (*.f64 x (-.f64 y z)) y) < 4.0000000000000002e300

    1. Initial program 0.3

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified6.3

      \[\leadsto \color{blue}{x - z \cdot \frac{x}{y}} \]
      Proof
      (-.f64 x (*.f64 z (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 x)) (*.f64 z (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (Rewrite<= *-inverses_binary64 (/.f64 y y)) x) (*.f64 z (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 y x) y)) (*.f64 z (/.f64 x y))): 67 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 40 points increase in error, 61 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 5 points increase in error, 4 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 82 points increase in error, 66 points decrease in error
    3. Taylor expanded in x around 0 4.5

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

      \[\leadsto \color{blue}{x - \frac{z \cdot x}{y}} \]
      Proof
      (-.f64 x (/.f64 (*.f64 z x) y)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 x)) (/.f64 (*.f64 z x) y)): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 1 x) (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 z y) x))): 22 points increase in error, 36 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 x (-.f64 1 (/.f64 z y)))): 2 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 (/.f64 z y)) x)): 0 points increase in error, 0 points decrease in error

    if 4.0000000000000002e300 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 62.0

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

      \[\leadsto \color{blue}{x - z \cdot \frac{x}{y}} \]
      Proof
      (-.f64 x (*.f64 z (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 x)) (*.f64 z (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (Rewrite<= *-inverses_binary64 (/.f64 y y)) x) (*.f64 z (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 y x) y)) (*.f64 z (/.f64 x y))): 67 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 40 points increase in error, 61 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 5 points increase in error, 4 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 82 points increase in error, 66 points decrease in error
    3. Applied egg-rr21.5

      \[\leadsto x - \color{blue}{\frac{1}{\frac{y}{z \cdot x}}} \]
    4. Taylor expanded in y around inf 12.5

      \[\leadsto \color{blue}{x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq 2 \cdot 10^{-230}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 4 \cdot 10^{+300}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternatives

Alternative 1
Error20.1
Cost912
\[\begin{array}{l} t_0 := \frac{-z}{\frac{y}{x}}\\ \mathbf{if}\;y \leq -1517845392941927.3:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.24 \cdot 10^{-234}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-168}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-73}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error20.9
Cost912
\[\begin{array}{l} \mathbf{if}\;y \leq -1517845392941927.3:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.24 \cdot 10^{-234}:\\ \;\;\;\;\frac{x}{\frac{-y}{z}}\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-168}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-73}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error3.0
Cost448
\[\frac{x}{\frac{y}{y - z}} \]
Alternative 4
Error25.1
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022298 
(FPCore (x y z)
  :name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))

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