?

Average Error: 12.9 → 2.0
Time: 6.3s
Precision: binary64
Cost: 840

?

\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-20}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-200}:\\ \;\;\;\;x - \frac{1}{y} \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (if (<= y -5e-20)
   (- x (/ x (/ y z)))
   (if (<= y 7.2e-200) (- x (* (/ 1.0 y) (* x z))) (/ x (/ y (- y z))))))
double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
	double tmp;
	if (y <= -5e-20) {
		tmp = x - (x / (y / z));
	} else if (y <= 7.2e-200) {
		tmp = x - ((1.0 / y) * (x * z));
	} else {
		tmp = x / (y / (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) :: tmp
    if (y <= (-5d-20)) then
        tmp = x - (x / (y / z))
    else if (y <= 7.2d-200) then
        tmp = x - ((1.0d0 / y) * (x * z))
    else
        tmp = x / (y / (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 tmp;
	if (y <= -5e-20) {
		tmp = x - (x / (y / z));
	} else if (y <= 7.2e-200) {
		tmp = x - ((1.0 / y) * (x * z));
	} else {
		tmp = x / (y / (y - z));
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y - z)) / y
def code(x, y, z):
	tmp = 0
	if y <= -5e-20:
		tmp = x - (x / (y / z))
	elif y <= 7.2e-200:
		tmp = x - ((1.0 / y) * (x * z))
	else:
		tmp = x / (y / (y - z))
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(y - z)) / y)
end
function code(x, y, z)
	tmp = 0.0
	if (y <= -5e-20)
		tmp = Float64(x - Float64(x / Float64(y / z)));
	elseif (y <= 7.2e-200)
		tmp = Float64(x - Float64(Float64(1.0 / y) * Float64(x * z)));
	else
		tmp = Float64(x / Float64(y / 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)
	tmp = 0.0;
	if (y <= -5e-20)
		tmp = x - (x / (y / z));
	elseif (y <= 7.2e-200)
		tmp = x - ((1.0 / y) * (x * z));
	else
		tmp = x / (y / (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_] := If[LessEqual[y, -5e-20], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.2e-200], N[(x - N[(N[(1.0 / y), $MachinePrecision] * N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-20}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.9
Target3.4
Herbie2.0
\[\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 y < -4.9999999999999999e-20

    1. Initial program 16.5

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

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

      [Start]16.5

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

      associate-*r/ [<=]0.1

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

      div-sub [=>]0.1

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

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

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

      *-inverses [=>]0.1

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

      *-lft-identity [=>]0.1

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

      associate-*l/ [=>]5.4

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

      *-commutative [<=]5.4

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

      associate-/l* [=>]0.1

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

    if -4.9999999999999999e-20 < y < 7.2000000000000003e-200

    1. Initial program 8.3

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

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

      [Start]8.3

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

      associate-*r/ [<=]9.5

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

      div-sub [=>]9.5

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

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

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

      *-inverses [=>]9.5

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

      *-lft-identity [=>]9.5

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

      associate-*l/ [=>]5.1

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

      *-commutative [<=]5.1

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

      associate-/l* [=>]8.8

      \[ x - \color{blue}{\frac{x}{\frac{y}{z}}} \]
    3. Applied egg-rr5.2

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

    if 7.2000000000000003e-200 < y

    1. Initial program 13.0

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

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

      [Start]13.0

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

      associate-/l* [=>]1.5

      \[ \color{blue}{\frac{x}{\frac{y}{y - z}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-20}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-200}:\\ \;\;\;\;x - \frac{1}{y} \cdot \left(x \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \end{array} \]

Alternatives

Alternative 1
Error2.4
Cost1480
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;x\\ \mathbf{elif}\;t_0 \leq -500000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 2
Error20.1
Cost1177
\[\begin{array}{l} \mathbf{if}\;y \leq -2.1 \cdot 10^{+45}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.3 \cdot 10^{+28}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{elif}\;y \leq -950:\\ \;\;\;\;\frac{y \cdot x}{y}\\ \mathbf{elif}\;y \leq -7 \cdot 10^{-166} \lor \neg \left(y \leq -4.5 \cdot 10^{-213}\right) \land y \leq 7.6 \cdot 10^{-103}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error20.3
Cost913
\[\begin{array}{l} \mathbf{if}\;y \leq -2.1 \cdot 10^{+45}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-168} \lor \neg \left(y \leq -3.2 \cdot 10^{-214}\right) \land y \leq 5.5 \cdot 10^{-103}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error3.0
Cost448
\[x - \frac{x}{\frac{y}{z}} \]
Alternative 5
Error25.8
Cost64
\[x \]

Error

Reproduce?

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