
(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 91.5%
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.3
Applied rewrites97.3%
(FPCore (x y z t) :precision binary64 (if (or (<= t -4e+17) (not (<= t 9.4e-101))) (fma (/ z t) y x) (/ (* (- z x) y) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -4e+17) || !(t <= 9.4e-101)) {
tmp = fma((z / t), y, x);
} else {
tmp = ((z - x) * y) / t;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((t <= -4e+17) || !(t <= 9.4e-101)) tmp = fma(Float64(z / t), y, x); else tmp = Float64(Float64(Float64(z - x) * y) / t); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -4e+17], N[Not[LessEqual[t, 9.4e-101]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4 \cdot 10^{+17} \lor \neg \left(t \leq 9.4 \cdot 10^{-101}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(z - x\right) \cdot y}{t}\\
\end{array}
\end{array}
if t < -4e17 or 9.3999999999999999e-101 < t Initial program 86.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.8
Applied rewrites97.8%
Taylor expanded in x around 0
lower-/.f6487.4
Applied rewrites87.4%
if -4e17 < t < 9.3999999999999999e-101Initial program 97.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.0
Applied rewrites96.0%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6484.5
Applied rewrites84.5%
Final simplification86.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -5.8e+72) (not (<= z 2.65e-5))) (fma (/ z t) y x) (* (- 1.0 (/ y t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -5.8e+72) || !(z <= 2.65e-5)) {
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 <= -5.8e+72) || !(z <= 2.65e-5)) 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, -5.8e+72], N[Not[LessEqual[z, 2.65e-5]], $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 -5.8 \cdot 10^{+72} \lor \neg \left(z \leq 2.65 \cdot 10^{-5}\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 < -5.80000000000000034e72 or 2.65e-5 < z Initial program 87.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6487.4
Applied rewrites87.4%
Taylor expanded in x around 0
lower-/.f6483.2
Applied rewrites83.2%
if -5.80000000000000034e72 < z < 2.65e-5Initial program 95.1%
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-/.f6486.6
Applied rewrites86.6%
Final simplification85.0%
(FPCore (x y z t) :precision binary64 (if (<= z -5.8e+72) (+ x (/ (* z y) t)) (if (<= z 2.65e-5) (* (- 1.0 (/ y t)) x) (fma (/ z t) y x))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -5.8e+72) {
tmp = x + ((z * y) / t);
} else if (z <= 2.65e-5) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = fma((z / t), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -5.8e+72) tmp = Float64(x + Float64(Float64(z * y) / t)); elseif (z <= 2.65e-5) tmp = Float64(Float64(1.0 - Float64(y / t)) * x); else tmp = fma(Float64(z / t), y, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -5.8e+72], N[(x + N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.65e-5], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{+72}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\mathbf{elif}\;z \leq 2.65 \cdot 10^{-5}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\end{array}
\end{array}
if z < -5.80000000000000034e72Initial program 91.1%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6491.0
Applied rewrites91.0%
if -5.80000000000000034e72 < z < 2.65e-5Initial program 95.1%
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-/.f6486.6
Applied rewrites86.6%
if 2.65e-5 < z Initial program 84.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.0
Applied rewrites90.0%
Taylor expanded in x around 0
lower-/.f6482.7
Applied rewrites82.7%
Final simplification86.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -1.8e-249) (not (<= z -1.15e-299))) (fma (/ z t) y x) (* (- x) (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -1.8e-249) || !(z <= -1.15e-299)) {
tmp = fma((z / t), y, x);
} else {
tmp = -x * (y / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -1.8e-249) || !(z <= -1.15e-299)) 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[z, -1.8e-249], N[Not[LessEqual[z, -1.15e-299]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[((-x) * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{-249} \lor \neg \left(z \leq -1.15 \cdot 10^{-299}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) \cdot \frac{y}{t}\\
\end{array}
\end{array}
if z < -1.79999999999999997e-249 or -1.15e-299 < z Initial program 91.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.2
Applied rewrites91.2%
Taylor expanded in x around 0
lower-/.f6473.4
Applied rewrites73.4%
if -1.79999999999999997e-249 < z < -1.15e-299Initial program 99.7%
Taylor expanded in y around inf
div-subN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6478.7
Applied rewrites78.7%
Taylor expanded in x around inf
Applied rewrites99.8%
Final simplification74.3%
(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 91.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.8
Applied rewrites90.8%
Taylor expanded in x around 0
lower-/.f6470.9
Applied rewrites70.9%
(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 91.5%
Taylor expanded in x around 0
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6434.9
Applied rewrites34.9%
Applied rewrites38.6%
Final simplification38.6%
(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 2024337
(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)))