?

Average Error: 12.8 → 1.6
Time: 8.0s
Precision: binary64
Cost: 2576

?

\[\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 -5 \cdot 10^{+289}:\\ \;\;\;\;\left(1 - \frac{z}{y}\right) \cdot x\\ \mathbf{elif}\;t_0 \leq -5 \cdot 10^{+57}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;x - x \cdot \frac{z}{y}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+282}:\\ \;\;\;\;x + \left(-\frac{z \cdot x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \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 -5e+289)
     (* (- 1.0 (/ z y)) x)
     (if (<= t_0 -5e+57)
       t_0
       (if (<= t_0 0.0)
         (- x (* x (/ z y)))
         (if (<= t_0 5e+282) (+ x (- (/ (* z x) y))) x))))))
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 <= -5e+289) {
		tmp = (1.0 - (z / y)) * x;
	} else if (t_0 <= -5e+57) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = x - (x * (z / y));
	} else if (t_0 <= 5e+282) {
		tmp = x + -((z * x) / y);
	} else {
		tmp = x;
	}
	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 <= (-5d+289)) then
        tmp = (1.0d0 - (z / y)) * x
    else if (t_0 <= (-5d+57)) then
        tmp = t_0
    else if (t_0 <= 0.0d0) then
        tmp = x - (x * (z / y))
    else if (t_0 <= 5d+282) then
        tmp = x + -((z * x) / y)
    else
        tmp = x
    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 <= -5e+289) {
		tmp = (1.0 - (z / y)) * x;
	} else if (t_0 <= -5e+57) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = x - (x * (z / y));
	} else if (t_0 <= 5e+282) {
		tmp = x + -((z * x) / y);
	} else {
		tmp = x;
	}
	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 <= -5e+289:
		tmp = (1.0 - (z / y)) * x
	elif t_0 <= -5e+57:
		tmp = t_0
	elif t_0 <= 0.0:
		tmp = x - (x * (z / y))
	elif t_0 <= 5e+282:
		tmp = x + -((z * x) / y)
	else:
		tmp = x
	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 <= -5e+289)
		tmp = Float64(Float64(1.0 - Float64(z / y)) * x);
	elseif (t_0 <= -5e+57)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = Float64(x - Float64(x * Float64(z / y)));
	elseif (t_0 <= 5e+282)
		tmp = Float64(x + Float64(-Float64(Float64(z * x) / y)));
	else
		tmp = x;
	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 <= -5e+289)
		tmp = (1.0 - (z / y)) * x;
	elseif (t_0 <= -5e+57)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = x - (x * (z / y));
	elseif (t_0 <= 5e+282)
		tmp = x + -((z * x) / y);
	else
		tmp = x;
	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, -5e+289], N[(N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, -5e+57], t$95$0, If[LessEqual[t$95$0, 0.0], N[(x - N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+282], N[(x + (-N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision])), $MachinePrecision], x]]]]]
\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 -5 \cdot 10^{+289}:\\
\;\;\;\;\left(1 - \frac{z}{y}\right) \cdot x\\

\mathbf{elif}\;t_0 \leq -5 \cdot 10^{+57}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;x - x \cdot \frac{z}{y}\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+282}:\\
\;\;\;\;x + \left(-\frac{z \cdot x}{y}\right)\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.8
Target3.3
Herbie1.6
\[\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 5 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < -5.00000000000000031e289

    1. Initial program 57.3

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Taylor expanded in y around 0 19.0

      \[\leadsto \color{blue}{-1 \cdot \frac{z \cdot x}{y} + x} \]
    3. Simplified19.0

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

      [Start]19.0

      \[ -1 \cdot \frac{z \cdot x}{y} + x \]

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]19.0

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]19.0

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]19.0

      \[ x + \color{blue}{\left(-\frac{z \cdot x}{y}\right)} \]
    4. Taylor expanded in x around 0 1.4

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

    if -5.00000000000000031e289 < (/.f64 (*.f64 x (-.f64 y z)) y) < -4.99999999999999972e57

    1. Initial program 0.2

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

    if -4.99999999999999972e57 < (/.f64 (*.f64 x (-.f64 y z)) y) < -0.0

    1. Initial program 9.7

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Taylor expanded in y around 0 5.1

      \[\leadsto \color{blue}{-1 \cdot \frac{z \cdot x}{y} + x} \]
    3. Simplified5.1

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

      [Start]5.1

      \[ -1 \cdot \frac{z \cdot x}{y} + x \]

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]5.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]5.1

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]5.1

      \[ x + \color{blue}{\left(-\frac{z \cdot x}{y}\right)} \]
    4. Taylor expanded in x around 0 0.2

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

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

      [Start]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-13 [=>]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [<=]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-52 [=>]0.2

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

    if -0.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < 4.99999999999999978e282

    1. Initial program 0.4

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Taylor expanded in y around 0 0.2

      \[\leadsto \color{blue}{-1 \cdot \frac{z \cdot x}{y} + x} \]
    3. Simplified0.2

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

      [Start]0.2

      \[ -1 \cdot \frac{z \cdot x}{y} + x \]

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]0.2

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

    if 4.99999999999999978e282 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 55.8

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Taylor expanded in y around inf 15.4

      \[\leadsto \color{blue}{x} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification1.6

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

Alternatives

Alternative 1
Error1.7
Cost2512
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{+289}:\\ \;\;\;\;\left(1 - \frac{z}{y}\right) \cdot x\\ \mathbf{elif}\;t_0 \leq -5 \cdot 10^{+57}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{+70}:\\ \;\;\;\;x - x \cdot \frac{z}{y}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+282}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error18.7
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2 \cdot 10^{-57}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error3.2
Cost448
\[\left(1 - \frac{z}{y}\right) \cdot x \]
Alternative 4
Error3.2
Cost448
\[x - x \cdot \frac{z}{y} \]
Alternative 5
Error25.0
Cost64
\[x \]

Error

Reproduce?

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