Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D

Percentage Accurate: 93.6% → 97.6%
Time: 7.4s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ x + \frac{y \cdot \left(z - x\right)}{t} \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
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 - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
def code(x, y, z, t):
	return x + ((y * (z - x)) / t)
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * Float64(z - x)) / t))
end
function tmp = code(x, y, z, t)
	tmp = x + ((y * (z - x)) / t);
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 93.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \frac{y \cdot \left(z - x\right)}{t} \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
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 - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
def code(x, y, z, t):
	return x + ((y * (z - x)) / t)
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * Float64(z - x)) / t))
end
function tmp = code(x, y, z, t)
	tmp = x + ((y * (z - x)) / t);
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}

Alternative 1: 97.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \frac{z - x}{\frac{t}{y}} \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (- z x) (/ t y))))
double code(double x, double y, double z, double t) {
	return x + ((z - x) / (t / y));
}
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 + ((z - x) / (t / y))
end function
public static double code(double x, double y, double z, double t) {
	return x + ((z - x) / (t / y));
}
def code(x, y, z, t):
	return x + ((z - x) / (t / y))
function code(x, y, z, t)
	return Float64(x + Float64(Float64(z - x) / Float64(t / y)))
end
function tmp = code(x, y, z, t)
	tmp = x + ((z - x) / (t / y));
end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \frac{z - x}{\frac{t}{y}}
\end{array}
Derivation
  1. Initial program 93.6%

    \[x + \frac{y \cdot \left(z - x\right)}{t} \]
  2. Step-by-step derivation
    1. associate-*l/97.1%

      \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
  3. Simplified97.1%

    \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
  4. Step-by-step derivation
    1. *-commutative97.1%

      \[\leadsto x + \color{blue}{\left(z - x\right) \cdot \frac{y}{t}} \]
    2. clear-num96.9%

      \[\leadsto x + \left(z - x\right) \cdot \color{blue}{\frac{1}{\frac{t}{y}}} \]
    3. un-div-inv97.3%

      \[\leadsto x + \color{blue}{\frac{z - x}{\frac{t}{y}}} \]
  5. Applied egg-rr97.3%

    \[\leadsto x + \color{blue}{\frac{z - x}{\frac{t}{y}}} \]
  6. Final simplification97.3%

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

Alternative 2: 48.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;t \leq -5.4 \cdot 10^{-113}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 8.4 \cdot 10^{-156} \lor \neg \left(t \leq 10^{-112}\right) \land t \leq 2.8 \cdot 10^{-11}:\\ \;\;\;\;y \cdot \frac{x}{-t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= t -5.4e-113)
   x
   (if (or (<= t 8.4e-156) (and (not (<= t 1e-112)) (<= t 2.8e-11)))
     (* y (/ x (- t)))
     x)))
