
(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 6 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 92.9%
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 (<= z -6.8e-96) (not (<= z 3.15e-51))) (fma (/ z t) y x) (fma (/ y t) (- x) x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.8e-96) || !(z <= 3.15e-51)) {
tmp = fma((z / t), y, x);
} else {
tmp = fma((y / t), -x, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.8e-96) || !(z <= 3.15e-51)) tmp = fma(Float64(z / t), y, x); else tmp = fma(Float64(y / t), Float64(-x), x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.8e-96], N[Not[LessEqual[z, 3.15e-51]], $MachinePrecision]], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * (-x) + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{-96} \lor \neg \left(z \leq 3.15 \cdot 10^{-51}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, -x, x\right)\\
\end{array}
\end{array}
if z < -6.8000000000000002e-96 or 3.1499999999999999e-51 < z Initial program 91.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6495.2
Applied rewrites95.2%
Taylor expanded in x around 0
lower-/.f6489.6
Applied rewrites89.6%
if -6.8000000000000002e-96 < z < 3.1499999999999999e-51Initial program 95.0%
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.6
Applied rewrites96.6%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6489.2
Applied rewrites89.2%
Final simplification89.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6.8e-96) (not (<= z 3.15e-51))) (fma (/ z t) y x) (* (- 1.0 (/ y t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.8e-96) || !(z <= 3.15e-51)) {
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 <= -6.8e-96) || !(z <= 3.15e-51)) 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, -6.8e-96], N[Not[LessEqual[z, 3.15e-51]], $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 -6.8 \cdot 10^{-96} \lor \neg \left(z \leq 3.15 \cdot 10^{-51}\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 < -6.8000000000000002e-96 or 3.1499999999999999e-51 < z Initial program 91.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6495.2
Applied rewrites95.2%
Taylor expanded in x around 0
lower-/.f6489.6
Applied rewrites89.6%
if -6.8000000000000002e-96 < z < 3.1499999999999999e-51Initial program 95.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6489.2
Applied rewrites89.2%
Final simplification89.5%
(FPCore (x y z t) :precision binary64 (if (<= y 4.8e+133) (fma (/ z t) y x) (* (/ (- x) t) y)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 4.8e+133) {
tmp = fma((z / t), y, x);
} else {
tmp = (-x / t) * y;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 4.8e+133) 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[LessEqual[y, 4.8e+133], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[((-x) / t), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.8 \cdot 10^{+133}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{t} \cdot y\\
\end{array}
\end{array}
if y < 4.7999999999999997e133Initial program 95.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.6
Applied rewrites93.6%
Taylor expanded in x around 0
lower-/.f6479.1
Applied rewrites79.1%
if 4.7999999999999997e133 < y Initial program 75.9%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6470.0
Applied rewrites70.0%
Taylor expanded in x around inf
Applied rewrites62.7%
(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 92.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.0
Applied rewrites94.0%
Taylor expanded in x around 0
lower-/.f6474.4
Applied rewrites74.4%
(FPCore (x y z t) :precision binary64 (* (/ y t) z))
double code(double x, double y, double z, double t) {
return (y / t) * z;
}
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 = (y / t) * z
end function
public static double code(double x, double y, double z, double t) {
return (y / t) * z;
}
def code(x, y, z, t): return (y / t) * z
function code(x, y, z, t) return Float64(Float64(y / t) * z) end
function tmp = code(x, y, z, t) tmp = (y / t) * z; end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{t} \cdot z
\end{array}
Initial program 92.9%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6435.4
Applied rewrites35.4%
Applied rewrites37.9%
(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 2024318
(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)))