Average Error: 2.0 → 1.5
Time: 10.4s
Precision: binary64
Cost: 1220
\[\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}\;t_1 \leq -5 \cdot 10^{+298}:\\ \;\;\;\;t + x \cdot \frac{z - t}{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 (<= t_1 -5e+298) (+ t (* 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 (t_1 <= -5e+298) {
		tmp = t + (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 (t_1 <= (-5d+298)) then
        tmp = t + (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 (t_1 <= -5e+298) {
		tmp = t + (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 t_1 <= -5e+298:
		tmp = t + (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 (t_1 <= -5e+298)
		tmp = Float64(t + Float64(x * Float64(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 (t_1 <= -5e+298)
		tmp = t + (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[t$95$1, -5e+298], N[(t + N[(x * N[(N[(z - t), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $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}\;t_1 \leq -5 \cdot 10^{+298}:\\
\;\;\;\;t + x \cdot \frac{z - t}{y}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.0
Target2.2
Herbie1.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 (+.f64 (*.f64 (/.f64 x y) (-.f64 z t)) t) < -5.0000000000000003e298

    1. Initial program 32.4

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

      \[\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)): 3 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): 48 points increase in error, 42 points decrease in error
      (+.f64 (Rewrite<= associate-*r/_binary64 (*.f64 (-.f64 z t) (/.f64 x y))) t): 27 points increase in error, 52 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. Applied egg-rr9.7

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

    if -5.0000000000000003e298 < (+.f64 (*.f64 (/.f64 x y) (-.f64 z t)) t)

    1. Initial program 1.3

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

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

Alternatives

Alternative 1
Error24.2
Cost2464
\[\begin{array}{l} t_1 := \frac{z}{\frac{y}{x}}\\ t_2 := x \cdot \frac{-t}{y}\\ \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{+96}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{x}{y} \leq -4 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -20000000000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{x}{y} \leq -2 \cdot 10^{-38}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-101}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 10000:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{+49}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{x}{y} \leq 10^{+132}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error23.9
Cost1944
\[\begin{array}{l} t_1 := \frac{x}{y} \cdot \left(-t\right)\\ \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{+96}:\\ \;\;\;\;x \cdot \frac{-t}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -4 \cdot 10^{+28}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x}{y} \leq -20000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -2 \cdot 10^{-38}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-101}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 10000:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error23.9
Cost1944
\[\begin{array}{l} t_1 := \frac{x}{y} \cdot \left(-t\right)\\ \mathbf{if}\;\frac{x}{y} \leq -1 \cdot 10^{+96}:\\ \;\;\;\;\frac{x \cdot \left(-t\right)}{y}\\ \mathbf{elif}\;\frac{x}{y} \leq -4 \cdot 10^{+28}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;\frac{x}{y} \leq -20000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -2 \cdot 10^{-38}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-101}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 10000:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error14.6
Cost1488
\[\begin{array}{l} t_1 := \frac{x}{\frac{y}{z - t}}\\ \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{-24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -2 \cdot 10^{-38}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-101}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error22.9
Cost1360
\[\begin{array}{l} t_1 := \frac{z}{\frac{y}{x}}\\ \mathbf{if}\;\frac{x}{y} \leq -50000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq -2 \cdot 10^{-38}:\\ \;\;\;\;t\\ \mathbf{elif}\;\frac{x}{y} \leq -5 \cdot 10^{-101}:\\ \;\;\;\;\frac{x}{y} \cdot z\\ \mathbf{elif}\;\frac{x}{y} \leq 5 \cdot 10^{-38}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error5.6
Cost968
\[\begin{array}{l} t_1 := \frac{x}{\frac{y}{z - t}}\\ \mathbf{if}\;\frac{x}{y} \leq -20000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error4.4
Cost968
\[\begin{array}{l} t_1 := \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{if}\;\frac{x}{y} \leq -20000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error3.2
Cost968
\[\begin{array}{l} t_1 := \frac{x}{y} \cdot \left(z - t\right)\\ \mathbf{if}\;\frac{x}{y} \leq -20000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t + \frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error3.4
Cost968
\[\begin{array}{l} \mathbf{if}\;\frac{x}{y} \leq -2 \cdot 10^{-5}:\\ \;\;\;\;t + \frac{x}{\frac{y}{z - t}}\\ \mathbf{elif}\;\frac{x}{y} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t + \frac{x}{y} \cdot z\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right)\\ \end{array} \]
Alternative 10
Error26.2
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -8.559562695059754 \cdot 10^{-61}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 1.1106062039131974 \cdot 10^{-185}:\\ \;\;\;\;\frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 11
Error25.7
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -2.2907707931085747 \cdot 10^{-54}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 1.1106062039131974 \cdot 10^{-185}:\\ \;\;\;\;\frac{z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 12
Error31.5
Cost64
\[t \]

Error

Reproduce

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