Average Error: 2.1 → 2.5
Time: 6.2s
Precision: binary64
Cost: 840
\[\frac{x}{y} \cdot \left(z - t\right) + t \]
\[\begin{array}{l} t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{if}\;y \leq -2 \cdot 10^{-294}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-168}:\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ t (* (/ x y) (- z t)))))
   (if (<= y -2e-294) t_1 (if (<= y 5.5e-168) (/ (* x (- z t)) y) t_1))))
double code(double x, double y, double z, double t) {
	return ((x / y) * (z - t)) + t;
}
double code(double x, double y, double z, double t) {
	double t_1 = t + ((x / y) * (z - t));
	double tmp;
	if (y <= -2e-294) {
		tmp = t_1;
	} else if (y <= 5.5e-168) {
		tmp = (x * (z - t)) / y;
	} else {
		tmp = t_1;
	}
	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) * (z - t)) + 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 = t + ((x / y) * (z - t))
    if (y <= (-2d-294)) then
        tmp = t_1
    else if (y <= 5.5d-168) then
        tmp = (x * (z - t)) / y
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return ((x / y) * (z - t)) + t;
}
public static double code(double x, double y, double z, double t) {
	double t_1 = t + ((x / y) * (z - t));
	double tmp;
	if (y <= -2e-294) {
		tmp = t_1;
	} else if (y <= 5.5e-168) {
		tmp = (x * (z - t)) / y;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	return ((x / y) * (z - t)) + t
def code(x, y, z, t):
	t_1 = t + ((x / y) * (z - t))
	tmp = 0
	if y <= -2e-294:
		tmp = t_1
	elif y <= 5.5e-168:
		tmp = (x * (z - t)) / y
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t)
	return Float64(Float64(Float64(x / y) * Float64(z - t)) + t)
end
function code(x, y, z, t)
	t_1 = Float64(t + Float64(Float64(x / y) * Float64(z - t)))
	tmp = 0.0
	if (y <= -2e-294)
		tmp = t_1;
	elseif (y <= 5.5e-168)
		tmp = Float64(Float64(x * Float64(z - t)) / y);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = ((x / y) * (z - t)) + t;
end
function tmp_2 = code(x, y, z, t)
	t_1 = t + ((x / y) * (z - t));
	tmp = 0.0;
	if (y <= -2e-294)
		tmp = t_1;
	elseif (y <= 5.5e-168)
		tmp = (x * (z - t)) / y;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t + N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2e-294], t$95$1, If[LessEqual[y, 5.5e-168], N[(N[(x * N[(z - t), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], t$95$1]]]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\
\mathbf{if}\;y \leq -2 \cdot 10^{-294}:\\
\;\;\;\;t_1\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.1
Target2.3
Herbie2.5
\[\begin{array}{l} \mathbf{if}\;z < 2.759456554562692 \cdot 10^{-282}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \mathbf{elif}\;z < 2.326994450874436 \cdot 10^{-110}:\\ \;\;\;\;x \cdot \frac{z - t}{y} + t\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if y < -2.00000000000000003e-294 or 5.4999999999999999e-168 < y

    1. Initial program 1.7

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

    if -2.00000000000000003e-294 < y < 5.4999999999999999e-168

    1. Initial program 7.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)} \]
      Proof
      (fma.f64 x (/.f64 (-.f64 z t) y) t): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (/.f64 (-.f64 z t) y)) t)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 (-.f64 z t) y) x)) t): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (-.f64 z t) x) y)) t): 50 points increase in error, 38 points decrease in error
      (+.f64 (Rewrite<= associate-*r/_binary64 (*.f64 (-.f64 z t) (/.f64 x y))) t): 16 points increase in error, 50 points decrease in error
      (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 x y) (-.f64 z t))) t): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in x around -inf 12.7

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

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

Alternatives

Alternative 1
Error2.4
Cost7112
\[\begin{array}{l} \mathbf{if}\;z \leq -2.3 \cdot 10^{-217}:\\ \;\;\;\;t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-129}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z - t}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\ \end{array} \]
Alternative 2
Error22.5
Cost1100
\[\begin{array}{l} t_1 := \frac{z}{\frac{y}{x}}\\ \mathbf{if}\;\frac{x}{y} \leq -4 \cdot 10^{+235}:\\ \;\;\;\;x \cdot \frac{-t}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -2 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-72}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error17.8
Cost976
\[\begin{array}{l} t_1 := t \cdot \left(1 - \frac{x}{y}\right)\\ \mathbf{if}\;t \leq -6 \cdot 10^{-189}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.7 \cdot 10^{-234}:\\ \;\;\;\;\frac{z \cdot x}{y}\\ \mathbf{elif}\;t \leq 9.5 \cdot 10^{-184}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 8.5 \cdot 10^{-147}:\\ \;\;\;\;z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error5.3
Cost968
\[\begin{array}{l} t_1 := \frac{x}{\frac{y}{z - t}}\\ \mathbf{if}\;\frac{x}{y} \leq -20000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{+39}:\\ \;\;\;\;t + z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error5.1
Cost968
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -20000000:\\ \;\;\;\;\frac{x}{\frac{y}{z - t}}\\ \mathbf{elif}\;\frac{x}{y} \leq 4 \cdot 10^{+33}:\\ \;\;\;\;t + z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(z - t\right)}{y}\\ \end{array} \]
Alternative 6
Error22.8
Cost840
\[\begin{array}{l} t_1 := z \cdot \frac{x}{y}\\ \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-72}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error22.7
Cost840
\[\begin{array}{l} t_1 := \frac{z}{\frac{y}{x}}\\ \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{-72}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error2.4
Cost840
\[\begin{array}{l} t_1 := t + \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{if}\;z \leq -1.7 \cdot 10^{-217}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-129}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z - t}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error8.6
Cost712
\[\begin{array}{l} t_1 := t + z \cdot \frac{x}{y}\\ \mathbf{if}\;z \leq -6 \cdot 10^{-177}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-100}:\\ \;\;\;\;t \cdot \left(1 - \frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error9.1
Cost712
\[\begin{array}{l} t_1 := t + z \cdot \frac{x}{y}\\ \mathbf{if}\;z \leq -6.6 \cdot 10^{-178}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.3 \cdot 10^{-125}:\\ \;\;\;\;t - x \cdot \frac{t}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error32.0
Cost64
\[t \]

Error

Reproduce

herbie shell --seed 2022325 
(FPCore (x y z t)
  :name "Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1"
  :precision binary64

  :herbie-target
  (if (< z 2.759456554562692e-282) (+ (* (/ x y) (- z t)) t) (if (< z 2.326994450874436e-110) (+ (* x (/ (- z t) y)) t) (+ (* (/ x y) (- z t)) t)))

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