
(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 (fma (/ y t) (- z x) x))
double code(double x, double y, double z, double t) {
return fma((y / t), (z - x), x);
}
function code(x, y, z, t) return fma(Float64(y / t), Float64(z - x), x) end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)
\end{array}
Initial program 93.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.0
Applied rewrites97.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.1e-16) (not (<= z 9.2e-125))) (fma (/ z t) y x) (* (- 1.0 (/ y t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.1e-16) || !(z <= 9.2e-125)) {
tmp = fma((z / t), y, x);
} else {
tmp = (1.0 - (y / t)) * x;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.1e-16) || !(z <= 9.2e-125)) tmp = fma(Float64(z / t), y, x); else tmp = Float64(Float64(1.0 - Float64(y / t)) * x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.1e-16], N[Not[LessEqual[z, 9.2e-125]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{-16} \lor \neg \left(z \leq 9.2 \cdot 10^{-125}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\end{array}
\end{array}
if z < -4.10000000000000006e-16 or 9.1999999999999996e-125 < z Initial program 92.8%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.1
Applied rewrites92.1%
Taylor expanded in x around 0
lower-/.f6487.0
Applied rewrites87.0%
if -4.10000000000000006e-16 < z < 9.1999999999999996e-125Initial program 93.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6488.8
Applied rewrites88.8%
Final simplification87.9%
(FPCore (x y z t) :precision binary64 (if (<= z -4.1e-16) (fma (/ z t) y x) (if (<= z 9.2e-125) (* (- 1.0 (/ y t)) x) (+ x (/ (* z y) t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -4.1e-16) {
tmp = fma((z / t), y, x);
} else if (z <= 9.2e-125) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = x + ((z * y) / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -4.1e-16) tmp = fma(Float64(z / t), y, x); elseif (z <= 9.2e-125) tmp = Float64(Float64(1.0 - Float64(y / t)) * x); else tmp = Float64(x + Float64(Float64(z * y) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -4.1e-16], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 9.2e-125], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(x + N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{elif}\;z \leq 9.2 \cdot 10^{-125}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\end{array}
\end{array}
if z < -4.10000000000000006e-16Initial program 86.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6495.6
Applied rewrites95.6%
Taylor expanded in x around 0
lower-/.f6490.5
Applied rewrites90.5%
if -4.10000000000000006e-16 < z < 9.1999999999999996e-125Initial program 93.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f6488.8
Applied rewrites88.8%
if 9.1999999999999996e-125 < z Initial program 98.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6490.6
Applied rewrites90.6%
Final simplification89.7%
(FPCore (x y z t) :precision binary64 (if (or (<= t -2.9e-226) (not (<= t 1.15e-239))) (fma (/ z t) y x) (* (- x) (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -2.9e-226) || !(t <= 1.15e-239)) {
tmp = fma((z / t), y, x);
} else {
tmp = -x * (y / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((t <= -2.9e-226) || !(t <= 1.15e-239)) tmp = fma(Float64(z / t), y, x); else tmp = Float64(Float64(-x) * Float64(y / t)); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -2.9e-226], N[Not[LessEqual[t, 1.15e-239]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[((-x) * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.9 \cdot 10^{-226} \lor \neg \left(t \leq 1.15 \cdot 10^{-239}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) \cdot \frac{y}{t}\\
\end{array}
\end{array}
if t < -2.90000000000000002e-226 or 1.1499999999999999e-239 < t Initial program 92.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.7
Applied rewrites93.7%
Taylor expanded in x around 0
lower-/.f6477.9
Applied rewrites77.9%
if -2.90000000000000002e-226 < t < 1.1499999999999999e-239Initial program 99.7%
Taylor expanded in y around inf
div-subN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6489.4
Applied rewrites89.4%
Taylor expanded in x around inf
Applied rewrites64.5%
Applied rewrites69.6%
Final simplification76.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9e-203) (not (<= z 1.65e-273))) (fma (/ z t) y x) (* (/ (- x) t) y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9e-203) || !(z <= 1.65e-273)) {
tmp = fma((z / t), y, x);
} else {
tmp = (-x / t) * y;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -9e-203) || !(z <= 1.65e-273)) tmp = fma(Float64(z / t), y, x); else tmp = Float64(Float64(Float64(-x) / t) * y); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9e-203], N[Not[LessEqual[z, 1.65e-273]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[((-x) / t), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-203} \lor \neg \left(z \leq 1.65 \cdot 10^{-273}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{t} \cdot y\\
\end{array}
\end{array}
if z < -9.0000000000000003e-203 or 1.64999999999999995e-273 < z Initial program 94.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.4
Applied rewrites92.4%
Taylor expanded in x around 0
lower-/.f6478.6
Applied rewrites78.6%
if -9.0000000000000003e-203 < z < 1.64999999999999995e-273Initial program 86.8%
Taylor expanded in y around inf
div-subN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6463.8
Applied rewrites63.8%
Taylor expanded in x around inf
Applied rewrites63.8%
Final simplification76.5%
(FPCore (x y z t) :precision binary64 (fma (/ z t) y x))
double code(double x, double y, double z, double t) {
return fma((z / t), y, x);
}
function code(x, y, z, t) return fma(Float64(z / t), y, x) end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z}{t}, y, x\right)
\end{array}
Initial program 93.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.1
Applied rewrites93.1%
Taylor expanded in x around 0
lower-/.f6472.6
Applied rewrites72.6%
(FPCore (x y z t) :precision binary64 (* z (/ y t)))
double code(double x, double y, double z, double t) {
return 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 = z * (y / t)
end function
public static double code(double x, double y, double z, double t) {
return z * (y / t);
}
def code(x, y, z, t): return z * (y / t)
function code(x, y, z, t) return Float64(z * Float64(y / t)) end
function tmp = code(x, y, z, t) tmp = z * (y / t); end
code[x_, y_, z_, t_] := N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \frac{y}{t}
\end{array}
Initial program 93.2%
Taylor expanded in x around 0
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6436.8
Applied rewrites36.8%
Applied rewrites39.2%
Final simplification39.2%
(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 2024326
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:alt
(! :herbie-platform default (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
(+ x (/ (* y (- z x)) t)))