Average Error: 6.4 → 0.9
Time: 12.1s
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}\\ t_2 := x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{+296}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+299}:\\ \;\;\;\;t_1\\ \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 (+ x (/ (- y x) (/ t z)))))
   (if (<= t_1 -4e+296) t_2 (if (<= t_1 1e+299) t_1 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 = x + ((y - x) / (t / z));
	double tmp;
	if (t_1 <= -4e+296) {
		tmp = t_2;
	} else if (t_1 <= 1e+299) {
		tmp = t_1;
	} 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 = x + ((y - x) / (t / z))
    if (t_1 <= (-4d+296)) then
        tmp = t_2
    else if (t_1 <= 1d+299) then
        tmp = t_1
    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 = x + ((y - x) / (t / z));
	double tmp;
	if (t_1 <= -4e+296) {
		tmp = t_2;
	} else if (t_1 <= 1e+299) {
		tmp = t_1;
	} 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 = x + ((y - x) / (t / z))
	tmp = 0
	if t_1 <= -4e+296:
		tmp = t_2
	elif t_1 <= 1e+299:
		tmp = t_1
	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(x + Float64(Float64(y - x) / Float64(t / z)))
	tmp = 0.0
	if (t_1 <= -4e+296)
		tmp = t_2;
	elseif (t_1 <= 1e+299)
		tmp = t_1;
	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 = x + ((y - x) / (t / z));
	tmp = 0.0;
	if (t_1 <= -4e+296)
		tmp = t_2;
	elseif (t_1 <= 1e+299)
		tmp = t_1;
	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[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+296], t$95$2, If[LessEqual[t$95$1, 1e+299], t$95$1, 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 := x + \frac{y - x}{\frac{t}{z}}\\
\mathbf{if}\;t_1 \leq -4 \cdot 10^{+296}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 10^{+299}:\\
\;\;\;\;t_1\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.4
Target2.1
Herbie0.9
\[\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)) < -3.99999999999999993e296 or 1.0000000000000001e299 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 52.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
      Proof
      (fma.f64 (-.f64 y x) (/.f64 z t) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y x) (/.f64 z t)) x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (-.f64 y x) z) t)) x): 44 points increase in error, 23 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr1.4

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

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

    if -3.99999999999999993e296 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 1.0000000000000001e299

    1. Initial program 0.8

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

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

Alternatives

Alternative 1
Error21.1
Cost1504
\[\begin{array}{l} t_1 := \frac{y - x}{\frac{t}{z}}\\ t_2 := x - z \cdot \frac{x}{t}\\ \mathbf{if}\;x \leq -27107829549.611862:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -7.734714090229673 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.44024367565031 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -9.656900221017529 \cdot 10^{-254}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.509692961622689 \cdot 10^{-46}:\\ \;\;\;\;\frac{z}{\frac{t}{y - x}}\\ \mathbf{elif}\;x \leq 3.722869152509367 \cdot 10^{-22}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.8518132387020875 \cdot 10^{+22}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.7484898187110868 \cdot 10^{+82}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error15.8
Cost1372
\[\begin{array}{l} t_1 := \frac{y - x}{\frac{t}{z}}\\ t_2 := x + \frac{y \cdot z}{t}\\ t_3 := x - z \cdot \frac{x}{t}\\ \mathbf{if}\;x \leq -27107829549.611862:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.1088060373500884 \cdot 10^{-24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.44024367565031 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.2904194535720593 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.6976248470586 \cdot 10^{-256}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.2292834975240435 \cdot 10^{-112}:\\ \;\;\;\;\frac{z}{\frac{t}{y - x}}\\ \mathbf{elif}\;x \leq 3.509692961622689 \cdot 10^{-46}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error20.6
Cost1108
\[\begin{array}{l} t_1 := \frac{z}{\frac{t}{y - x}}\\ t_2 := x - z \cdot \frac{x}{t}\\ \mathbf{if}\;x \leq -27107829549.611862:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -7.734714090229673 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.3613749215794964 \cdot 10^{-115}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.70203633421233 \cdot 10^{-220}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{elif}\;x \leq 3.509692961622689 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error24.2
Cost976
\[\begin{array}{l} t_1 := \frac{z}{\frac{t}{y - x}}\\ \mathbf{if}\;x \leq -8.961997013120384 \cdot 10^{+90}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.5304652952704116 \cdot 10^{+26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -27107829549.611862:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.8518132387020875 \cdot 10^{+22}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error12.4
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 -5.336571372234044 \cdot 10^{-18}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 9.6976248470586 \cdot 10^{-256}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.2292834975240435 \cdot 10^{-112}:\\ \;\;\;\;\frac{z}{\frac{t}{y - x}}\\ \mathbf{elif}\;x \leq 3.509692961622689 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error26.6
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -2.44024367565031 \cdot 10^{-105}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.8075777738548352 \cdot 10^{-135}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 1.045122135193916 \cdot 10^{-105}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{t}\\ \mathbf{elif}\;x \leq 3.509692961622689 \cdot 10^{-46}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error10.9
Cost712
\[\begin{array}{l} t_1 := x + z \cdot \frac{y}{t}\\ \mathbf{if}\;t \leq -0.185:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9.6 \cdot 10^{-126}:\\ \;\;\;\;\frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error25.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.44024367565031 \cdot 10^{-105}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.509692961622689 \cdot 10^{-46}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error25.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.44024367565031 \cdot 10^{-105}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.509692961622689 \cdot 10^{-46}:\\ \;\;\;\;y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error2.0
Cost576
\[x + \frac{y - x}{\frac{t}{z}} \]
Alternative 11
Error2.1
Cost576
\[x + \left(y - x\right) \cdot \frac{z}{t} \]
Alternative 12
Error31.6
Cost64
\[x \]

Error

Reproduce

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