Average Error: 12.7 → 1.2
Time: 5.5s
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^{+305}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -1 \cdot 10^{-92}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 10^{-249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+295}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \frac{x}{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)) (t_1 (- x (/ z (/ y x)))))
   (if (<= t_0 -5e+305)
     t_1
     (if (<= t_0 -1e-92)
       t_0
       (if (<= t_0 1e-249)
         t_1
         (if (<= t_0 1e+295) t_0 (- x (* z (/ x 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 - (z / (y / x));
	double tmp;
	if (t_0 <= -5e+305) {
		tmp = t_1;
	} else if (t_0 <= -1e-92) {
		tmp = t_0;
	} else if (t_0 <= 1e-249) {
		tmp = t_1;
	} else if (t_0 <= 1e+295) {
		tmp = t_0;
	} else {
		tmp = x - (z * (x / 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) :: t_1
    real(8) :: tmp
    t_0 = (x * (y - z)) / y
    t_1 = x - (z / (y / x))
    if (t_0 <= (-5d+305)) then
        tmp = t_1
    else if (t_0 <= (-1d-92)) then
        tmp = t_0
    else if (t_0 <= 1d-249) then
        tmp = t_1
    else if (t_0 <= 1d+295) then
        tmp = t_0
    else
        tmp = x - (z * (x / 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 t_1 = x - (z / (y / x));
	double tmp;
	if (t_0 <= -5e+305) {
		tmp = t_1;
	} else if (t_0 <= -1e-92) {
		tmp = t_0;
	} else if (t_0 <= 1e-249) {
		tmp = t_1;
	} else if (t_0 <= 1e+295) {
		tmp = t_0;
	} else {
		tmp = x - (z * (x / 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 - (z / (y / x))
	tmp = 0
	if t_0 <= -5e+305:
		tmp = t_1
	elif t_0 <= -1e-92:
		tmp = t_0
	elif t_0 <= 1e-249:
		tmp = t_1
	elif t_0 <= 1e+295:
		tmp = t_0
	else:
		tmp = x - (z * (x / 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(z / Float64(y / x)))
	tmp = 0.0
	if (t_0 <= -5e+305)
		tmp = t_1;
	elseif (t_0 <= -1e-92)
		tmp = t_0;
	elseif (t_0 <= 1e-249)
		tmp = t_1;
	elseif (t_0 <= 1e+295)
		tmp = t_0;
	else
		tmp = Float64(x - Float64(z * Float64(x / 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 - (z / (y / x));
	tmp = 0.0;
	if (t_0 <= -5e+305)
		tmp = t_1;
	elseif (t_0 <= -1e-92)
		tmp = t_0;
	elseif (t_0 <= 1e-249)
		tmp = t_1;
	elseif (t_0 <= 1e+295)
		tmp = t_0;
	else
		tmp = x - (z * (x / 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[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+305], t$95$1, If[LessEqual[t$95$0, -1e-92], t$95$0, If[LessEqual[t$95$0, 1e-249], t$95$1, If[LessEqual[t$95$0, 1e+295], t$95$0, N[(x - N[(z * N[(x / 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{z}{\frac{y}{x}}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+305}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -1 \cdot 10^{-92}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 10^{-249}:\\
\;\;\;\;t_1\\

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.7
Target3.0
Herbie1.2
\[\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) < -5.00000000000000009e305 or -9.99999999999999988e-93 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.00000000000000005e-249

    1. Initial program 29.2

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

      \[\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))): 57 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 34 points increase in error, 52 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 5 points increase in error, 1 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 74 points increase in error, 72 points decrease in error
    3. Applied egg-rr2.8

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

    if -5.00000000000000009e305 < (/.f64 (*.f64 x (-.f64 y z)) y) < -9.99999999999999988e-93 or 1.00000000000000005e-249 < (/.f64 (*.f64 x (-.f64 y z)) y) < 9.9999999999999998e294

    1. Initial program 0.3

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

    if 9.9999999999999998e294 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 57.8

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

      \[\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))): 57 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 34 points increase in error, 52 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 5 points increase in error, 1 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 74 points increase in error, 72 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification1.2

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

Alternatives

Alternative 1
Error19.7
Cost912
\[\begin{array}{l} t_0 := \frac{x \cdot \left(-z\right)}{y}\\ \mathbf{if}\;z \leq -3.2 \cdot 10^{+87}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7 \cdot 10^{+34}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.672487080657242 \cdot 10^{-37}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error19.5
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -3.2 \cdot 10^{+87}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\ \mathbf{elif}\;z \leq -7 \cdot 10^{+34}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.672487080657242 \cdot 10^{-37}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error4.8
Cost712
\[\begin{array}{l} t_0 := x - \frac{z}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -6.283335327159574 \cdot 10^{-196}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.8032510996784576 \cdot 10^{-129}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error25.3
Cost64
\[x \]

Error

Reproduce

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