double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= -5.4e-113) {
		tmp = x;
	} else if ((t <= 8.4e-156) || (!(t <= 1e-112) && (t <= 2.8e-11))) {
		tmp = y * (x / -t);
	} else {
		tmp = x;
	}
	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
    real(8) :: tmp
    if (t <= (-5.4d-113)) then
        tmp = x
    else if ((t <= 8.4d-156) .or. (.not. (t <= 1d-112)) .and. (t <= 2.8d-11)) then
        tmp = y * (x / -t)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= -5.4e-113) {
		tmp = x;
	} else if ((t <= 8.4e-156) || (!(t <= 1e-112) && (t <= 2.8e-11))) {
		tmp = y * (x / -t);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if t <= -5.4e-113:
		tmp = x
	elif (t <= 8.4e-156) or (not (t <= 1e-112) and (t <= 2.8e-11)):
		tmp = y * (x / -t)
	else:
		tmp = x
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (t <= -5.4e-113)
		tmp = x;
	elseif ((t <= 8.4e-156) || (!(t <= 1e-112) && (t <= 2.8e-11)))
		tmp = Float64(y * Float64(x / Float64(-t)));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (t <= -5.4e-113)
		tmp = x;
	elseif ((t <= 8.4e-156) || (~((t <= 1e-112)) && (t <= 2.8e-11)))
		tmp = y * (x / -t);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[t, -5.4e-113], x, If[Or[LessEqual[t, 8.4e-156], And[N[Not[LessEqual[t, 1e-112]], $MachinePrecision], LessEqual[t, 2.8e-11]]], N[(y * N[(x / (-t)), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.4 \cdot 10^{-113}:\\
\;\;\;\;x\\

\mathbf{elif}\;t \leq 8.4 \cdot 10^{-156} \lor \neg \left(t \leq 10^{-112}\right) \land t \leq 2.8 \cdot 10^{-11}:\\
\;\;\;\;y \cdot \frac{x}{-t}\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -5.39999999999999991e-113 or 8.40000000000000049e-156 < t < 9.9999999999999995e-113 or 2.8e-11 < t

    1. Initial program 90.7%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/97.3%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified97.3%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Taylor expanded in y around 0 53.6%

      \[\leadsto \color{blue}{x} \]

    if -5.39999999999999991e-113 < t < 8.40000000000000049e-156 or 9.9999999999999995e-113 < t < 2.8e-11

    1. Initial program 98.9%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/96.8%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified96.8%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Taylor expanded in x around inf 63.4%

      \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{y}{t}\right) \cdot x} \]
    5. Step-by-step derivation
      1. *-commutative63.4%

        \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \frac{y}{t}\right)} \]
      2. distribute-lft-in63.4%

        \[\leadsto \color{blue}{x \cdot 1 + x \cdot \left(-1 \cdot \frac{y}{t}\right)} \]
      3. *-rgt-identity63.4%

        \[\leadsto \color{blue}{x} + x \cdot \left(-1 \cdot \frac{y}{t}\right) \]
      4. mul-1-neg63.4%

        \[\leadsto x + x \cdot \color{blue}{\left(-\frac{y}{t}\right)} \]
      5. distribute-rgt-neg-in63.4%

        \[\leadsto x + \color{blue}{\left(-x \cdot \frac{y}{t}\right)} \]
      6. unsub-neg63.4%

        \[\leadsto \color{blue}{x - x \cdot \frac{y}{t}} \]
    6. Simplified63.4%

      \[\leadsto \color{blue}{x - x \cdot \frac{y}{t}} \]
    7. Step-by-step derivation
      1. clear-num63.4%

        \[\leadsto x - x \cdot \color{blue}{\frac{1}{\frac{t}{y}}} \]
      2. un-div-inv64.3%

        \[\leadsto x - \color{blue}{\frac{x}{\frac{t}{y}}} \]
    8. Applied egg-rr64.3%

      \[\leadsto x - \color{blue}{\frac{x}{\frac{t}{y}}} \]
    9. Taylor expanded in t around 0 51.7%

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot x}{t}} \]
    10. Step-by-step derivation
      1. associate-*r/51.7%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(y \cdot x\right)}{t}} \]
      2. associate-*l/51.6%

        \[\leadsto \color{blue}{\frac{-1}{t} \cdot \left(y \cdot x\right)} \]
      3. metadata-eval51.6%

        \[\leadsto \frac{\color{blue}{-1}}{t} \cdot \left(y \cdot x\right) \]
      4. distribute-neg-frac51.6%

        \[\leadsto \color{blue}{\left(-\frac{1}{t}\right)} \cdot \left(y \cdot x\right) \]
      5. associate-*r*51.7%

        \[\leadsto \color{blue}{\left(\left(-\frac{1}{t}\right) \cdot y\right) \cdot x} \]
      6. distribute-neg-frac51.7%

        \[\leadsto \left(\color{blue}{\frac{-1}{t}} \cdot y\right) \cdot x \]
      7. metadata-eval51.7%

        \[\leadsto \left(\frac{\color{blue}{-1}}{t} \cdot y\right) \cdot x \]
      8. metadata-eval51.7%

        \[\leadsto \left(\frac{\color{blue}{\frac{1}{-1}}}{t} \cdot y\right) \cdot x \]
      9. associate-/r*51.7%

        \[\leadsto \left(\color{blue}{\frac{1}{-1 \cdot t}} \cdot y\right) \cdot x \]
      10. neg-mul-151.7%

        \[\leadsto \left(\frac{1}{\color{blue}{-t}} \cdot y\right) \cdot x \]
      11. associate-/r/51.7%

        \[\leadsto \color{blue}{\frac{1}{\frac{-t}{y}}} \cdot x \]
      12. *-commutative51.7%

        \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{-t}{y}}} \]
      13. associate-*r/52.6%

        \[\leadsto \color{blue}{\frac{x \cdot 1}{\frac{-t}{y}}} \]
      14. *-rgt-identity52.6%

        \[\leadsto \frac{\color{blue}{x}}{\frac{-t}{y}} \]
      15. associate-/r/47.7%

        \[\leadsto \color{blue}{\frac{x}{-t} \cdot y} \]
      16. *-commutative47.7%

        \[\leadsto \color{blue}{y \cdot \frac{x}{-t}} \]
    11. Simplified47.7%

      \[\leadsto \color{blue}{y \cdot \frac{x}{-t}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification51.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -5.4 \cdot 10^{-113}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 8.4 \cdot 10^{-156} \lor \neg \left(t \leq 10^{-112}\right) \land t \leq 2.8 \cdot 10^{-11}:\\ \;\;\;\;y \cdot \frac{x}{-t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 3: 50.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;t \leq -2.7 \cdot 10^{-105}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 8.8 \cdot 10^{-156} \lor \neg \left(t \leq 8.5 \cdot 10^{-113}\right) \land t \leq 2.3 \cdot 10^{-12}:\\ \;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= t -2.7e-105)
   x
   (if (or (<= t 8.8e-156) (and (not (<= t 8.5e-113)) (<= t 2.3e-12)))
     (* (/ y t) (- x))
     x)))
