
(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 91.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.1
Applied rewrites98.1%
(FPCore (x y z t) :precision binary64 (if (or (<= x -4.6e+61) (not (<= x 4.2e-54))) (* (- 1.0 (/ y t)) x) (+ x (/ (* z y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4.6e+61) || !(x <= 4.2e-54)) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = x + ((z * 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 ((x <= (-4.6d+61)) .or. (.not. (x <= 4.2d-54))) then
tmp = (1.0d0 - (y / t)) * x
else
tmp = x + ((z * y) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4.6e+61) || !(x <= 4.2e-54)) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = x + ((z * y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -4.6e+61) or not (x <= 4.2e-54): tmp = (1.0 - (y / t)) * x else: tmp = x + ((z * y) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -4.6e+61) || !(x <= 4.2e-54)) tmp = Float64(Float64(1.0 - Float64(y / t)) * x); else tmp = Float64(x + Float64(Float64(z * y) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -4.6e+61) || ~((x <= 4.2e-54))) tmp = (1.0 - (y / t)) * x; else tmp = x + ((z * y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -4.6e+61], N[Not[LessEqual[x, 4.2e-54]], $MachinePrecision]], 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}\;x \leq -4.6 \cdot 10^{+61} \lor \neg \left(x \leq 4.2 \cdot 10^{-54}\right):\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\end{array}
\end{array}
if x < -4.5999999999999999e61 or 4.2e-54 < x Initial program 89.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-/.f6488.3
Applied rewrites88.3%
if -4.5999999999999999e61 < x < 4.2e-54Initial program 93.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6484.6
Applied rewrites84.6%
Final simplification86.4%
(FPCore (x y z t) :precision binary64 (if (or (<= x -9.2e-17) (not (<= x 3.7e-81))) (* (- 1.0 (/ y t)) x) (* (/ (- z x) t) y)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -9.2e-17) || !(x <= 3.7e-81)) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = ((z - x) / 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 ((x <= (-9.2d-17)) .or. (.not. (x <= 3.7d-81))) then
tmp = (1.0d0 - (y / t)) * x
else
tmp = ((z - x) / t) * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -9.2e-17) || !(x <= 3.7e-81)) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = ((z - x) / t) * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -9.2e-17) or not (x <= 3.7e-81): tmp = (1.0 - (y / t)) * x else: tmp = ((z - x) / t) * y return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -9.2e-17) || !(x <= 3.7e-81)) tmp = Float64(Float64(1.0 - Float64(y / t)) * x); else tmp = Float64(Float64(Float64(z - x) / t) * y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -9.2e-17) || ~((x <= 3.7e-81))) tmp = (1.0 - (y / t)) * x; else tmp = ((z - x) / t) * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -9.2e-17], N[Not[LessEqual[x, 3.7e-81]], $MachinePrecision]], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.2 \cdot 10^{-17} \lor \neg \left(x \leq 3.7 \cdot 10^{-81}\right):\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{z - x}{t} \cdot y\\
\end{array}
\end{array}
if x < -9.20000000000000035e-17 or 3.69999999999999986e-81 < x Initial program 90.6%
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-/.f6485.2
Applied rewrites85.2%
if -9.20000000000000035e-17 < x < 3.69999999999999986e-81Initial program 92.4%
Taylor expanded in y around inf
div-subN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6473.9
Applied rewrites73.9%
Final simplification80.6%
(FPCore (x y z t) :precision binary64 (if (or (<= x -3.6e-119) (not (<= x 3.3e-81))) (* (- 1.0 (/ y t)) x) (* z (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -3.6e-119) || !(x <= 3.3e-81)) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = z * (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 ((x <= (-3.6d-119)) .or. (.not. (x <= 3.3d-81))) then
tmp = (1.0d0 - (y / t)) * x
else
tmp = z * (y / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -3.6e-119) || !(x <= 3.3e-81)) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = z * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -3.6e-119) or not (x <= 3.3e-81): tmp = (1.0 - (y / t)) * x else: tmp = z * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -3.6e-119) || !(x <= 3.3e-81)) tmp = Float64(Float64(1.0 - Float64(y / t)) * x); else tmp = Float64(z * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -3.6e-119) || ~((x <= 3.3e-81))) tmp = (1.0 - (y / t)) * x; else tmp = z * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -3.6e-119], N[Not[LessEqual[x, 3.3e-81]], $MachinePrecision]], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-119} \lor \neg \left(x \leq 3.3 \cdot 10^{-81}\right):\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -3.6e-119 or 3.29999999999999987e-81 < x Initial program 90.4%
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-/.f6481.6
Applied rewrites81.6%
if -3.6e-119 < x < 3.29999999999999987e-81Initial program 93.0%
Taylor expanded in x around 0
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6469.2
Applied rewrites69.2%
Applied rewrites72.4%
Final simplification78.5%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.8e+96) (not (<= x 6e-27))) (* (- x) (/ y t)) (* z (/ y t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.8e+96) || !(x <= 6e-27)) {
tmp = -x * (y / t);
} else {
tmp = z * (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 ((x <= (-1.8d+96)) .or. (.not. (x <= 6d-27))) then
tmp = -x * (y / t)
else
tmp = z * (y / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.8e+96) || !(x <= 6e-27)) {
tmp = -x * (y / t);
} else {
tmp = z * (y / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.8e+96) or not (x <= 6e-27): tmp = -x * (y / t) else: tmp = z * (y / t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.8e+96) || !(x <= 6e-27)) tmp = Float64(Float64(-x) * Float64(y / t)); else tmp = Float64(z * Float64(y / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.8e+96) || ~((x <= 6e-27))) tmp = -x * (y / t); else tmp = z * (y / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.8e+96], N[Not[LessEqual[x, 6e-27]], $MachinePrecision]], N[((-x) * N[(y / t), $MachinePrecision]), $MachinePrecision], N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+96} \lor \neg \left(x \leq 6 \cdot 10^{-27}\right):\\
\;\;\;\;\left(-x\right) \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -1.80000000000000007e96 or 6.0000000000000002e-27 < x Initial program 88.3%
Taylor expanded in y around inf
div-subN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6447.4
Applied rewrites47.4%
Taylor expanded in x around inf
Applied rewrites40.9%
if -1.80000000000000007e96 < x < 6.0000000000000002e-27Initial program 93.7%
Taylor expanded in x around 0
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6458.8
Applied rewrites58.8%
Applied rewrites61.4%
Final simplification52.3%
(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.3%
Taylor expanded in x around 0
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6440.5
Applied rewrites40.5%
Applied rewrites42.4%
(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 2024343
(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)))