Average Error: 12.1 → 1.8
Time: 5.2s
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 10^{-28}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+264}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y - z}{y}\\ \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 1e-28)
     (/ x (/ y (- y z)))
     (if (<= t_0 2e+264) (- x (/ (* x z) y)) (* x (/ (- y 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 tmp;
	if (t_0 <= 1e-28) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= 2e+264) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x * ((y - z) / y);
	}
	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 <= 1d-28) then
        tmp = x / (y / (y - z))
    else if (t_0 <= 2d+264) then
        tmp = x - ((x * z) / y)
    else
        tmp = x * ((y - z) / y)
    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 <= 1e-28) {
		tmp = x / (y / (y - z));
	} else if (t_0 <= 2e+264) {
		tmp = x - ((x * z) / y);
	} else {
		tmp = x * ((y - 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
	tmp = 0
	if t_0 <= 1e-28:
		tmp = x / (y / (y - z))
	elif t_0 <= 2e+264:
		tmp = x - ((x * z) / y)
	else:
		tmp = x * ((y - 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)
	tmp = 0.0
	if (t_0 <= 1e-28)
		tmp = Float64(x / Float64(y / Float64(y - z)));
	elseif (t_0 <= 2e+264)
		tmp = Float64(x - Float64(Float64(x * z) / y));
	else
		tmp = Float64(x * Float64(Float64(y - 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;
	tmp = 0.0;
	if (t_0 <= 1e-28)
		tmp = x / (y / (y - z));
	elseif (t_0 <= 2e+264)
		tmp = x - ((x * z) / y);
	else
		tmp = x * ((y - 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]}, If[LessEqual[t$95$0, 1e-28], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+264], N[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]]
\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 10^{-28}:\\
\;\;\;\;\frac{x}{\frac{y}{y - z}}\\

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

\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y - z}{y}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.1
Target2.8
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 3 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < 9.99999999999999971e-29

    1. Initial program 10.8

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

      \[\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)): 74 points increase in error, 26 points decrease in error

    if 9.99999999999999971e-29 < (/.f64 (*.f64 x (-.f64 y z)) y) < 2.00000000000000009e264

    1. Initial program 0.2

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

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

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

    if 2.00000000000000009e264 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 48.8

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

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

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

Alternatives

Alternative 1
Error19.6
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;y \leq -2.2 \cdot 10^{+43}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.15 \cdot 10^{-49}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-29}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 76:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error19.7
Cost912
\[\begin{array}{l} \mathbf{if}\;y \leq -2.2 \cdot 10^{+43}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{-49}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-28}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{+16}:\\ \;\;\;\;x \cdot \frac{-z}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error2.7
Cost712
\[\begin{array}{l} t_0 := x \cdot \frac{y - z}{y}\\ \mathbf{if}\;z \leq -1.3 \cdot 10^{+235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.06 \cdot 10^{+127}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error2.4
Cost712
\[\begin{array}{l} t_0 := x \cdot \frac{y - z}{y}\\ \mathbf{if}\;y \leq 3.4 \cdot 10^{-261}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-49}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error3.2
Cost448
\[x \cdot \frac{y - z}{y} \]
Alternative 6
Error25.5
Cost64
\[x \]

Error

Reproduce

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