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

\mathbf{elif}\;t_1 \leq 10^{+296}:\\
\;\;\;\;x + \frac{t_1}{a}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.3
Target0.6
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 3 regimes
  2. if (*.f64 y (-.f64 z t)) < -4.9999999999999997e303

    1. Initial program 60.7

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

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

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

    if -4.9999999999999997e303 < (*.f64 y (-.f64 z t)) < 9.99999999999999981e295

    1. Initial program 0.4

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

    if 9.99999999999999981e295 < (*.f64 y (-.f64 z t))

    1. Initial program 58.7

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

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

      \[\leadsto \color{blue}{\frac{\left(z - t\right) \cdot y}{a}} \]
    4. Applied egg-rr10.9

      \[\leadsto \color{blue}{\frac{z}{\frac{a}{y}} - \frac{t}{\frac{a}{y}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.0

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

Alternatives

Alternative 1
Error0.4
Cost1352
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ t_2 := y \cdot \frac{z - t}{a} + x\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+303}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+296}:\\ \;\;\;\;x + \frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error29.7
Cost912
\[\begin{array}{l} \mathbf{if}\;x \leq -5.0664580198150126 \cdot 10^{-163}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.9139986715848785 \cdot 10^{-256}:\\ \;\;\;\;\frac{y \cdot t}{-a}\\ \mathbf{elif}\;x \leq 1.7617504487801152 \cdot 10^{-259}:\\ \;\;\;\;\frac{y}{\frac{a}{z}}\\ \mathbf{elif}\;x \leq 2.649308884011006 \cdot 10^{+45}:\\ \;\;\;\;\frac{-t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error29.6
Cost912
\[\begin{array}{l} \mathbf{if}\;x \leq -5.0664580198150126 \cdot 10^{-163}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.9139986715848785 \cdot 10^{-256}:\\ \;\;\;\;\frac{y \cdot t}{-a}\\ \mathbf{elif}\;x \leq 1.10274229300989 \cdot 10^{-279}:\\ \;\;\;\;\frac{y}{\frac{a}{z}}\\ \mathbf{elif}\;x \leq 2.649308884011006 \cdot 10^{+45}:\\ \;\;\;\;t \cdot \frac{-y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error18.2
Cost844
\[\begin{array}{l} \mathbf{if}\;z \leq 1.0194106529681273 \cdot 10^{+46}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+213}:\\ \;\;\;\;\frac{y}{\frac{a}{z}}\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+245}:\\ \;\;\;\;x - y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{a}\\ \end{array} \]
Alternative 5
Error5.9
Cost840
\[\begin{array}{l} t_1 := y \cdot \frac{z - t}{a} + x\\ \mathbf{if}\;y \leq -8.901040791320461 \cdot 10^{-138}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.303880842316988 \cdot 10^{-162}:\\ \;\;\;\;x - t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error29.5
Cost780
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1954007636779402 \cdot 10^{-170}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.7617504487801152 \cdot 10^{-259}:\\ \;\;\;\;\frac{y}{\frac{a}{z}}\\ \mathbf{elif}\;x \leq 2.649308884011006 \cdot 10^{+45}:\\ \;\;\;\;\frac{-t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error18.3
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq 1.0194106529681273 \cdot 10^{+46}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+213}:\\ \;\;\;\;\frac{y}{\frac{a}{z}}\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+245}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{a}\\ \end{array} \]
Alternative 8
Error11.5
Cost712
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{a}{z}}\\ \mathbf{if}\;z \leq -3.003301132523552 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.192508321952651 \cdot 10^{-13}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error11.6
Cost712
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{a}{z}}\\ \mathbf{if}\;z \leq -3.003301132523552 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.192508321952651 \cdot 10^{-13}:\\ \;\;\;\;x - t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error28.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1954007636779402 \cdot 10^{-170}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.076860249449997 \cdot 10^{-141}:\\ \;\;\;\;\frac{y}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error27.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.185512794135133 \cdot 10^{-101}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.076860249449997 \cdot 10^{-141}:\\ \;\;\;\;z \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error31.0
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022294 
(FPCore (x y z t a)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, E"
  :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)))