Average Error: 12.9 → 0.4
Time: 7.9s
Precision: binary64
Cost: 2640
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ t_1 := x - \frac{x}{\frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{+85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+293}:\\ \;\;\;\;x - \frac{1}{\frac{y}{x \cdot z}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \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)) (t_1 (- x (/ x (/ y z)))))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 -2e+85)
       t_0
       (if (<= t_0 5e+14)
         t_1
         (if (<= t_0 2e+293)
           (- x (/ 1.0 (/ y (* x z))))
           (* x (- 1.0 (/ z y)))))))))
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 t_1 = x - (x / (y / z));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= -2e+85) {
		tmp = t_0;
	} else if (t_0 <= 5e+14) {
		tmp = t_1;
	} else if (t_0 <= 2e+293) {
		tmp = x - (1.0 / (y / (x * z)));
	} else {
		tmp = x * (1.0 - (z / y));
	}
	return tmp;
}
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 t_1 = x - (x / (y / z));
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_0 <= -2e+85) {
		tmp = t_0;
	} else if (t_0 <= 5e+14) {
		tmp = t_1;
	} else if (t_0 <= 2e+293) {
		tmp = x - (1.0 / (y / (x * z)));
	} else {
		tmp = x * (1.0 - (z / y));
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y - z)) / y
def code(x, y, z):
	t_0 = (x * (y - z)) / y
	t_1 = x - (x / (y / z))
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1
	elif t_0 <= -2e+85:
		tmp = t_0
	elif t_0 <= 5e+14:
		tmp = t_1
	elif t_0 <= 2e+293:
		tmp = x - (1.0 / (y / (x * z)))
	else:
		tmp = x * (1.0 - (z / y))
	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)
	t_1 = Float64(x - Float64(x / Float64(y / z)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= -2e+85)
		tmp = t_0;
	elseif (t_0 <= 5e+14)
		tmp = t_1;
	elseif (t_0 <= 2e+293)
		tmp = Float64(x - Float64(1.0 / Float64(y / Float64(x * z))));
	else
		tmp = Float64(x * Float64(1.0 - Float64(z / y)));
	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;
	t_1 = x - (x / (y / z));
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1;
	elseif (t_0 <= -2e+85)
		tmp = t_0;
	elseif (t_0 <= 5e+14)
		tmp = t_1;
	elseif (t_0 <= 2e+293)
		tmp = x - (1.0 / (y / (x * z)));
	else
		tmp = x * (1.0 - (z / y));
	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]}, Block[{t$95$1 = N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -2e+85], t$95$0, If[LessEqual[t$95$0, 5e+14], t$95$1, If[LessEqual[t$95$0, 2e+293], N[(x - N[(1.0 / N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y - z\right)}{y}\\
t_1 := x - \frac{x}{\frac{y}{z}}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -2 \cdot 10^{+85}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+14}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+293}:\\
\;\;\;\;x - \frac{1}{\frac{y}{x \cdot z}}\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.9
Target3.3
Herbie0.4
\[\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 4 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < -inf.0 or -2e85 < (/.f64 (*.f64 x (-.f64 y z)) y) < 5e14

    1. Initial program 13.3

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

      \[\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))): 43 points increase in error, 63 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 0 points increase in error, 3 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 87 points increase in error, 69 points decrease in error
    3. Taylor expanded in z around 0 5.7

      \[\leadsto x - \color{blue}{\frac{z \cdot x}{y}} \]
    4. Simplified0.3

      \[\leadsto x - \color{blue}{x \cdot \frac{z}{y}} \]
      Proof
      (*.f64 x (/.f64 z y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 z y) x)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 z x) y)): 51 points increase in error, 58 points decrease in error
    5. Applied egg-rr0.3

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -2e85

    1. Initial program 0.2

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

    if 5e14 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.9999999999999998e293

    1. Initial program 0.2

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

      \[\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))): 43 points increase in error, 63 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 0 points increase in error, 3 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 87 points increase in error, 69 points decrease in error
    3. Applied egg-rr0.2

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

    if 1.9999999999999998e293 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 59.2

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

      \[\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))): 43 points increase in error, 63 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 0 points increase in error, 3 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 87 points increase in error, 69 points decrease in error
    3. Taylor expanded in x around 0 1.5

      \[\leadsto \color{blue}{\left(1 - \frac{z}{y}\right) \cdot x} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -\infty:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq -2 \cdot 10^{+85}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 5 \cdot 10^{+14}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 2 \cdot 10^{+293}:\\ \;\;\;\;x - \frac{1}{\frac{y}{x \cdot z}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost2512
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ t_1 := x - \frac{x}{\frac{y}{z}}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{+85}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 9 \cdot 10^{-59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+293}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \end{array} \]
Alternative 2
Error19.6
Cost912
\[\begin{array}{l} t_0 := \frac{-z}{\frac{y}{x}}\\ \mathbf{if}\;y \leq -4.2823194274122806 \cdot 10^{+30}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-170}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{-97}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{-43}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error3.7
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+150}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 4
Error2.2
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+33}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 5
Error25.2
Cost64
\[x \]

Error

Reproduce

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