Average Error: 6.3 → 13.5
Time: 7.2s
Precision: binary64
Cost: 4060
\[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}{\frac{a}{y}}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+305}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -1 \cdot 10^{+139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-174}:\\ \;\;\;\;x + y \cdot \frac{z}{a}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-8}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+71}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+128}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+305}:\\ \;\;\;\;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 (/ a y)))))
   (if (<= t_1 -2e+305)
     t_2
     (if (<= t_1 -1e+139)
       t_1
       (if (<= t_1 5e-174)
         (+ x (* y (/ z a)))
         (if (<= t_1 5e-8)
           t_2
           (if (<= t_1 1e+71)
             t_1
             (if (<= t_1 5e+128) t_2 (if (<= t_1 2e+305) 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 / (a / y));
	double tmp;
	if (t_1 <= -2e+305) {
		tmp = t_2;
	} else if (t_1 <= -1e+139) {
		tmp = t_1;
	} else if (t_1 <= 5e-174) {
		tmp = x + (y * (z / a));
	} else if (t_1 <= 5e-8) {
		tmp = t_2;
	} else if (t_1 <= 1e+71) {
		tmp = t_1;
	} else if (t_1 <= 5e+128) {
		tmp = t_2;
	} else if (t_1 <= 2e+305) {
		tmp = 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 / (a / y))
    if (t_1 <= (-2d+305)) then
        tmp = t_2
    else if (t_1 <= (-1d+139)) then
        tmp = t_1
    else if (t_1 <= 5d-174) then
        tmp = x + (y * (z / a))
    else if (t_1 <= 5d-8) then
        tmp = t_2
    else if (t_1 <= 1d+71) then
        tmp = t_1
    else if (t_1 <= 5d+128) then
        tmp = t_2
    else if (t_1 <= 2d+305) 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, 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 / (a / y));
	double tmp;
	if (t_1 <= -2e+305) {
		tmp = t_2;
	} else if (t_1 <= -1e+139) {
		tmp = t_1;
	} else if (t_1 <= 5e-174) {
		tmp = x + (y * (z / a));
	} else if (t_1 <= 5e-8) {
		tmp = t_2;
	} else if (t_1 <= 1e+71) {
		tmp = t_1;
	} else if (t_1 <= 5e+128) {
		tmp = t_2;
	} else if (t_1 <= 2e+305) {
		tmp = 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 / (a / y))
	tmp = 0
	if t_1 <= -2e+305:
		tmp = t_2
	elif t_1 <= -1e+139:
		tmp = t_1
	elif t_1 <= 5e-174:
		tmp = x + (y * (z / a))
	elif t_1 <= 5e-8:
		tmp = t_2
	elif t_1 <= 1e+71:
		tmp = t_1
	elif t_1 <= 5e+128:
		tmp = t_2
	elif t_1 <= 2e+305:
		tmp = 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(t / Float64(a / y)))
	tmp = 0.0
	if (t_1 <= -2e+305)
		tmp = t_2;
	elseif (t_1 <= -1e+139)
		tmp = t_1;
	elseif (t_1 <= 5e-174)
		tmp = Float64(x + Float64(y * Float64(z / a)));
	elseif (t_1 <= 5e-8)
		tmp = t_2;
	elseif (t_1 <= 1e+71)
		tmp = t_1;
	elseif (t_1 <= 5e+128)
		tmp = t_2;
	elseif (t_1 <= 2e+305)
		tmp = 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 / (a / y));
	tmp = 0.0;
	if (t_1 <= -2e+305)
		tmp = t_2;
	elseif (t_1 <= -1e+139)
		tmp = t_1;
	elseif (t_1 <= 5e-174)
		tmp = x + (y * (z / a));
	elseif (t_1 <= 5e-8)
		tmp = t_2;
	elseif (t_1 <= 1e+71)
		tmp = t_1;
	elseif (t_1 <= 5e+128)
		tmp = t_2;
	elseif (t_1 <= 2e+305)
		tmp = 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[(t / N[(a / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+305], t$95$2, If[LessEqual[t$95$1, -1e+139], t$95$1, If[LessEqual[t$95$1, 5e-174], N[(x + N[(y * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e-8], t$95$2, If[LessEqual[t$95$1, 1e+71], t$95$1, If[LessEqual[t$95$1, 5e+128], t$95$2, If[LessEqual[t$95$1, 2e+305], t$95$1, 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}{\frac{a}{y}}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+305}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq -1 \cdot 10^{+139}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{-174}:\\
\;\;\;\;x + y \cdot \frac{z}{a}\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{-8}:\\
\;\;\;\;t_2\\

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

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+128}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+305}:\\
\;\;\;\;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
Herbie13.5
\[\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 (*.f64 y (-.f64 z t)) a) < -1.9999999999999999e305 or 5.0000000000000002e-174 < (/.f64 (*.f64 y (-.f64 z t)) a) < 4.9999999999999998e-8 or 1e71 < (/.f64 (*.f64 y (-.f64 z t)) a) < 5e128 or 1.9999999999999999e305 < (/.f64 (*.f64 y (-.f64 z t)) a)

    1. Initial program 24.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - t}{a}, x\right)} \]
    3. Taylor expanded in z around 0 31.7

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot t}{a} + x} \]
    4. Simplified19.4

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

    if -1.9999999999999999e305 < (/.f64 (*.f64 y (-.f64 z t)) a) < -1.00000000000000003e139 or 4.9999999999999998e-8 < (/.f64 (*.f64 y (-.f64 z t)) a) < 1e71 or 5e128 < (/.f64 (*.f64 y (-.f64 z t)) a) < 1.9999999999999999e305

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - t}{a}, x\right)} \]
    3. Taylor expanded in y around -inf 14.0

      \[\leadsto \color{blue}{\frac{y \cdot \left(z - t\right)}{a}} \]

    if -1.00000000000000003e139 < (/.f64 (*.f64 y (-.f64 z t)) a) < 5.0000000000000002e-174

    1. Initial program 0.5

      \[x + \frac{y \cdot \left(z - t\right)}{a} \]
    2. Taylor expanded in z around inf 9.2

      \[\leadsto x + \color{blue}{\frac{y \cdot z}{a}} \]
    3. Simplified10.1

      \[\leadsto x + \color{blue}{y \cdot \frac{z}{a}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y \cdot \left(z - t\right)}{a} \leq -2 \cdot 10^{+305}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \mathbf{elif}\;\frac{y \cdot \left(z - t\right)}{a} \leq -1 \cdot 10^{+139}:\\ \;\;\;\;\frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{elif}\;\frac{y \cdot \left(z - t\right)}{a} \leq 5 \cdot 10^{-174}:\\ \;\;\;\;x + y \cdot \frac{z}{a}\\ \mathbf{elif}\;\frac{y \cdot \left(z - t\right)}{a} \leq 5 \cdot 10^{-8}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \mathbf{elif}\;\frac{y \cdot \left(z - t\right)}{a} \leq 10^{+71}:\\ \;\;\;\;\frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{elif}\;\frac{y \cdot \left(z - t\right)}{a} \leq 5 \cdot 10^{+128}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \mathbf{elif}\;\frac{y \cdot \left(z - t\right)}{a} \leq 2 \cdot 10^{+305}:\\ \;\;\;\;\frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \end{array} \]

