?

Average Error: 6.7 → 1.4
Time: 17.7s
Precision: binary64
Cost: 2056

?

\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ t_2 := \frac{y - x}{t} \cdot z + x\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+288}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+298}:\\ \;\;\;\;x + \frac{z \cdot y + z \cdot \left(-x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ x (/ (* (- y x) z) t))) (t_2 (+ (* (/ (- y x) t) z) x)))
   (if (<= t_1 -2e+288)
     t_2
     (if (<= t_1 1e+298) (+ x (/ (+ (* z y) (* z (- x))) t)) t_2))))
double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
double code(double x, double y, double z, double t) {
	double t_1 = x + (((y - x) * z) / t);
	double t_2 = (((y - x) / t) * z) + x;
	double tmp;
	if (t_1 <= -2e+288) {
		tmp = t_2;
	} else if (t_1 <= 1e+298) {
		tmp = x + (((z * y) + (z * -x)) / t);
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x + (((y - x) * z) / t)
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = x + (((y - x) * z) / t)
    t_2 = (((y - x) / t) * z) + x
    if (t_1 <= (-2d+288)) then
        tmp = t_2
    else if (t_1 <= 1d+298) then
        tmp = x + (((z * y) + (z * -x)) / t)
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
public static double code(double x, double y, double z, double t) {
	double t_1 = x + (((y - x) * z) / t);
	double t_2 = (((y - x) / t) * z) + x;
	double tmp;
	if (t_1 <= -2e+288) {
		tmp = t_2;
	} else if (t_1 <= 1e+298) {
		tmp = x + (((z * y) + (z * -x)) / t);
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t):
	return x + (((y - x) * z) / t)
def code(x, y, z, t):
	t_1 = x + (((y - x) * z) / t)
	t_2 = (((y - x) / t) * z) + x
	tmp = 0
	if t_1 <= -2e+288:
		tmp = t_2
	elif t_1 <= 1e+298:
		tmp = x + (((z * y) + (z * -x)) / t)
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t)
	return Float64(x + Float64(Float64(Float64(y - x) * z) / t))
end
function code(x, y, z, t)
	t_1 = Float64(x + Float64(Float64(Float64(y - x) * z) / t))
	t_2 = Float64(Float64(Float64(Float64(y - x) / t) * z) + x)
	tmp = 0.0
	if (t_1 <= -2e+288)
		tmp = t_2;
	elseif (t_1 <= 1e+298)
		tmp = Float64(x + Float64(Float64(Float64(z * y) + Float64(z * Float64(-x))) / t));
	else
		tmp = t_2;
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x + (((y - x) * z) / t);
end
function tmp_2 = code(x, y, z, t)
	t_1 = x + (((y - x) * z) / t);
	t_2 = (((y - x) / t) * z) + x;
	tmp = 0.0;
	if (t_1 <= -2e+288)
		tmp = t_2;
	elseif (t_1 <= 1e+298)
		tmp = x + (((z * y) + (z * -x)) / t);
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision] * z), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+288], t$95$2, If[LessEqual[t$95$1, 1e+298], N[(x + N[(N[(N[(z * y), $MachinePrecision] + N[(z * (-x)), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\
t_2 := \frac{y - x}{t} \cdot z + x\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+288}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 10^{+298}:\\
\;\;\;\;x + \frac{z \cdot y + z \cdot \left(-x\right)}{t}\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.7
Target2.0
Herbie1.4
\[\begin{array}{l} \mathbf{if}\;x < -9.025511195533005 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x < 4.275032163700715 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -2e288 or 9.9999999999999996e297 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 49.0

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

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

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

    if -2e288 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 9.9999999999999996e297

    1. Initial program 0.8

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

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

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

      [Start]0.8

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

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

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

      rational.json-simplify-43 [=>]0.8

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

      rational.json-simplify-8 [<=]0.8

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

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

Alternatives

Alternative 1
Error2.6
Cost1864
\[\begin{array}{l} t_1 := \frac{y}{t} \cdot z + x\\ t_2 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+291}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error1.4
Cost1864
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ t_2 := \frac{y - x}{t} \cdot z + x\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+288}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+298}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error27.9
Cost1176
\[\begin{array}{l} t_1 := \frac{z \cdot \left(-x\right)}{t}\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{+87}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{+56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.9 \cdot 10^{-133}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.3 \cdot 10^{-185}:\\ \;\;\;\;\frac{z \cdot y}{t}\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{-19}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{+36}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error11.6
Cost976
\[\begin{array}{l} t_1 := x \cdot \left(1 - \frac{z}{t}\right)\\ t_2 := \frac{y}{t} \cdot z + x\\ \mathbf{if}\;y \leq -9.5 \cdot 10^{-66}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.4 \cdot 10^{-239}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-207}:\\ \;\;\;\;\frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-52}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error17.7
Cost712
\[\begin{array}{l} t_1 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -4.8 \cdot 10^{-134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-213}:\\ \;\;\;\;\frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error11.1
Cost712
\[\begin{array}{l} t_1 := x + \frac{z \cdot y}{t}\\ \mathbf{if}\;y \leq -7.2 \cdot 10^{-66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{-51}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error10.8
Cost712
\[\begin{array}{l} t_1 := \frac{y}{t} \cdot z + x\\ \mathbf{if}\;y \leq -8.2 \cdot 10^{-66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-51}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error26.6
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-134}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.3 \cdot 10^{-185}:\\ \;\;\;\;\frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error32.0
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023077 
(FPCore (x y z t)
  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))

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