Average Error: 6.3 → 1.0
Time: 9.3s
Precision: binary64
Cost: 1608
\[x - \frac{y \cdot \left(z - t\right)}{a} \]
\[\begin{array}{l} t_1 := \frac{y \cdot \left(z - t\right)}{a}\\ t_2 := x + \frac{t - z}{\frac{a}{y}}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+281}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 100000000000:\\ \;\;\;\;x - t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (- x (/ (* y (- z t)) a)))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (/ (* y (- z t)) a)) (t_2 (+ x (/ (- t z) (/ a y)))))
   (if (<= t_1 -1e+281) t_2 (if (<= t_1 100000000000.0) (- x t_1) t_2))))
double code(double x, double y, double z, double t, double a) {
	return x - ((y * (z - t)) / a);
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (y * (z - t)) / a;
	double t_2 = x + ((t - z) / (a / y));
	double tmp;
	if (t_1 <= -1e+281) {
		tmp = t_2;
	} else if (t_1 <= 100000000000.0) {
		tmp = x - t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = x - ((y * (z - t)) / a)
end function
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = (y * (z - t)) / a
    t_2 = x + ((t - z) / (a / y))
    if (t_1 <= (-1d+281)) then
        tmp = t_2
    else if (t_1 <= 100000000000.0d0) then
        tmp = x - t_1
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	return x - ((y * (z - t)) / a);
}
public static double code(double x, double y, double z, double t, double a) {
	double t_1 = (y * (z - t)) / a;
	double t_2 = x + ((t - z) / (a / y));
	double tmp;
	if (t_1 <= -1e+281) {
		tmp = t_2;
	} else if (t_1 <= 100000000000.0) {
		tmp = x - t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t, a):
	return x - ((y * (z - t)) / a)
def code(x, y, z, t, a):
	t_1 = (y * (z - t)) / a
	t_2 = x + ((t - z) / (a / y))
	tmp = 0
	if t_1 <= -1e+281:
		tmp = t_2
	elif t_1 <= 100000000000.0:
		tmp = x - t_1
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t, a)
	return Float64(x - Float64(Float64(y * Float64(z - t)) / a))
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(y * Float64(z - t)) / a)
	t_2 = Float64(x + Float64(Float64(t - z) / Float64(a / y)))
	tmp = 0.0
	if (t_1 <= -1e+281)
		tmp = t_2;
	elseif (t_1 <= 100000000000.0)
		tmp = Float64(x - t_1);
	else
		tmp = t_2;
	end
	return tmp
end
function tmp = code(x, y, z, t, a)
	tmp = x - ((y * (z - t)) / a);
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = (y * (z - t)) / a;
	t_2 = x + ((t - z) / (a / y));
	tmp = 0.0;
	if (t_1 <= -1e+281)
		tmp = t_2;
	elseif (t_1 <= 100000000000.0)
		tmp = x - t_1;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := N[(x - N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(t - z), $MachinePrecision] / N[(a / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+281], t$95$2, If[LessEqual[t$95$1, 100000000000.0], N[(x - t$95$1), $MachinePrecision], t$95$2]]]]
x - \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
t_1 := \frac{y \cdot \left(z - t\right)}{a}\\
t_2 := x + \frac{t - z}{\frac{a}{y}}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+281}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 100000000000:\\
\;\;\;\;x - 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.3
Target0.7
Herbie1.0
\[\begin{array}{l} \mathbf{if}\;y < -1.0761266216389975 \cdot 10^{-10}:\\ \;\;\;\;x - \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x - \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{a}{z - t}}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 y (-.f64 z t)) a) < -1e281 or 1e11 < (/.f64 (*.f64 y (-.f64 z t)) a)

    1. Initial program 19.4

      \[x - \frac{y \cdot \left(z - t\right)}{a} \]
    2. Simplified2.8

      \[\leadsto \color{blue}{x - \frac{y}{a} \cdot \left(z - t\right)} \]
      Proof
      (-.f64 x (*.f64 (/.f64 y a) (-.f64 z t))): 0 points increase in error, 0 points decrease in error
      (-.f64 x (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 y (-.f64 z t)) a))): 37 points increase in error, 24 points decrease in error
    3. Applied egg-rr2.6

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

    if -1e281 < (/.f64 (*.f64 y (-.f64 z t)) a) < 1e11

    1. Initial program 0.4

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

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

Alternatives

Alternative 1
Error1.4
Cost1096
\[\begin{array}{l} t_1 := x + \frac{y}{a} \cdot \left(t - z\right)\\ \mathbf{if}\;z - t \leq -500000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z - t \leq 2 \cdot 10^{+44}:\\ \;\;\;\;x + y \cdot \frac{t - z}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error5.4
Cost840
\[\begin{array}{l} t_1 := x + y \cdot \frac{t - z}{a}\\ \mathbf{if}\;a \leq -2 \cdot 10^{-151}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3.6 \cdot 10^{-266}:\\ \;\;\;\;\frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error0.8
Cost840
\[\begin{array}{l} \mathbf{if}\;a \leq -5 \cdot 10^{+60}:\\ \;\;\;\;x - \frac{y}{\frac{a}{z - t}}\\ \mathbf{elif}\;a \leq 10^{-14}:\\ \;\;\;\;x - \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{t - z}{a}\\ \end{array} \]
Alternative 4
Error18.5
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -6.7 \cdot 10^{-37}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+14}:\\ \;\;\;\;\frac{y}{a} \cdot \left(t - z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error13.8
Cost712
\[\begin{array}{l} t_1 := x + t \cdot \frac{y}{a}\\ \mathbf{if}\;x \leq -7.2 \cdot 10^{-129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-62}:\\ \;\;\;\;\frac{y}{a} \cdot \left(t - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error11.4
Cost712
\[\begin{array}{l} t_1 := x + t \cdot \frac{y}{a}\\ \mathbf{if}\;t \leq -4.6 \cdot 10^{+111}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{-13}:\\ \;\;\;\;x - y \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error11.3
Cost712
\[\begin{array}{l} t_1 := x + t \cdot \frac{y}{a}\\ \mathbf{if}\;t \leq -1.6 \cdot 10^{+116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{-13}:\\ \;\;\;\;x - \frac{y}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error28.4
Cost648
\[\begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{-132}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.4 \cdot 10^{-52}:\\ \;\;\;\;z \cdot \frac{-y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error29.0
Cost648
\[\begin{array}{l} \mathbf{if}\;x \leq -3 \cdot 10^{-130}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.26 \cdot 10^{-54}:\\ \;\;\;\;\frac{z}{a} \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error28.9
Cost648
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-134}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.1 \cdot 10^{-53}:\\ \;\;\;\;\frac{y \cdot \left(-z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error28.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -7.4 \cdot 10^{-151}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-35}:\\ \;\;\;\;y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error28.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3.85 \cdot 10^{-153}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.42 \cdot 10^{-33}:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error28.6
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.6 \cdot 10^{-154}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.3 \cdot 10^{-26}:\\ \;\;\;\;\frac{t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 14
Error31.8
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022325 
(FPCore (x y z t a)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, F"
  :precision binary64

  :herbie-target
  (if (< y -1.0761266216389975e-10) (- x (/ 1.0 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (- x (/ (* y (- z t)) a)) (- x (/ y (/ a (- z t))))))

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