Average Error: 12.1 → 2.1
Time: 2.9s
Precision: binary64
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{if}\;z \leq -1.95 \cdot 10^{+119}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+221}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (- 1.0 (/ z y)))))
   (if (<= z -1.95e+119)
     (- x (* z (/ x y)))
     (if (<= z 6.5e-20) t_0 (if (<= z 5.5e+221) (- x (/ z (/ y x))) t_0)))))
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 * (1.0 - (z / y));
	double tmp;
	if (z <= -1.95e+119) {
		tmp = x - (z * (x / y));
	} else if (z <= 6.5e-20) {
		tmp = t_0;
	} else if (z <= 5.5e+221) {
		tmp = x - (z / (y / x));
	} else {
		tmp = t_0;
	}
	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 * (1.0d0 - (z / y))
    if (z <= (-1.95d+119)) then
        tmp = x - (z * (x / y))
    else if (z <= 6.5d-20) then
        tmp = t_0
    else if (z <= 5.5d+221) then
        tmp = x - (z / (y / x))
    else
        tmp = t_0
    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 * (1.0 - (z / y));
	double tmp;
	if (z <= -1.95e+119) {
		tmp = x - (z * (x / y));
	} else if (z <= 6.5e-20) {
		tmp = t_0;
	} else if (z <= 5.5e+221) {
		tmp = x - (z / (y / x));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y - z)) / y
def code(x, y, z):
	t_0 = x * (1.0 - (z / y))
	tmp = 0
	if z <= -1.95e+119:
		tmp = x - (z * (x / y))
	elif z <= 6.5e-20:
		tmp = t_0
	elif z <= 5.5e+221:
		tmp = x - (z / (y / x))
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(y - z)) / y)
end
function code(x, y, z)
	t_0 = Float64(x * Float64(1.0 - Float64(z / y)))
	tmp = 0.0
	if (z <= -1.95e+119)
		tmp = Float64(x - Float64(z * Float64(x / y)));
	elseif (z <= 6.5e-20)
		tmp = t_0;
	elseif (z <= 5.5e+221)
		tmp = Float64(x - Float64(z / Float64(y / x)));
	else
		tmp = t_0;
	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 * (1.0 - (z / y));
	tmp = 0.0;
	if (z <= -1.95e+119)
		tmp = x - (z * (x / y));
	elseif (z <= 6.5e-20)
		tmp = t_0;
	elseif (z <= 5.5e+221)
		tmp = x - (z / (y / x));
	else
		tmp = t_0;
	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[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.95e+119], N[(x - N[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6.5e-20], t$95$0, If[LessEqual[z, 5.5e+221], N[(x - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := x \cdot \left(1 - \frac{z}{y}\right)\\
\mathbf{if}\;z \leq -1.95 \cdot 10^{+119}:\\
\;\;\;\;x - z \cdot \frac{x}{y}\\

\mathbf{elif}\;z \leq 6.5 \cdot 10^{-20}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 5.5 \cdot 10^{+221}:\\
\;\;\;\;x - \frac{z}{\frac{y}{x}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.1
Target3.3
Herbie2.1
\[\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 z < -1.9499999999999999e119

    1. Initial program 12.9

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

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
    3. Applied egg-rr6.0

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

    if -1.9499999999999999e119 < z < 6.50000000000000032e-20 or 5.5000000000000003e221 < z

    1. Initial program 12.5

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

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
    3. Taylor expanded in x around 0 1.6

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

    if 6.50000000000000032e-20 < z < 5.5000000000000003e221

    1. Initial program 10.2

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

      \[\leadsto \color{blue}{x - \frac{z}{\frac{y}{x}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.95 \cdot 10^{+119}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-20}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+221}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \end{array} \]

Reproduce

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