?

Average Error: 10.0 → 0.1
Time: 14.0s
Precision: binary64
Cost: 968

?

\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -5.5 \cdot 10^{-25}:\\ \;\;\;\;x \cdot \left(-1 + \frac{1 + y}{z}\right)\\ \mathbf{elif}\;z \leq 100000000:\\ \;\;\;\;\left(\left(y - z\right) + 1\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-1 + \frac{1}{z} \cdot \left(1 + y\right)\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= z -5.5e-25)
   (* x (+ -1.0 (/ (+ 1.0 y) z)))
   (if (<= z 100000000.0)
     (* (+ (- y z) 1.0) (/ x z))
     (* x (+ -1.0 (* (/ 1.0 z) (+ 1.0 y)))))))
double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
	double tmp;
	if (z <= -5.5e-25) {
		tmp = x * (-1.0 + ((1.0 + y) / z));
	} else if (z <= 100000000.0) {
		tmp = ((y - z) + 1.0) * (x / z);
	} else {
		tmp = x * (-1.0 + ((1.0 / z) * (1.0 + 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) + 1.0d0)) / z
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 (z <= (-5.5d-25)) then
        tmp = x * ((-1.0d0) + ((1.0d0 + y) / z))
    else if (z <= 100000000.0d0) then
        tmp = ((y - z) + 1.0d0) * (x / z)
    else
        tmp = x * ((-1.0d0) + ((1.0d0 / z) * (1.0d0 + y)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -5.5e-25) {
		tmp = x * (-1.0 + ((1.0 + y) / z));
	} else if (z <= 100000000.0) {
		tmp = ((y - z) + 1.0) * (x / z);
	} else {
		tmp = x * (-1.0 + ((1.0 / z) * (1.0 + y)));
	}
	return tmp;
}
def code(x, y, z):
	return (x * ((y - z) + 1.0)) / z
def code(x, y, z):
	tmp = 0
	if z <= -5.5e-25:
		tmp = x * (-1.0 + ((1.0 + y) / z))
	elif z <= 100000000.0:
		tmp = ((y - z) + 1.0) * (x / z)
	else:
		tmp = x * (-1.0 + ((1.0 / z) * (1.0 + y)))
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z)
end
function code(x, y, z)
	tmp = 0.0
	if (z <= -5.5e-25)
		tmp = Float64(x * Float64(-1.0 + Float64(Float64(1.0 + y) / z)));
	elseif (z <= 100000000.0)
		tmp = Float64(Float64(Float64(y - z) + 1.0) * Float64(x / z));
	else
		tmp = Float64(x * Float64(-1.0 + Float64(Float64(1.0 / z) * Float64(1.0 + y))));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * ((y - z) + 1.0)) / z;
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -5.5e-25)
		tmp = x * (-1.0 + ((1.0 + y) / z));
	elseif (z <= 100000000.0)
		tmp = ((y - z) + 1.0) * (x / z);
	else
		tmp = x * (-1.0 + ((1.0 / z) * (1.0 + y)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[z, -5.5e-25], N[(x * N[(-1.0 + N[(N[(1.0 + y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 100000000.0], N[(N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(-1.0 + N[(N[(1.0 / z), $MachinePrecision] * N[(1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{-25}:\\
\;\;\;\;x \cdot \left(-1 + \frac{1 + y}{z}\right)\\

\mathbf{elif}\;z \leq 100000000:\\
\;\;\;\;\left(\left(y - z\right) + 1\right) \cdot \frac{x}{z}\\

\mathbf{else}:\\
\;\;\;\;x \cdot \left(-1 + \frac{1}{z} \cdot \left(1 + y\right)\right)\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.0
Target0.4
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x < 3.874108816439546 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if z < -5.50000000000000004e-25

    1. Initial program 15.5

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

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

      [Start]15.5

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

      rational.json-simplify-2 [=>]15.5

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

      rational.json-simplify-49 [=>]0.2

      \[ \color{blue}{x \cdot \frac{\left(y - z\right) + 1}{z}} \]
    3. Applied egg-rr0.1

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

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

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

      [Start]5.1

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

      rational.json-simplify-1 [=>]5.1

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

      rational.json-simplify-49 [=>]0.2

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

      rational.json-simplify-51 [=>]0.2

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

    if -5.50000000000000004e-25 < z < 1e8

    1. Initial program 0.1

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

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

      [Start]0.1

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

      rational.json-simplify-49 [=>]0.1

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

    if 1e8 < z

    1. Initial program 17.1

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

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

      [Start]17.1

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

      rational.json-simplify-2 [=>]17.1

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

      rational.json-simplify-49 [=>]0.1

      \[ \color{blue}{x \cdot \frac{\left(y - z\right) + 1}{z}} \]
    3. Applied egg-rr0.1

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

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

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

      [Start]6.3

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

      rational.json-simplify-1 [=>]6.3

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

      rational.json-simplify-49 [=>]0.1

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

      rational.json-simplify-51 [=>]0.1

      \[ \color{blue}{x \cdot \left(-1 + \frac{1 + y}{z}\right)} \]
    6. Applied egg-rr0.1

      \[\leadsto x \cdot \left(-1 + \color{blue}{\frac{1}{z} \cdot \left(1 + y\right)}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

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

Alternatives

Alternative 1
Error20.9
Cost852
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;z \leq -2 \cdot 10^{+52}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -4.1 \cdot 10^{-10}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4 \cdot 10^{-171}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{-301}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 60000000:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 2
Error11.7
Cost848
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -9 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+56}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+136}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{+165}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error11.8
Cost848
\[\begin{array}{l} t_0 := \frac{y}{\frac{z}{x}}\\ \mathbf{if}\;y \leq -1.55 \cdot 10^{+60}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{+56}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+136}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.12 \cdot 10^{+169}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.1
Cost840
\[\begin{array}{l} t_0 := x \cdot \left(-1 + \frac{1 + y}{z}\right)\\ \mathbf{if}\;z \leq -6 \cdot 10^{-25}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 500000000000:\\ \;\;\;\;\left(\left(y - z\right) + 1\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error4.6
Cost712
\[\begin{array}{l} t_0 := x \cdot \left(-1 + \frac{y}{z}\right)\\ \mathbf{if}\;y \leq -2300000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-15}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error19.6
Cost588
\[\begin{array}{l} \mathbf{if}\;z \leq -1.9 \cdot 10^{+54}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -4.3 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;z \leq 60000000:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 7
Error3.8
Cost576
\[x \cdot \left(-1 + \frac{1 + y}{z}\right) \]
Alternative 8
Error19.3
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -9.2 \cdot 10^{-5}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 60000000:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 9
Error33.5
Cost128
\[-x \]

Error

Reproduce?

herbie shell --seed 2023075 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

  (/ (* x (+ (- y z) 1.0)) z))