Average Error: 12.7 → 2.2
Time: 6.3s
Precision: binary64
Cost: 844
\[\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^{+90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-146}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+274}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \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+90)
     t_0
     (if (<= z 4e-146)
       (* x (- 1.0 (/ z y)))
       (if (<= z 2.1e+274) t_0 (/ (- x) (/ y z)))))))
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+90) {
		tmp = t_0;
	} else if (z <= 4e-146) {
		tmp = x * (1.0 - (z / y));
	} else if (z <= 2.1e+274) {
		tmp = t_0;
	} else {
		tmp = -x / (y / z);
	}
	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+90)) then
        tmp = t_0
    else if (z <= 4d-146) then
        tmp = x * (1.0d0 - (z / y))
    else if (z <= 2.1d+274) then
        tmp = t_0
    else
        tmp = -x / (y / z)
    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+90) {
		tmp = t_0;
	} else if (z <= 4e-146) {
		tmp = x * (1.0 - (z / y));
	} else if (z <= 2.1e+274) {
		tmp = t_0;
	} else {
		tmp = -x / (y / z);
	}
	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+90:
		tmp = t_0
	elif z <= 4e-146:
		tmp = x * (1.0 - (z / y))
	elif z <= 2.1e+274:
		tmp = t_0
	else:
		tmp = -x / (y / z)
	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+90)
		tmp = t_0;
	elseif (z <= 4e-146)
		tmp = Float64(x * Float64(1.0 - Float64(z / y)));
	elseif (z <= 2.1e+274)
		tmp = t_0;
	else
		tmp = Float64(Float64(-x) / Float64(y / z));
	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+90)
		tmp = t_0;
	elseif (z <= 4e-146)
		tmp = x * (1.0 - (z / y));
	elseif (z <= 2.1e+274)
		tmp = t_0;
	else
		tmp = -x / (y / z);
	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+90], t$95$0, If[LessEqual[z, 4e-146], N[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.1e+274], t$95$0, N[((-x) / N[(y / z), $MachinePrecision]), $MachinePrecision]]]]]
\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^{+90}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 4 \cdot 10^{-146}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\

\mathbf{elif}\;z \leq 2.1 \cdot 10^{+274}:\\
\;\;\;\;t_0\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.7
Target3.2
Herbie2.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 z < -9.99999999999999966e89 or 4.0000000000000001e-146 < z < 2.10000000000000016e274

    1. Initial program 11.7

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

      \[\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))): 52 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, 44 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 6 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 66 points increase in error, 71 points decrease in error

    if -9.99999999999999966e89 < z < 4.0000000000000001e-146

    1. Initial program 13.4

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

      \[\leadsto \color{blue}{x \cdot \left(1 - \frac{z}{y}\right)} \]
      Proof
      (*.f64 x (-.f64 1 (/.f64 z y))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (-.f64 (Rewrite<= *-inverses_binary64 (/.f64 y y)) (/.f64 z y))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= div-sub_binary64 (/.f64 (-.f64 y z) y))): 1 points increase in error, 1 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 73 points increase in error, 30 points decrease in error

    if 2.10000000000000016e274 < z

    1. Initial program 17.4

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified13.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))): 52 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, 44 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 6 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 66 points increase in error, 71 points decrease in error
    3. Taylor expanded in z around inf 20.1

      \[\leadsto \color{blue}{-1 \cdot \frac{z \cdot x}{y}} \]
    4. Simplified20.8

      \[\leadsto \color{blue}{\frac{-x}{\frac{y}{z}}} \]
      Proof
      (/.f64 (neg.f64 x) (/.f64 y z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (neg.f64 x) z) y)): 46 points increase in error, 55 points decrease in error
      (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 z (neg.f64 x))) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite=> distribute-rgt-neg-out_binary64 (neg.f64 (*.f64 z x))) y): 0 points increase in error, 0 points decrease in error
      (Rewrite=> distribute-frac-neg_binary64 (neg.f64 (/.f64 (*.f64 z x) y))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 z x) y))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification2.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+90}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-146}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+274}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \end{array} \]

Alternatives

Alternative 1
Error19.7
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -1.8 \cdot 10^{+89}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{-104}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-140}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{+80}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error19.7
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -5.4 \cdot 10^{+90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-104}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-140}:\\ \;\;\;\;\frac{x}{y \cdot \frac{-1}{z}}\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{+81}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error2.4
Cost712
\[\begin{array}{l} t_0 := \frac{x}{\frac{y}{y - z}}\\ \mathbf{if}\;x \leq -2.05 \cdot 10^{-280}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+70}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error18.6
Cost648
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -4.4 \cdot 10^{+90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+84}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error5.0
Cost448
\[x - z \cdot \frac{x}{y} \]
Alternative 6
Error25.0
Cost64
\[x \]

Error

Reproduce

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