Average Error: 12.5 → 1.8
Time: 5.3s
Precision: binary64
Cost: 712
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := x - z \cdot \frac{x}{y}\\ \mathbf{if}\;z \leq -1 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-63}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \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 (* z (/ x y)))))
   (if (<= z -1e+23) t_0 (if (<= z 2e-63) (/ x (/ y (- y z))) 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 - (z * (x / y));
	double tmp;
	if (z <= -1e+23) {
		tmp = t_0;
	} else if (z <= 2e-63) {
		tmp = x / (y / (y - z));
	} 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 - (z * (x / y))
    if (z <= (-1d+23)) then
        tmp = t_0
    else if (z <= 2d-63) then
        tmp = x / (y / (y - z))
    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 - (z * (x / y));
	double tmp;
	if (z <= -1e+23) {
		tmp = t_0;
	} else if (z <= 2e-63) {
		tmp = x / (y / (y - z));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y - z)) / y
def code(x, y, z):
	t_0 = x - (z * (x / y))
	tmp = 0
	if z <= -1e+23:
		tmp = t_0
	elif z <= 2e-63:
		tmp = x / (y / (y - z))
	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(z * Float64(x / y)))
	tmp = 0.0
	if (z <= -1e+23)
		tmp = t_0;
	elseif (z <= 2e-63)
		tmp = Float64(x / Float64(y / Float64(y - z)));
	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 - (z * (x / y));
	tmp = 0.0;
	if (z <= -1e+23)
		tmp = t_0;
	elseif (z <= 2e-63)
		tmp = x / (y / (y - z));
	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[(z * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1e+23], t$95$0, If[LessEqual[z, 2e-63], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := x - z \cdot \frac{x}{y}\\
\mathbf{if}\;z \leq -1 \cdot 10^{+23}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 2 \cdot 10^{-63}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.5
Target3.1
Herbie1.8
\[\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 2 regimes
  2. if z < -9.9999999999999992e22 or 2.00000000000000013e-63 < z

    1. Initial program 11.1

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified3.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))): 51 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 47 points increase in error, 46 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 2 points increase in error, 2 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 68 points increase in error, 72 points decrease in error

    if -9.9999999999999992e22 < z < 2.00000000000000013e-63

    1. Initial program 13.7

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

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}} \]
      Proof
      (/.f64 x (/.f64 y (-.f64 y z))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 67 points increase in error, 34 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification1.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+23}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-63}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \end{array} \]

Alternatives

Alternative 1
Error18.9
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;y \leq -9.2 \cdot 10^{+35}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{+18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.96 \cdot 10^{-48}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error18.7
Cost912
\[\begin{array}{l} \mathbf{if}\;y \leq -3.3 \cdot 10^{+36}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{+19}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{elif}\;y \leq -8.4 \cdot 10^{-47}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{-39}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error18.7
Cost912
\[\begin{array}{l} \mathbf{if}\;y \leq -9.2 \cdot 10^{+35}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.25 \cdot 10^{+18}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{elif}\;y \leq -7.8 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-41}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error2.0
Cost712
\[\begin{array}{l} t_0 := x - z \cdot \frac{x}{y}\\ \mathbf{if}\;z \leq -3 \cdot 10^{-33}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-105}:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error3.7
Cost448
\[x \cdot \frac{y - z}{y} \]
Alternative 6
Error25.5
Cost64
\[x \]

Error

Reproduce

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