Average Error: 12.7 → 1.0
Time: 9.2s
Precision: binary64
Cost: 2512
\[\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{z}{\frac{y}{x}}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{+280}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -5 \cdot 10^{-128}:\\ \;\;\;\;x - \frac{1}{\frac{y}{x \cdot z}}\\ \mathbf{elif}\;t_0 \leq 10^{-74}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;t_0 \leq 10^{+271}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (/ z (/ y x)))))
   (if (<= t_0 -5e+280)
     t_1
     (if (<= t_0 -5e-128)
       (- x (/ 1.0 (/ y (* x z))))
       (if (<= t_0 1e-74) (/ x (/ y (- y z))) (if (<= t_0 1e+271) t_0 t_1))))))
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 - (z / (y / x));
	double tmp;
	if (t_0 <= -5e+280) {
		tmp = t_1;
	} else if (t_0 <= -5e-128) {
		tmp = x - (1.0 / (y / (x * z)));
	} else if (t_0 <= 1e-74) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= 1e+271) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = (x * (y - z)) / y
    t_1 = x - (z / (y / x))
    if (t_0 <= (-5d+280)) then
        tmp = t_1
    else if (t_0 <= (-5d-128)) then
        tmp = x - (1.0d0 / (y / (x * z)))
    else if (t_0 <= 1d-74) then
        tmp = x / (y / (y - z))
    else if (t_0 <= 1d+271) then
        tmp = t_0
    else
        tmp = t_1
    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 t_1 = x - (z / (y / x));
	double tmp;
	if (t_0 <= -5e+280) {
		tmp = t_1;
	} else if (t_0 <= -5e-128) {
		tmp = x - (1.0 / (y / (x * z)));
	} else if (t_0 <= 1e-74) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= 1e+271) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 - (z / (y / x))
	tmp = 0
	if t_0 <= -5e+280:
		tmp = t_1
	elif t_0 <= -5e-128:
		tmp = x - (1.0 / (y / (x * z)))
	elif t_0 <= 1e-74:
		tmp = x / (y / (y - z))
	elif t_0 <= 1e+271:
		tmp = t_0
	else:
		tmp = t_1
	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(z / Float64(y / x)))
	tmp = 0.0
	if (t_0 <= -5e+280)
		tmp = t_1;
	elseif (t_0 <= -5e-128)
		tmp = Float64(x - Float64(1.0 / Float64(y / Float64(x * z))));
	elseif (t_0 <= 1e-74)
		tmp = Float64(x / Float64(y / Float64(y - z)));
	elseif (t_0 <= 1e+271)
		tmp = t_0;
	else
		tmp = t_1;
	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 - (z / (y / x));
	tmp = 0.0;
	if (t_0 <= -5e+280)
		tmp = t_1;
	elseif (t_0 <= -5e-128)
		tmp = x - (1.0 / (y / (x * z)));
	elseif (t_0 <= 1e-74)
		tmp = x / (y / (y - z));
	elseif (t_0 <= 1e+271)
		tmp = t_0;
	else
		tmp = t_1;
	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[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+280], t$95$1, If[LessEqual[t$95$0, -5e-128], N[(x - N[(1.0 / N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e-74], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+271], t$95$0, t$95$1]]]]]]
\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{z}{\frac{y}{x}}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+280}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-128}:\\
\;\;\;\;x - \frac{1}{\frac{y}{x \cdot z}}\\

\mathbf{elif}\;t_0 \leq 10^{-74}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\

\mathbf{elif}\;t_0 \leq 10^{+271}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.7
Target3.1
Herbie1.0
\[\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) < -5.0000000000000002e280 or 9.99999999999999953e270 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 53.2

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

      \[\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))): 55 points increase in error, 1 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 43 points increase in error, 55 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 8 points increase in error, 4 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 68 points increase in error, 74 points decrease in error
    3. Applied egg-rr4.5

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

    if -5.0000000000000002e280 < (/.f64 (*.f64 x (-.f64 y z)) y) < -5.0000000000000001e-128

    1. Initial program 0.4

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified4.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))): 55 points increase in error, 1 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 43 points increase in error, 55 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 8 points increase in error, 4 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 68 points increase in error, 74 points decrease in error
    3. Applied egg-rr0.3

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

    if -5.0000000000000001e-128 < (/.f64 (*.f64 x (-.f64 y z)) y) < 9.99999999999999958e-75

    1. Initial program 10.8

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

      \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{y}{y - z}}} \]
    3. Applied egg-rr0.1

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

    if 9.99999999999999958e-75 < (/.f64 (*.f64 x (-.f64 y z)) y) < 9.99999999999999953e270

    1. Initial program 0.3

      \[\frac{x \cdot \left(y - z\right)}{y} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq -5 \cdot 10^{+280}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq -5 \cdot 10^{-128}:\\ \;\;\;\;x - \frac{1}{\frac{y}{x \cdot z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 10^{-74}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 10^{+271}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \end{array} \]

Alternatives

Alternative 1
Error1.0
Cost2512
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ t_1 := \frac{x}{\frac{y}{y - z}}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -1 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 10^{-74}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+271}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 2
Error20.9
Cost912
\[\begin{array}{l} t_0 := -\frac{z}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -2.3129384686956604 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.3696361838585986 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.5838275979479375 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{+119}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error21.4
Cost912
\[\begin{array}{l} t_0 := \frac{x}{\frac{-y}{z}}\\ \mathbf{if}\;z \leq -2.3129384686956604 \cdot 10^{+27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.3696361838585986 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.5838275979479375 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{+119}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;-\frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 4
Error21.4
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -2.3129384686956604 \cdot 10^{+27}:\\ \;\;\;\;\frac{x}{\frac{-y}{z}}\\ \mathbf{elif}\;z \leq 5.3696361838585986 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.5838275979479375 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.4 \cdot 10^{+119}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error3.9
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq 10^{+130}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \end{array} \]
Alternative 6
Error2.9
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq 5.8760564166368735 \cdot 10^{-192}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \end{array} \]
Alternative 7
Error2.9
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq 5.8760564166368735 \cdot 10^{-192}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \end{array} \]
Alternative 8
Error25.9
Cost64
\[x \]

Error

Reproduce

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