
(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.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.8
Applied rewrites98.8%
(FPCore (x y z t) :precision binary64 (if (or (<= x -2.7e-30) (not (<= x 2.05e-119))) (* (- 1.0 (/ y t)) x) (+ x (/ (* z y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -2.7e-30) || !(x <= 2.05e-119)) {
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 <= (-2.7d-30)) .or. (.not. (x <= 2.05d-119))) 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 <= -2.7e-30) || !(x <= 2.05e-119)) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = x + ((z * y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -2.7e-30) or not (x <= 2.05e-119): 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 <= -2.7e-30) || !(x <= 2.05e-119)) 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 <= -2.7e-30) || ~((x <= 2.05e-119))) 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, -2.7e-30], N[Not[LessEqual[x, 2.05e-119]], $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 -2.7 \cdot 10^{-30} \lor \neg \left(x \leq 2.05 \cdot 10^{-119}\right):\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\end{array}
\end{array}
if x < -2.69999999999999987e-30 or 2.0500000000000001e-119 < x Initial program 89.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6486.1
Applied rewrites86.1%
if -2.69999999999999987e-30 < x < 2.0500000000000001e-119Initial program 95.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6491.6
Applied rewrites91.6%
Final simplification87.8%
(FPCore (x y z t) :precision binary64 (if (or (<= x -4.3e-30) (not (<= x 1.65e-80))) (* (- 1.0 (/ y t)) x) (fma (/ z t) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4.3e-30) || !(x <= 1.65e-80)) {
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 ((x <= -4.3e-30) || !(x <= 1.65e-80)) 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[Or[LessEqual[x, -4.3e-30], N[Not[LessEqual[x, 1.65e-80]], $MachinePrecision]], 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}\;x \leq -4.3 \cdot 10^{-30} \lor \neg \left(x \leq 1.65 \cdot 10^{-80}\right):\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\end{array}
\end{array}
if x < -4.29999999999999966e-30 or 1.65e-80 < x Initial program 89.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6487.3
Applied rewrites87.3%
if -4.29999999999999966e-30 < x < 1.65e-80Initial program 94.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.2
Applied rewrites94.2%
Taylor expanded in x around 0
lower-/.f6487.9
Applied rewrites87.9%
Final simplification87.5%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2e+175) (not (<= y 2e+237))) (* (/ y t) (- x)) (fma (/ z t) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2e+175) || !(y <= 2e+237)) {
tmp = (y / t) * -x;
} else {
tmp = fma((z / t), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -2e+175) || !(y <= 2e+237)) tmp = Float64(Float64(y / t) * Float64(-x)); else tmp = fma(Float64(z / t), y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2e+175], N[Not[LessEqual[y, 2e+237]], $MachinePrecision]], N[(N[(y / t), $MachinePrecision] * (-x)), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+175} \lor \neg \left(y \leq 2 \cdot 10^{+237}\right):\\
\;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\end{array}
\end{array}
if y < -1.9999999999999999e175 or 1.99999999999999988e237 < y Initial program 76.5%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.3
Applied rewrites75.3%
Taylor expanded in x around inf
Applied rewrites53.2%
Applied rewrites68.6%
if -1.9999999999999999e175 < y < 1.99999999999999988e237Initial program 94.8%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.1
Applied rewrites90.1%
Taylor expanded in x around 0
lower-/.f6474.6
Applied rewrites74.6%
Final simplification73.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.25e+175) (not (<= y 1.4e+221))) (* (/ (- x) t) y) (fma (/ z t) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.25e+175) || !(y <= 1.4e+221)) {
tmp = (-x / t) * y;
} else {
tmp = fma((z / t), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.25e+175) || !(y <= 1.4e+221)) tmp = Float64(Float64(Float64(-x) / t) * y); else tmp = fma(Float64(z / t), y, x); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.25e+175], N[Not[LessEqual[y, 1.4e+221]], $MachinePrecision]], N[(N[((-x) / t), $MachinePrecision] * y), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.25 \cdot 10^{+175} \lor \neg \left(y \leq 1.4 \cdot 10^{+221}\right):\\
\;\;\;\;\frac{-x}{t} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\end{array}
\end{array}
if y < -2.24999999999999995e175 or 1.39999999999999994e221 < y Initial program 77.4%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.2
Applied rewrites76.2%
Taylor expanded in x around inf
Applied rewrites65.5%
if -2.24999999999999995e175 < y < 1.39999999999999994e221Initial program 94.8%
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-/.f6474.8
Applied rewrites74.8%
Final simplification73.0%
(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.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.6
Applied rewrites91.6%
Taylor expanded in x around 0
lower-/.f6468.9
Applied rewrites68.9%
(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 91.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6434.1
Applied rewrites34.1%
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 2024313
(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)))