
(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:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (x y z t) :precision binary64 (if (<= y -1e+107) (fma y (/ (- z x) t) x) (+ x (* (- z x) (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1e+107) {
tmp = fma(y, ((z - x) / t), x);
} else {
tmp = x + ((z - x) * (y / t));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -1e+107) tmp = fma(y, Float64(Float64(z - x) / t), x); else tmp = Float64(x + Float64(Float64(z - x) * Float64(y / t))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -1e+107], N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{+107}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(z - x\right) \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < -9.9999999999999997e106Initial program 79.0%
+-commutative79.0%
associate-*r/99.8%
fma-def99.8%
Simplified99.8%
if -9.9999999999999997e106 < y Initial program 94.0%
associate-*l/98.4%
Simplified98.4%
Final simplification98.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6e-73) (not (<= z 5.8e-124))) (+ x (* z (/ y t))) (- x (* y (/ x t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6e-73) || !(z <= 5.8e-124)) {
tmp = x + (z * (y / t));
} else {
tmp = x - (y * (x / t));
}
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 <= (-6d-73)) .or. (.not. (z <= 5.8d-124))) then
tmp = x + (z * (y / t))
else
tmp = x - (y * (x / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6e-73) || !(z <= 5.8e-124)) {
tmp = x + (z * (y / t));
} else {
tmp = x - (y * (x / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6e-73) or not (z <= 5.8e-124): tmp = x + (z * (y / t)) else: tmp = x - (y * (x / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6e-73) || !(z <= 5.8e-124)) tmp = Float64(x + Float64(z * Float64(y / t))); else tmp = Float64(x - Float64(y * Float64(x / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -6e-73) || ~((z <= 5.8e-124))) tmp = x + (z * (y / t)); else tmp = x - (y * (x / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6e-73], N[Not[LessEqual[z, 5.8e-124]], $MachinePrecision]], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * N[(x / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{-73} \lor \neg \left(z \leq 5.8 \cdot 10^{-124}\right):\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot \frac{x}{t}\\
\end{array}
\end{array}
if z < -6e-73 or 5.8000000000000004e-124 < z Initial program 88.6%
associate-*l/99.2%
Simplified99.2%
Taylor expanded in z around inf 79.3%
associate-*l/88.1%
*-commutative88.1%
Simplified88.1%
if -6e-73 < z < 5.8000000000000004e-124Initial program 93.0%
+-commutative93.0%
associate-*r/96.9%
fma-def96.9%
Simplified96.9%
Taylor expanded in z around 0 85.1%
+-commutative85.1%
mul-1-neg85.1%
unsub-neg85.1%
*-commutative85.1%
associate-/l*88.2%
Simplified88.2%
associate-/r/89.0%
Applied egg-rr89.0%
Final simplification88.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -5.2e-69) (not (<= z 3.4e-118))) (+ x (* z (/ y t))) (- x (/ y (/ t x)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5.2e-69) || !(z <= 3.4e-118)) {
tmp = x + (z * (y / t));
} else {
tmp = x - (y / (t / 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 ((z <= (-5.2d-69)) .or. (.not. (z <= 3.4d-118))) then
tmp = x + (z * (y / t))
else
tmp = x - (y / (t / x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5.2e-69) || !(z <= 3.4e-118)) {
tmp = x + (z * (y / t));
} else {
tmp = x - (y / (t / x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -5.2e-69) or not (z <= 3.4e-118): tmp = x + (z * (y / t)) else: tmp = x - (y / (t / x)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -5.2e-69) || !(z <= 3.4e-118)) tmp = Float64(x + Float64(z * Float64(y / t))); else tmp = Float64(x - Float64(y / Float64(t / x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -5.2e-69) || ~((z <= 3.4e-118))) tmp = x + (z * (y / t)); else tmp = x - (y / (t / x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -5.2e-69], N[Not[LessEqual[z, 3.4e-118]], $MachinePrecision]], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(y / N[(t / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{-69} \lor \neg \left(z \leq 3.4 \cdot 10^{-118}\right):\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{\frac{t}{x}}\\
\end{array}
\end{array}
if z < -5.2000000000000004e-69 or 3.39999999999999991e-118 < z Initial program 88.6%
associate-*l/99.2%
Simplified99.2%
Taylor expanded in z around inf 79.3%
associate-*l/88.1%
*-commutative88.1%
Simplified88.1%
if -5.2000000000000004e-69 < z < 3.39999999999999991e-118Initial program 93.0%
+-commutative93.0%
associate-*r/96.9%
fma-def96.9%
Simplified96.9%
Taylor expanded in z around 0 85.1%
+-commutative85.1%
mul-1-neg85.1%
unsub-neg85.1%
*-commutative85.1%
associate-/l*88.2%
Simplified88.2%
Taylor expanded in x around 0 85.1%
associate-/l*90.0%
Simplified90.0%
Final simplification88.8%
(FPCore (x y z t) :precision binary64 (if (<= y -3e+125) (+ x (/ y (/ t (- z x)))) (+ x (* (- z x) (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -3e+125) {
tmp = x + (y / (t / (z - x)));
} else {
tmp = x + ((z - x) * (y / t));
}
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 (y <= (-3d+125)) then
tmp = x + (y / (t / (z - x)))
else
tmp = x + ((z - x) * (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -3e+125) {
tmp = x + (y / (t / (z - x)));
} else {
tmp = x + ((z - x) * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -3e+125: tmp = x + (y / (t / (z - x))) else: tmp = x + ((z - x) * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -3e+125) tmp = Float64(x + Float64(y / Float64(t / Float64(z - x)))); else tmp = Float64(x + Float64(Float64(z - x) * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -3e+125) tmp = x + (y / (t / (z - x))); else tmp = x + ((z - x) * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -3e+125], N[(x + N[(y / N[(t / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+125}:\\
\;\;\;\;x + \frac{y}{\frac{t}{z - x}}\\
\mathbf{else}:\\
\;\;\;\;x + \left(z - x\right) \cdot \frac{y}{t}\\
\end{array}
\end{array}
if y < -3.00000000000000015e125Initial program 78.0%
associate-/l*99.7%
Simplified99.7%
if -3.00000000000000015e125 < y Initial program 93.7%
associate-*l/98.5%
Simplified98.5%
Final simplification98.7%
(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}
Initial program 90.3%
associate-*l/96.9%
Simplified96.9%
Final simplification96.9%
(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}
Initial program 90.3%
associate-*l/96.9%
Simplified96.9%
Taylor expanded in z around inf 67.7%
associate-*l/73.5%
*-commutative73.5%
Simplified73.5%
Final simplification73.5%
(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}
Initial program 90.3%
+-commutative90.3%
associate-*r/95.0%
fma-def95.0%
Simplified95.0%
Taylor expanded in y around 0 35.8%
Final simplification35.8%
(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}
herbie shell --seed 2023238
(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)))