Alternatives

Alternative 1
Error17.8
Cost2512
\[\begin{array}{l} t_1 := \frac{y \cdot \left(z - t\right)}{a}\\ t_2 := \frac{-t}{\frac{a}{y}}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+305}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -1 \cdot 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-10}:\\ \;\;\;\;x\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+305}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error14.0
Cost2512
\[\begin{array}{l} t_1 := x + y \cdot \frac{z}{a}\\ t_2 := \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq -1 \cdot 10^{+139}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+305}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{-t}{\frac{a}{y}}\\ \end{array} \]
Alternative 3
Error13.9
Cost2512
\[\begin{array}{l} t_1 := \frac{y \cdot \left(z - t\right)}{a}\\ t_2 := \left(z - t\right) \cdot \frac{y}{a}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+182}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-174}:\\ \;\;\;\;x + y \cdot \frac{z}{a}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-8}:\\ \;\;\;\;x - \frac{t}{\frac{a}{y}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+69}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error30.8
Cost1308
\[\begin{array}{l} t_1 := \frac{-t}{\frac{a}{y}}\\ \mathbf{if}\;t \leq -1.75 \cdot 10^{+180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -3.8249319442978446 \cdot 10^{-230}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -1.0736205040373965 \cdot 10^{-256}:\\ \;\;\;\;y \cdot \frac{z}{a}\\ \mathbf{elif}\;t \leq 3.850147018943957 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.2729909712006244 \cdot 10^{-13}:\\ \;\;\;\;\frac{y \cdot z}{a}\\ \mathbf{elif}\;t \leq 8 \cdot 10^{+206}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{+290}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error28.4
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -9.762265705292778 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9.572022819467558 \cdot 10^{-63}:\\ \;\;\;\;z \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error29.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -9.762265705292778 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9.572022819467558 \cdot 10^{-63}:\\ \;\;\;\;y \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error28.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -9.762265705292778 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9.572022819467558 \cdot 10^{-63}:\\ \;\;\;\;\frac{y \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
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, 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)))