?

Average Error: 10.4 → 0.2
Time: 15.6s
Precision: binary64
Cost: 904

?

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

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.4
Target0.5
Herbie0.2
\[\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 2 regimes
  2. if z < -5.0000000000000001e26 or 2.4e58 < z

    1. Initial program 19.1

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

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

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

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

    if -5.0000000000000001e26 < z < 2.4e58

    1. Initial program 0.6

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

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

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

      [Start]0.3

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

      rational_best.json-simplify-1 [<=]0.3

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

      rational_best.json-simplify-2 [=>]0.3

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

      rational_best.json-simplify-2 [=>]0.3

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

      rational_best.json-simplify-12 [=>]0.3

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

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

Alternatives

Alternative 1
Error12.9
Cost1440
\[\begin{array}{l} t_0 := \frac{x}{z} + \left(-x\right)\\ t_1 := \frac{y \cdot x}{z}\\ \mathbf{if}\;y \leq -1.9 \cdot 10^{+192}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{+171}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq -1.8 \cdot 10^{+150}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1400000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4 \cdot 10^{+30}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.15 \cdot 10^{+145}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error21.3
Cost980
\[\begin{array}{l} t_0 := \frac{y \cdot x}{z}\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -1 \cdot 10^{-201}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-261}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.06 \cdot 10^{-187}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+14}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 3
Error0.3
Cost840
\[\begin{array}{l} t_0 := \left(\frac{y}{z} - 1\right) \cdot x\\ \mathbf{if}\;z \leq -9.2 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+58}:\\ \;\;\;\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error4.1
Cost712
\[\begin{array}{l} t_0 := \left(\frac{y}{z} - 1\right) \cdot x\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.0069:\\ \;\;\;\;\frac{x}{z} + \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.0
Cost712
\[\begin{array}{l} t_0 := \left(\frac{y}{z} - 1\right) \cdot x\\ \mathbf{if}\;z \leq -1.05:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.05:\\ \;\;\;\;\frac{\left(1 + y\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error19.1
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 2.05:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 7
Error33.3
Cost128
\[-x \]

Error

Reproduce?

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