double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= -2.7e-105) {
		tmp = x;
	} else if ((t <= 8.8e-156) || (!(t <= 8.5e-113) && (t <= 2.3e-12))) {
		tmp = (y / t) * -x;
	} else {
		tmp = x;
	}
	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
    real(8) :: tmp
    if (t <= (-2.7d-105)) then
        tmp = x
    else if ((t <= 8.8d-156) .or. (.not. (t <= 8.5d-113)) .and. (t <= 2.3d-12)) then
        tmp = (y / t) * -x
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= -2.7e-105) {
		tmp = x;
	} else if ((t <= 8.8e-156) || (!(t <= 8.5e-113) && (t <= 2.3e-12))) {
		tmp = (y / t) * -x;
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if t <= -2.7e-105:
		tmp = x
	elif (t <= 8.8e-156) or (not (t <= 8.5e-113) and (t <= 2.3e-12)):
		tmp = (y / t) * -x
	else:
		tmp = x
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (t <= -2.7e-105)
		tmp = x;
	elseif ((t <= 8.8e-156) || (!(t <= 8.5e-113) && (t <= 2.3e-12)))
		tmp = Float64(Float64(y / t) * Float64(-x));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (t <= -2.7e-105)
		tmp = x;
	elseif ((t <= 8.8e-156) || (~((t <= 8.5e-113)) && (t <= 2.3e-12)))
		tmp = (y / t) * -x;
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[t, -2.7e-105], x, If[Or[LessEqual[t, 8.8e-156], And[N[Not[LessEqual[t, 8.5e-113]], $MachinePrecision], LessEqual[t, 2.3e-12]]], N[(N[(y / t), $MachinePrecision] * (-x)), $MachinePrecision], x]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.7 \cdot 10^{-105}:\\
\;\;\;\;x\\

\mathbf{elif}\;t \leq 8.8 \cdot 10^{-156} \lor \neg \left(t \leq 8.5 \cdot 10^{-113}\right) \land t \leq 2.3 \cdot 10^{-12}:\\
\;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -2.69999999999999993e-105 or 8.7999999999999996e-156 < t < 8.4999999999999995e-113 or 2.29999999999999989e-12 < t

    1. Initial program 90.7%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/97.3%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified97.3%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Taylor expanded in y around 0 53.6%

      \[\leadsto \color{blue}{x} \]

    if -2.69999999999999993e-105 < t < 8.7999999999999996e-156 or 8.4999999999999995e-113 < t < 2.29999999999999989e-12

    1. Initial program 98.9%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/96.8%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified96.8%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Taylor expanded in x around inf 63.4%

      \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{y}{t}\right) \cdot x} \]
    5. Step-by-step derivation
      1. *-commutative63.4%

        \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \frac{y}{t}\right)} \]
      2. distribute-lft-in63.4%

        \[\leadsto \color{blue}{x \cdot 1 + x \cdot \left(-1 \cdot \frac{y}{t}\right)} \]
      3. *-rgt-identity63.4%

        \[\leadsto \color{blue}{x} + x \cdot \left(-1 \cdot \frac{y}{t}\right) \]
      4. mul-1-neg63.4%

        \[\leadsto x + x \cdot \color{blue}{\left(-\frac{y}{t}\right)} \]
      5. distribute-rgt-neg-in63.4%

        \[\leadsto x + \color{blue}{\left(-x \cdot \frac{y}{t}\right)} \]
      6. unsub-neg63.4%

        \[\leadsto \color{blue}{x - x \cdot \frac{y}{t}} \]
    6. Simplified63.4%

      \[\leadsto \color{blue}{x - x \cdot \frac{y}{t}} \]
    7. Step-by-step derivation
      1. clear-num63.4%

        \[\leadsto x - x \cdot \color{blue}{\frac{1}{\frac{t}{y}}} \]
      2. un-div-inv64.3%

        \[\leadsto x - \color{blue}{\frac{x}{\frac{t}{y}}} \]
    8. Applied egg-rr64.3%

      \[\leadsto x - \color{blue}{\frac{x}{\frac{t}{y}}} \]
    9. Taylor expanded in t around 0 51.7%

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot x}{t}} \]
    10. Step-by-step derivation
      1. mul-1-neg51.7%

        \[\leadsto \color{blue}{-\frac{y \cdot x}{t}} \]
      2. associate-*l/51.7%

        \[\leadsto -\color{blue}{\frac{y}{t} \cdot x} \]
      3. distribute-rgt-neg-in51.7%

        \[\leadsto \color{blue}{\frac{y}{t} \cdot \left(-x\right)} \]
    11. Simplified51.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -2.7 \cdot 10^{-105}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 8.8 \cdot 10^{-156} \lor \neg \left(t \leq 8.5 \cdot 10^{-113}\right) \land t \leq 2.3 \cdot 10^{-12}:\\ \;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 4: 85.4% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.45 \cdot 10^{-103}:\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-82}:\\ \;\;\;\;x - x \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= z -1.45e-103)
   (+ x (* z (/ y t)))
   (if (<= z 1.9e-82) (- x (* x (/ y t))) (+ x (/ z (/ t y))))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= -1.45e-103) {
		tmp = x + (z * (y / t));
	} else if (z <= 1.9e-82) {
		tmp = x - (x * (y / t));
	} else {
		tmp = x + (z / (t / y));
	}
	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
    real(8) :: tmp
    if (z <= (-1.45d-103)) then
        tmp = x + (z * (y / t))
    else if (z <= 1.9d-82) then
        tmp = x - (x * (y / t))
    else
        tmp = x + (z / (t / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= -1.45e-103) {
		tmp = x + (z * (y / t));
	} else if (z <= 1.9e-82) {
		tmp = x - (x * (y / t));
	} else {
		tmp = x + (z / (t / y));
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if z <= -1.45e-103:
		tmp = x + (z * (y / t))
	elif z <= 1.9e-82:
		tmp = x - (x * (y / t))
	else:
		tmp = x + (z / (t / y))
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (z <= -1.45e-103)
		tmp = Float64(x + Float64(z * Float64(y / t)));
	elseif (z <= 1.9e-82)
		tmp = Float64(x - Float64(x * Float64(y / t)));
	else
		tmp = Float64(x + Float64(z / Float64(t / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (z <= -1.45e-103)
		tmp = x + (z * (y / t));
	elseif (z <= 1.9e-82)
		tmp = x - (x * (y / t));
	else
		tmp = x + (z / (t / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.45e-103], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.9e-82], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{-103}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\

\mathbf{elif}\;z \leq 1.9 \cdot 10^{-82}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\

\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.4499999999999999e-103

    1. Initial program 96.5%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/96.8%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified96.8%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Taylor expanded in z around inf 86.6%

      \[\leadsto x + \color{blue}{\frac{y \cdot z}{t}} \]
    5. Step-by-step derivation
      1. associate-*l/88.1%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot z} \]
      2. *-commutative88.1%

        \[\leadsto x + \color{blue}{z \cdot \frac{y}{t}} \]
    6. Simplified88.1%

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

    if -1.4499999999999999e-103 < z < 1.9000000000000001e-82

    1. Initial program 94.7%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/96.7%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified96.7%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Taylor expanded in x around inf 91.3%

      \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{y}{t}\right) \cdot x} \]
    5. Step-by-step derivation
      1. *-commutative91.3%

        \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \frac{y}{t}\right)} \]
      2. distribute-lft-in91.3%

        \[\leadsto \color{blue}{x \cdot 1 + x \cdot \left(-1 \cdot \frac{y}{t}\right)} \]
      3. *-rgt-identity91.3%

        \[\leadsto \color{blue}{x} + x \cdot \left(-1 \cdot \frac{y}{t}\right) \]
      4. mul-1-neg91.3%

        \[\leadsto x + x \cdot \color{blue}{\left(-\frac{y}{t}\right)} \]
      5. distribute-rgt-neg-in91.3%

        \[\leadsto x + \color{blue}{\left(-x \cdot \frac{y}{t}\right)} \]
      6. unsub-neg91.3%

        \[\leadsto \color{blue}{x - x \cdot \frac{y}{t}} \]
    6. Simplified91.3%

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

    if 1.9000000000000001e-82 < z

    1. Initial program 89.9%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/97.7%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified97.7%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Step-by-step derivation
      1. *-commutative97.7%

        \[\leadsto x + \color{blue}{\left(z - x\right) \cdot \frac{y}{t}} \]
      2. clear-num97.7%

        \[\leadsto x + \left(z - x\right) \cdot \color{blue}{\frac{1}{\frac{t}{y}}} \]
      3. un-div-inv97.8%

        \[\leadsto x + \color{blue}{\frac{z - x}{\frac{t}{y}}} \]
    5. Applied egg-rr97.8%

      \[\leadsto x + \color{blue}{\frac{z - x}{\frac{t}{y}}} \]
    6. Taylor expanded in z around inf 82.0%

      \[\leadsto x + \color{blue}{\frac{y \cdot z}{t}} \]
    7. Step-by-step derivation
      1. *-commutative82.0%

        \[\leadsto x + \frac{\color{blue}{z \cdot y}}{t} \]
      2. associate-/l*87.6%

        \[\leadsto x + \color{blue}{\frac{z}{\frac{t}{y}}} \]
    8. Simplified87.6%

      \[\leadsto x + \color{blue}{\frac{z}{\frac{t}{y}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.45 \cdot 10^{-103}:\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-82}:\\ \;\;\;\;x - x \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \end{array} \]

Alternative 5: 85.4% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -5.3 \cdot 10^{-103}:\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-82}:\\ \;\;\;\;x - \frac{x}{\frac{t}{y}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= z -5.3e-103)
   (+ x (* z (/ y t)))
   (if (<= z 1.6e-82) (- x (/ x (/ t y))) (+ x (/ z (/ t y))))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= -5.3e-103) {
		tmp = x + (z * (y / t));
	} else if (z <= 1.6e-82) {
		tmp = x - (x / (t / y));
	} else {
		tmp = x + (z / (t / y));
	}
	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
    real(8) :: tmp
    if (z <= (-5.3d-103)) then
        tmp = x + (z * (y / t))
    else if (z <= 1.6d-82) then
        tmp = x - (x / (t / y))
    else
        tmp = x + (z / (t / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= -5.3e-103) {
		tmp = x + (z * (y / t));
	} else if (z <= 1.6e-82) {
		tmp = x - (x / (t / y));
	} else {
		tmp = x + (z / (t / y));
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if z <= -5.3e-103:
		tmp = x + (z * (y / t))
	elif z <= 1.6e-82:
		tmp = x - (x / (t / y))
	else:
		tmp = x + (z / (t / y))
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (z <= -5.3e-103)
		tmp = Float64(x + Float64(z * Float64(y / t)));
	elseif (z <= 1.6e-82)
		tmp = Float64(x - Float64(x / Float64(t / y)));
	else
		tmp = Float64(x + Float64(z / Float64(t / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (z <= -5.3e-103)
		tmp = x + (z * (y / t));
	elseif (z <= 1.6e-82)
		tmp = x - (x / (t / y));
	else
		tmp = x + (z / (t / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[z, -5.3e-103], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.6e-82], N[(x - N[(x / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.3 \cdot 10^{-103}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\

\mathbf{elif}\;z \leq 1.6 \cdot 10^{-82}:\\
\;\;\;\;x - \frac{x}{\frac{t}{y}}\\

\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -5.30000000000000006e-103

    1. Initial program 96.5%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/96.8%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified96.8%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Taylor expanded in z around inf 86.6%

      \[\leadsto x + \color{blue}{\frac{y \cdot z}{t}} \]
    5. Step-by-step derivation
      1. associate-*l/88.1%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot z} \]
      2. *-commutative88.1%

        \[\leadsto x + \color{blue}{z \cdot \frac{y}{t}} \]
    6. Simplified88.1%

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

    if -5.30000000000000006e-103 < z < 1.6000000000000001e-82

    1. Initial program 94.7%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/96.7%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified96.7%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Taylor expanded in x around inf 91.3%

      \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{y}{t}\right) \cdot x} \]
    5. Step-by-step derivation
      1. *-commutative91.3%

        \[\leadsto \color{blue}{x \cdot \left(1 + -1 \cdot \frac{y}{t}\right)} \]
      2. distribute-lft-in91.3%

        \[\leadsto \color{blue}{x \cdot 1 + x \cdot \left(-1 \cdot \frac{y}{t}\right)} \]
      3. *-rgt-identity91.3%

        \[\leadsto \color{blue}{x} + x \cdot \left(-1 \cdot \frac{y}{t}\right) \]
      4. mul-1-neg91.3%

        \[\leadsto x + x \cdot \color{blue}{\left(-\frac{y}{t}\right)} \]
      5. distribute-rgt-neg-in91.3%

        \[\leadsto x + \color{blue}{\left(-x \cdot \frac{y}{t}\right)} \]
      6. unsub-neg91.3%

        \[\leadsto \color{blue}{x - x \cdot \frac{y}{t}} \]
    6. Simplified91.3%

      \[\leadsto \color{blue}{x - x \cdot \frac{y}{t}} \]
    7. Step-by-step derivation
      1. clear-num91.3%

        \[\leadsto x - x \cdot \color{blue}{\frac{1}{\frac{t}{y}}} \]
      2. un-div-inv92.2%

        \[\leadsto x - \color{blue}{\frac{x}{\frac{t}{y}}} \]
    8. Applied egg-rr92.2%

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

    if 1.6000000000000001e-82 < z

    1. Initial program 89.9%

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Step-by-step derivation
      1. associate-*l/97.7%

        \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
    3. Simplified97.7%

      \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
    4. Step-by-step derivation
      1. *-commutative97.7%

        \[\leadsto x + \color{blue}{\left(z - x\right) \cdot \frac{y}{t}} \]
      2. clear-num97.7%

        \[\leadsto x + \left(z - x\right) \cdot \color{blue}{\frac{1}{\frac{t}{y}}} \]
      3. un-div-inv97.8%

        \[\leadsto x + \color{blue}{\frac{z - x}{\frac{t}{y}}} \]
    5. Applied egg-rr97.8%

      \[\leadsto x + \color{blue}{\frac{z - x}{\frac{t}{y}}} \]
    6. Taylor expanded in z around inf 82.0%

      \[\leadsto x + \color{blue}{\frac{y \cdot z}{t}} \]
    7. Step-by-step derivation
      1. *-commutative82.0%

        \[\leadsto x + \frac{\color{blue}{z \cdot y}}{t} \]
      2. associate-/l*87.6%

        \[\leadsto x + \color{blue}{\frac{z}{\frac{t}{y}}} \]
    8. Simplified87.6%

      \[\leadsto x + \color{blue}{\frac{z}{\frac{t}{y}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.3 \cdot 10^{-103}:\\ \;\;\;\;x + z \cdot \frac{y}{t}\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-82}:\\ \;\;\;\;x - \frac{x}{\frac{t}{y}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{\frac{t}{y}}\\ \end{array} \]

Alternative 6: 97.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \left(z - x\right) \cdot \frac{y}{t} \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (* (- z x) (/ y t))))
double code(double x, double y, double z, double t) {
	return x + ((z - x) * (y / t));
}
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 + ((z - x) * (y / t))
end function
public static double code(double x, double y, double z, double t) {
	return x + ((z - x) * (y / t));
}
def code(x, y, z, t):
	return x + ((z - x) * (y / t))
function code(x, y, z, t)
	return Float64(x + Float64(Float64(z - x) * Float64(y / t)))
end
function tmp = code(x, y, z, t)
	tmp = x + ((z - x) * (y / t));
end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \left(z - x\right) \cdot \frac{y}{t}
\end{array}
Derivation
  1. Initial program 93.6%

    \[x + \frac{y \cdot \left(z - x\right)}{t} \]
  2. Step-by-step derivation
    1. associate-*l/97.1%

      \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
  3. Simplified97.1%

    \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
  4. Final simplification97.1%

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

Alternative 7: 76.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ x + z \cdot \frac{y}{t} \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (* z (/ y t))))
double code(double x, double y, double z, double t) {
	return x + (z * (y / t));
}
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 + (z * (y / t))
end function
public static double code(double x, double y, double z, double t) {
	return x + (z * (y / t));
}
def code(x, y, z, t):
	return x + (z * (y / t))
function code(x, y, z, t)
	return Float64(x + Float64(z * Float64(y / t)))
end
function tmp = code(x, y, z, t)
	tmp = x + (z * (y / t));
end
code[x_, y_, z_, t_] := N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + z \cdot \frac{y}{t}
\end{array}
Derivation
  1. Initial program 93.6%

    \[x + \frac{y \cdot \left(z - x\right)}{t} \]
  2. Step-by-step derivation
    1. associate-*l/97.1%

      \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
  3. Simplified97.1%

    \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
  4. Taylor expanded in z around inf 74.7%

    \[\leadsto x + \color{blue}{\frac{y \cdot z}{t}} \]
  5. Step-by-step derivation
    1. associate-*l/77.6%

      \[\leadsto x + \color{blue}{\frac{y}{t} \cdot z} \]
    2. *-commutative77.6%

      \[\leadsto x + \color{blue}{z \cdot \frac{y}{t}} \]
  6. Simplified77.6%

    \[\leadsto x + \color{blue}{z \cdot \frac{y}{t}} \]
  7. Final simplification77.6%

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

Alternative 8: 39.0% accurate, 9.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
	return x;
}
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
end function
public static double code(double x, double y, double z, double t) {
	return x;
}
def code(x, y, z, t):
	return x
function code(x, y, z, t)
	return x
end
function tmp = code(x, y, z, t)
	tmp = x;
end
code[x_, y_, z_, t_] := x
\begin{array}{l}

\\
x
\end{array}
Derivation
  1. Initial program 93.6%

    \[x + \frac{y \cdot \left(z - x\right)}{t} \]
  2. Step-by-step derivation
    1. associate-*l/97.1%

      \[\leadsto x + \color{blue}{\frac{y}{t} \cdot \left(z - x\right)} \]
  3. Simplified97.1%

    \[\leadsto \color{blue}{x + \frac{y}{t} \cdot \left(z - x\right)} \]
  4. Taylor expanded in y around 0 39.5%

    \[\leadsto \color{blue}{x} \]
  5. Final simplification39.5%

    \[\leadsto x \]

Developer target: 90.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
double code(double x, double y, double z, double t) {
	return x - ((x * (y / t)) + (-z * (y / t)));
}
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 - ((x * (y / t)) + (-z * (y / t)))
end function
public static double code(double x, double y, double z, double t) {
	return x - ((x * (y / t)) + (-z * (y / t)));
}
def code(x, y, z, t):
	return x - ((x * (y / t)) + (-z * (y / t)))
function code(x, y, z, t)
	return Float64(x - Float64(Float64(x * Float64(y / t)) + Float64(Float64(-z) * Float64(y / t))))
end
function tmp = code(x, y, z, t)
	tmp = x - ((x * (y / t)) + (-z * (y / t)));
end
code[x_, y_, z_, t_] := N[(x - N[(N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision] + N[((-z) * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)
\end{array}

Reproduce

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

  :herbie-target
  (- x (+ (* x (/ y t)) (* (- z) (/ y t))))

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