?

Average Error: 19.39% → 4.35%
Time: 4.7s
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^{-60}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;t_0 \leq 10^{+290}:\\ \;\;\;\;t_0\\ \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 1e-60) (- x (/ x (/ y z))) (if (<= t_0 1e+290) t_0 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 <= 1e-60) {
		tmp = x - (x / (y / z));
	} else if (t_0 <= 1e+290) {
		tmp = t_0;
	} 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 <= 1d-60) then
        tmp = x - (x / (y / z))
    else if (t_0 <= 1d+290) then
        tmp = t_0
    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 <= 1e-60) {
		tmp = x - (x / (y / z));
	} else if (t_0 <= 1e+290) {
		tmp = t_0;
	} 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 <= 1e-60:
		tmp = x - (x / (y / z))
	elif t_0 <= 1e+290:
		tmp = t_0
	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 <= 1e-60)
		tmp = Float64(x - Float64(x / Float64(y / z)));
	elseif (t_0 <= 1e+290)
		tmp = t_0;
	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 <= 1e-60)
		tmp = x - (x / (y / z));
	elseif (t_0 <= 1e+290)
		tmp = t_0;
	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, 1e-60], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+290], t$95$0, 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 10^{-60}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.39%
Target5.23%
Herbie4.35%
\[\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.9999999999999997e-61

    1. Initial program 18.25

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

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

      [Start]18.25

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

      associate-*r/ [<=]3.98

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

      div-sub [=>]3.97

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

      distribute-rgt-out-- [<=]3.96

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

      *-inverses [=>]3.96

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

      *-lft-identity [=>]3.96

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

      associate-*l/ [=>]7.61

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

      *-commutative [<=]7.61

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

      associate-/l* [=>]3.64

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

    if 9.9999999999999997e-61 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.00000000000000006e290

    1. Initial program 0.37

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

    if 1.00000000000000006e290 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 87.99

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

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

      [Start]87.99

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

      *-commutative [=>]87.99

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

      associate-*r/ [<=]7.18

      \[ \color{blue}{\left(y - z\right) \cdot \frac{x}{y}} \]
    3. Taylor expanded in y around inf 22.65

      \[\leadsto \color{blue}{x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification4.35

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

Alternatives

Alternative 1
Error11.57%
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{+141}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+157}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error29.08%
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -6.4 \cdot 10^{-38}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-13}:\\ \;\;\;\;z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error4.81%
Cost448
\[x - \frac{x}{\frac{y}{z}} \]
Alternative 4
Error39.25%
Cost64
\[x \]

Error

Reproduce?

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