Average Error: 6.9 → 1.0
Time: 12.3s
Precision: binary64
Cost: 1864
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+291}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+304}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y - x}}\\ \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))))
   (if (<= t_1 -2e+291)
     (+ x (/ (- y x) (/ t z)))
     (if (<= t_1 5e+304) t_1 (+ x (/ z (/ t (- y x))))))))
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 tmp;
	if (t_1 <= -2e+291) {
		tmp = x + ((y - x) / (t / z));
	} else if (t_1 <= 5e+304) {
		tmp = t_1;
	} else {
		tmp = x + (z / (t / (y - x)));
	}
	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) :: tmp
    t_1 = x + (((y - x) * z) / t)
    if (t_1 <= (-2d+291)) then
        tmp = x + ((y - x) / (t / z))
    else if (t_1 <= 5d+304) then
        tmp = t_1
    else
        tmp = x + (z / (t / (y - x)))
    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 tmp;
	if (t_1 <= -2e+291) {
		tmp = x + ((y - x) / (t / z));
	} else if (t_1 <= 5e+304) {
		tmp = t_1;
	} else {
		tmp = x + (z / (t / (y - x)));
	}
	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)
	tmp = 0
	if t_1 <= -2e+291:
		tmp = x + ((y - x) / (t / z))
	elif t_1 <= 5e+304:
		tmp = t_1
	else:
		tmp = x + (z / (t / (y - x)))
	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))
	tmp = 0.0
	if (t_1 <= -2e+291)
		tmp = Float64(x + Float64(Float64(y - x) / Float64(t / z)));
	elseif (t_1 <= 5e+304)
		tmp = t_1;
	else
		tmp = Float64(x + Float64(z / Float64(t / Float64(y - x))));
	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);
	tmp = 0.0;
	if (t_1 <= -2e+291)
		tmp = x + ((y - x) / (t / z));
	elseif (t_1 <= 5e+304)
		tmp = t_1;
	else
		tmp = x + (z / (t / (y - x)));
	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]}, If[LessEqual[t$95$1, -2e+291], N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+304], t$95$1, N[(x + N[(z / N[(t / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+291}:\\
\;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+304}:\\
\;\;\;\;t_1\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.9
Target1.9
Herbie1.0
\[\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 3 regimes
  2. if (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -1.9999999999999999e291

    1. Initial program 48.2

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Applied egg-rr1.9

      \[\leadsto x + \color{blue}{\left(\frac{y}{\frac{t}{z}} - \frac{x}{\frac{t}{z}}\right)} \]
    3. Applied egg-rr1.9

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

    if -1.9999999999999999e291 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 4.9999999999999997e304

    1. Initial program 0.9

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

    if 4.9999999999999997e304 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 58.6

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

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

      \[\leadsto x + \color{blue}{\frac{z}{\frac{t}{y - x}}} \]
      Proof
      (/.f64 z (/.f64 t (-.f64 y x))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 z t) (-.f64 y x))): 50 points increase in error, 60 points decrease in error
      (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 y (/.f64 z t)) (*.f64 x (/.f64 z t)))): 2 points increase in error, 1 points decrease in error
      (-.f64 (*.f64 y (/.f64 z t)) (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x z) t))): 39 points increase in error, 19 points decrease in error
      (-.f64 (*.f64 y (/.f64 z t)) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 z x)) t)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (*.f64 y (/.f64 z t)) (neg.f64 (/.f64 (*.f64 z x) t)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y z) t)) (neg.f64 (/.f64 (*.f64 z x) t))): 26 points increase in error, 28 points decrease in error
      (+.f64 (/.f64 (*.f64 y z) t) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 z x) t)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 z x) t)) (/.f64 (*.f64 y z) t))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification1.0

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

Alternatives

Alternative 1
Error28.6
Cost1112
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6438284736016326 \cdot 10^{+54}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.1283570698179975 \cdot 10^{-42}:\\ \;\;\;\;\frac{z}{\frac{-t}{x}}\\ \mathbf{elif}\;x \leq -2.1800384038544185 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.743296979692854 \cdot 10^{-161}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 1.7271485835444998 \cdot 10^{-92}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.1130836454440602 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error28.6
Cost1112
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6438284736016326 \cdot 10^{+54}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.1283570698179975 \cdot 10^{-42}:\\ \;\;\;\;\frac{-x \cdot z}{t}\\ \mathbf{elif}\;x \leq -2.1800384038544185 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.743296979692854 \cdot 10^{-161}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 1.7271485835444998 \cdot 10^{-92}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.1130836454440602 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error21.4
Cost1108
\[\begin{array}{l} t_1 := x - \frac{x \cdot z}{t}\\ \mathbf{if}\;x \leq -7.79245494227672 \cdot 10^{-106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.743296979692854 \cdot 10^{-161}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 1.7271485835444998 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.1130836454440602 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{+146}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error19.7
Cost1108
\[\begin{array}{l} t_1 := x - \frac{x \cdot z}{t}\\ \mathbf{if}\;x \leq -7.79245494227672 \cdot 10^{-106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.743296979692854 \cdot 10^{-161}:\\ \;\;\;\;\frac{z}{\frac{t}{y - x}}\\ \mathbf{elif}\;x \leq 1.7271485835444998 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.1130836454440602 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{+146}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error16.8
Cost976
\[\begin{array}{l} t_1 := \frac{z}{\frac{t}{y - x}}\\ t_2 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -7.79245494227672 \cdot 10^{-106}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.743296979692854 \cdot 10^{-161}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.7271485835444998 \cdot 10^{-92}:\\ \;\;\;\;x - \frac{x \cdot z}{t}\\ \mathbf{elif}\;x \leq 9.5 \cdot 10^{-23}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error11.9
Cost976
\[\begin{array}{l} t_1 := x + \frac{y \cdot z}{t}\\ t_2 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -1.517835350827096 \cdot 10^{-101}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.620829357257797 \cdot 10^{-238}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -9.690031492643755 \cdot 10^{-268}:\\ \;\;\;\;\frac{z}{\frac{t}{y - x}}\\ \mathbf{elif}\;x \leq 6.586159687545671 \cdot 10^{+37}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error26.6
Cost848
\[\begin{array}{l} t_1 := \frac{y}{\frac{t}{z}}\\ \mathbf{if}\;x \leq -2.1800384038544185 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.743296979692854 \cdot 10^{-161}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.7271485835444998 \cdot 10^{-92}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.1130836454440602 \cdot 10^{-56}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error27.0
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1800384038544185 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.743296979692854 \cdot 10^{-161}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 1.7271485835444998 \cdot 10^{-92}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.1130836454440602 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error2.1
Cost840
\[\begin{array}{l} t_1 := x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{if}\;x \leq -9.690031492643755 \cdot 10^{-268}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.465941850898993 \cdot 10^{-257}:\\ \;\;\;\;x + \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error10.5
Cost712
\[\begin{array}{l} t_1 := x + z \cdot \frac{y}{t}\\ \mathbf{if}\;t \leq -5.8 \cdot 10^{-83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4 \cdot 10^{-106}:\\ \;\;\;\;\frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error31.7
Cost64
\[x \]

Error

Reproduce

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