tag:blogger.com,1999:blog-28890822945976253392019-08-05T20:24:53.066-07:00This Blog is Untitled呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-2889082294597625339.post-37351219437135798092019-07-24T08:16:00.004-07:002019-07-24T09:39:28.540-07:00Distribution of segments on Gaussian chain<p>The probability distribution function of $P_i(\mathbf{r}_i-\mathbf{r}_\mathrm{cm})$ of ideal chain is evaluated, for $P_i$ represents the probability distribution fucntion of $i$th segment with respect to its centre of mass on the ideal chain. An ideal chain is modeled as multidimensional random walk, where the steps are independent, and the distribution of a step at mean length $b$ is given by $P(\mathbf{r})\sim\mathcal{N}(0,b^2)$. Let $\mathbf{b}_i=\mathbf{r}_{i+1}-\mathbf{r}_{i}$ be the $i$th bond vector, then we have<br /><br />$$\mathbf{r}_i=\sum_{j=1}^{i-1} \mathbf{b}_j$$<br /><br />and the centre of mass $\mathbf{r}_\mathrm{cm}=\frac{1}{N}\sum_i \mathbf{r}_i$ is<br /><br />$$\mathbf{r}_\mathrm{cm}=\frac{1}{N}\sum_{j=1}^{N-1}(N-j)\mathbf{b}_j$$<br /><br />then<br /><br />$$\mathbf{r}_i-\mathbf{r}_\mathrm{cm}=\sum_{j=1}^{i-1}\frac{j}{N}\mathbf{b}_j+\sum_{j=i}^{N-1}\frac{N-j}{N}\mathbf{b}_j$$<br /><br />If variable $X$ is a Gaussian random variable with scale of $\sigma^2$, then $aX$ is a Gaussian random variable with scale of $a^2\sigma^2$, we can then write the characteristic function for $P_i(\mathbf{r}_i-\mathbf{r}_\mathrm{cm})$ of a $d$ dimensional ideal chain:<br /><br />$$\phi_i(\mathbf{q})=\Pi_{j} \phi_{\mathbf{b}_j'}(\mathbf{q})=\exp\left(-\frac{1}{2}\mathbf{q}^T\left(\sum_{j=1}^{N-1}\Sigma_j\right)\mathbf{q}\right)$$<br /><br />with $\mathbf{b}'_j=\frac{j}{N}\mathbf{b}_j$ for $j\le i-1$ and $\frac{N-j}{N}\mathbf{b}_j$ for $i\le j \le N-1$; $\phi_{\mathbf{b}_j'}=-\exp(-0.5\mathbf{q}^T\Sigma\mathbf{q})$ is the characteristic function of the probability distribution fucntion of bond $j$. $\Sigma_j=\frac{j^2 b^2}{d N^2}\mathbb{I}_d$ for $j\le i-1$ and $\Sigma_j=\frac{(N-j)^2 b^2}{d N^2}\mathbb{I}_d$ for $i\le j \le N-1$, and $\mathbb{I}_d$ is the $d$-dimensional identical matrix, and therefore: (For convenience, I will set $b=1$ in the later calculations.)<br /><br />$$\phi_i(\mathbf{q})=\exp \left(-\frac{\left(6 i^2-6 i (N+1)+2 N^2+3 N+1\right) \left(q_x^2+q_y^2+q_z^2\right)}{36 N}\right)$$<br /><br />The corresponding distribution of this characteristic function is still a Gaussian distribution with $\Sigma=\frac{b^2}{3} \mathbb{I}_3$, where the equivalent bond length $b^2=\frac{\left(6 i^2-6 i (N+1)+2 N^2+3 N+1\right)}{6 N}$. The 6th moment is $\frac{1}{N}\sum_{i=1}^N \langle(\mathbf{r}_i-\mathbf{r}_\mathrm{cm})^6\rangle=\frac{58 N^6-273 N^4+462 N^2-247}{1944 N^3}$. At large $N$, only leading term matters, which is $\frac{29}{972} N^3$. For $N=20$, the result is $235.886$, which is in accord with the simulation. Another example is for $N=5$, the $R_g^2$ is $0.8$ rather than $5/6=0.8\dot{3}$ in this case.<br /><br />Here is the simulation code:</p><pre><code class="python">ch = np.random.normal(size=(100000,20,3),scale=1/3**0.5)<br />ch[:,0,:]=0<br />ch = ch.cumsum(axis=1)<br />ch -= ch.mean(axis=1,keepdims=1)<br />m6 = np.mean(np.linalg.norm(ch,axis=-1)**6)<br /></code></pre>呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-5212322507823494562019-07-22T09:39:00.001-07:002019-08-05T09:43:13.934-07:00Simple Examples of Parallel Computing of Cython<p>It is more convenient to calculate some properties during a molecular simulation process by accessing data from API of the molecular simulation program than calculating after the whole simulation progress and dumping all the coordinates. Especially, for some more uncertain properties such as Virial, require massive frames to calculate, and it is expensive to dump densely. For some Python-friendly molecular simulation software, i.e., lammps, hoomd-blue, galamost, etc., it is easily to embed customized Python functions into the simulation control scripts, however, Python has a poor performance in massive calculation, <code>numba.cuda.jit</code> does give a dramatic boost, however, due to unknown reasons, GPU-accelerated molecular simulation software like hoomd-blue or galamost produce an error during simulation if one uses <code>numba.cuda.jit</code> compiled functions. Therefore, I try to use <a href="https://en.wikipedia.org/wiki/Cython">Cython</a> to generate C-functions to accelerate the calculations. Here I put a simple example of a pairwise property calculation function (RDF) using Cython-parallel method, it's also a learning note of mine:</p><br /><pre><code class="python"># cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True<br />import numpy as np<br />cimport numpy as np<br />import cython<br />from cython.parallel import prange, parallel<br />cimport openmp<br />from libc.math cimport floor,sqrt,pow<br />from libc.stdlib cimport malloc, free<br />import multiprocessing<br /><br /><br />cdef long * unravel_index_f(long i, long[:] dim) nogil:<br /> cdef long k, d<br /> d = dim.shape<br /> cdef long * ret = &lt;long *&gt; malloc(d * sizeof(long))<br /> for k in range(d):<br /> ret[k] = i % dim[k]<br /> i = (i - ret[k]) / dim[k]<br /> return ret<br /><br /><br />cdef long ravel_index_f(long * vec, long[:] dim) nogil:<br /> cdef long ret, d, tmp, k<br /> d = dim.shape<br /> ret = (vec + dim) % dim<br /> tmp = dim<br /> for k in range(1,d):<br /> ret += ((vec[k] + dim[k]) % dim[k]) * tmp<br /> tmp *= dim[k]<br /> return ret<br /><br /><br />cdef long jth_neighbour(long * veci, long * vecj, long[:] dim) nogil:<br /> cdef long ret, d, tmp, k<br /> cdef long * tmpi<br /> d = dim.shape<br /> ret = (veci + vecj - 1 + dim) % dim<br /> # re-ravel tmpi + tmpj - 1 to cell_j<br /> # -1 for indices from -1, -1, -1 to 1, 1, 1 rather than 0,0,0 to 2,2,2<br /> tmp = dim<br /> for k in range(1, d):<br /> ret += ((veci[k] + vecj[k] - 1 + dim[k]) % dim[k]) * tmp<br /> tmp *= dim[k]<br /> return ret<br /><br /><br />cdef double pbc_dist(double[:] x, double[:] y, double[:] b) nogil:<br /> cdef long i, d<br /> cdef double tmp=0, r=0<br /> d = b.shape<br /> for i in range(d):<br /> tmp = x[i]-y[i]<br /> tmp = tmp - b[i] * floor(tmp/b[i]+0.5)<br /> r = r + pow(tmp, 2)<br /> return sqrt(r)<br /><br /><br />cdef long cell_id(double[:] p, double[:] box, long[:] ibox) nogil:<br /> # In the Fortran way<br /> cdef long ret, tmp, i, n<br /> n = p.shape<br /> ret = &lt;long&gt; floor((p / box + 0.5) * ibox)<br /> tmp = ibox<br /> for i in range(1, n):<br /> ret = ret + tmp * &lt;long&gt; floor((p[i] / box[i] + 0.5) * ibox[i])<br /> tmp = tmp * ibox[i]<br /> return ret<br /><br /><br />cdef void linked_cl(double[:, :] pos, double[:] box, long[:] ibox, long[:] head, long[:] body) nogil:<br /> cdef long i, n, ic<br /> n = pos.shape<br /> for i in range(n):<br /> ic = cell_id(pos[i], box, ibox)<br /> body[i] = head[ic]<br /> head[ic] = i<br /><br /><br />def rdf(double[:,:] x, double[:,:] y, double[:] box, double bs, long nbins):<br /> cdef long i, j, k, l, n, m, d3, d, ic, jc<br /> cdef np.ndarray[np.double_t, ndim=2] ret<br /> cdef long[:] head, body, ibox, dim<br /> cdef double r, r_cut<br /> cdef long ** j_vecs<br /> cdef long * veci<br /> cdef int num_threads, thread_num<br /> num_threads = multiprocessing.cpu_count()<br /> r_cut = nbins * bs<br /> n = x.shape<br /> d = x.shape<br /> m = y.shape<br /> d3 = 3 ** d<br /> ibox = np.zeros((d,), dtype=np.int64)<br /> for i in range(d):<br /> ibox[i] = &lt;long&gt; floor(box[i] / r_cut + 0.5)<br /> head = np.zeros(np.multiply.reduce(ibox), dtype=np.int64) - 1<br /> body = np.zeros((m,), dtype=np.int64) - 1<br /> linked_cl(y, box, ibox, head, body)<br /> ret = np.zeros((num_threads, nbins), dtype=np.float)<br /> dim = np.zeros((d,), dtype=np.int64) + 3<br /> j_vecs = &lt;long **&gt; malloc(sizeof(long *) * d3)<br /> for i in range(d3):<br /> j_vecs[i] = unravel_index_f(i, dim) <br /> with nogil, parallel(num_threads=num_threads):<br /> for i in prange(n, schedule='dynamic'):<br /> ic = cell_id(x[i], box, ibox)<br /> thread_num = openmp.omp_get_thread_num()<br /> veci = unravel_index_f(ic, ibox)<br /> for j in range(d3):<br /> jc = jth_neighbour(veci, j_vecs[j], ibox)<br /> k = head[jc]<br /> while k != -1:<br /> r = pbc_dist(x[i], y[k], box)<br /> if r &lt; r_cut:<br /> l = &lt;long&gt; (r/bs)<br /> ret[thread_num, l]+=1<br /> k = body[k]<br /> return np.sum(ret, axis=0)<br /></code></pre><br /><p>Notes:</p><br /><ol><li><code>def</code> means Python function and <code>cdef</code> means C functions;</li><li>Arrays declared by <code>double[:]</code> etc. are <code>memoryslice</code> and can be conveniently initialized by <code>np.zeros</code> or reading an <code>np.ndarray</code> as function parameter;</li><li>Without GIL, any calling of Python function is forbidden, the array must be initialized and declared in the C method;</li><li>In <code>prange</code> loop, variables are thread-local (see the generated <code>.c</code> file, in section <code>#pragma omp parallel</code>), there is no explicit way to call an atomic operation in Cython (using <code>with gil</code> results in very low efficiency), hence the result is generated as <code>ret = np.zeros((n, nbins), ...</code> so that in each thread <code>i</code> that <code>ret[i]</code> are independent, or generate <code>ret</code> as (num_threads, data structure...), just keep independent amongst threads and in <code>i</code>th loop, call <code>openmp.omp_get_thread_num()</code> to get the current thread's id;</li><li><code>&lt;long&gt;</code> is a type casting.</li></ol><br /><p>This RDF function uses a <a href="https://books.google.com/books/about/Computer_Simulation_of_Liquids.html?id=ibURAQAAIAAJ">linked cell list</a> algorithm to reduce the calculation from $O(n^2)$ to $O(n)$, a small ranged RDF ($r&lt;r_\mathrm{cut}$) is calculated, the RDF on $r\ge r_\mathrm{cut}$ can be calculated using an FFT algorithm by setting $r_\mathrm{bin}&lt;\frac{r_\mathrm{cut}}{2}$</p><br /><p>The second example is calculation of histogram N-d array by modulus of indices: $\int f(\mathbf{r})\delta(|\mathbf{r}|-r)\mathrm{d}\mathbf{r}$:<br /></p><pre><code class="python"># cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True<br />import numpy as np<br />cimport numpy as np<br />import cython<br />from cython.parallel import prange, parallel<br />cimport openmp<br />from libc.math cimport floor,sqrt,pow<br />from libc.stdlib cimport malloc, free<br />import multiprocessing<br /><br /><br />cdef double unravel_index_f_r(long i, long[:] dim) nogil:<br /> # unravel in Fortran way<br /> cdef long k, d, tmp<br /> cdef double r<br /> d = dim.shape<br /> for k in range(d):<br /> tmp = i % dim[k]<br /> r += &lt;double&gt; (tmp)**2<br /> i = (i - tmp) / dim[k]<br /> return sqrt(r)<br /><br /><br /><br />def hist_to_r(double[:] x, long[:] shape, double dr, double bs, double rc):<br /> cdef long i, n, j, n_bins<br /> cdef np.ndarray[np.double_t, ndim=2] ret, count<br /> cdef int num_threads, thread_num<br /> n_bins = &lt;long&gt; (rc / bs)<br /> num_threads = multiprocessing.cpu_count()<br /> ret = np.zeros((num_threads, n_bins), dtype=np.float64)<br /> count = np.zeros((num_threads, n_bins), dtype=np.float64)<br /> n = x.shape<br /> with nogil, parallel(num_threads=num_threads):<br /> for i in prange(n, schedule='dynamic'):<br /> j = &lt;long&gt; (unravel_index_f_r(i, shape)*dr/bs)<br /> thread_num = openmp.omp_get_thread_num()<br /> if j &lt; n_bins:<br /> ret[thread_num, j] += x[i]<br /> count[thread_num, j] += 1<br /> return np.sum(ret,axis=0), np.sum(count,axis=0)<br /></code></pre><br /><p>In function <code>unravel_index_f_r</code>, the index is unraveled in the <code>Fortran</code> way, therefore, calling <code>hist_to_r</code> requires <code>x.ravel(order='F')</code>.<br /></p>呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-64493045956060412212019-07-13T17:47:00.001-07:002019-08-05T10:10:49.506-07:00Anisotropy of ideal chain<p>The Gaussian chain is isotropic when averaged over conformation space and all orientations. Therefore, a Gaussian chain is dealt as sphere with radius of $R_g$, it’s radius of gyration. In the 2nd chapter of Rubinstein’s <em>Polymer Physics</em>, an exercise shows that the $R_g^2$ is asymmetric if one set the coordinate frame on its end-to-end vector, $\mathbf{R}_{ee}$. i.e., the $\mathbf{R}_{ee}$ vector is set as the $x$-axis therefore $\mathbf{R}_{ee}=(R,0,0)^T$. Then the 3 components of $\mathbf{R}_{ee}$ are $\frac{Nb^2}{36}$, $\frac{Nb^2}{36}$ on $y$, $z$ direction and $\frac{Nb^2}{36}+\frac{R^2}{12}$ on $x$ direction. Here I make a very simple proof.</p><p>Consider a Gaussian chain is fixed between $(0,0,0)^T$ and $\mathbf{R}_{ee}$. It’s actually a Brownian bridge, and the distribution is a multivariate Gaussian with mean at $\frac{i}{N}\mathbf{R}$ with variance $\frac{i(N-i)}{N}b^2$, the proof is simple:<br /><br />$$P_{0\mathbf{R}}(\mathbf{r},n)=\frac{G(\mathbf{r},0,n)G(\mathbf{R},\mathbf{r},N-n)}{G(0,\mathbf{R},N)}$$<br /><br />$G(a,b,n)$ represents distribution of a Gaussian chain ends at $a,b$ with segment length $n$. The meaning is straightforward: it’s the probability of a length $n$ Gaussian chain start from $0$ and end at $\mathbf{r}$ connected with another $N-n$ Gaussian chain which started at $\mathbf{R}$ and stopped at $\mathbf{r}$, and the whole chain is an Gaussian chain with length $N$ and $\mathbf{R}_{ee}=\mathbf{R}$. It is easily to show the distribution of such chain<br /><br />$$P_{0\mathbf{R}}(\mathbf{r},n)=G\left(\mathbf{r}-\frac{n}{N}\mathbf{R}, 0,\frac{n(N-n)}{N}\right)$$<br /><br />is equivalent to a Gaussian chain segment ends with $\mathbf{r}$ and $\frac{n}{N}\mathbf{R}$ with equivalent length $\frac{n(N-n)}{N}$. The $R_g^2$ is then<br /><br />\begin{align}R_g^2=&amp;\frac{1}{2N^2}\int_0^N\langle(\mathbf{r}_i-\mathbf{r_j})^2\rangle\mathrm{d}i\mathrm{d}j\\<br />=&amp;\frac{1}{N^2}\int_0^N\int_j^N \frac{(i-j)^2 R^2}{N^2}+\frac{(i-j)(N-(i-j))}{N}b^2\mathrm{d}i\mathrm{d}j\\ =&amp;\frac{R^2+nb^2}{12}\end{align}<br /><br />In this equivalent method, $\langle (\mathbf{r}_i-\mathbf{r}_j)^2\rangle$ is considered as $(\frac{i}{N}-\frac{j}{N})^2R^2+\frac{|i-j|(N-|i-j|)}{N}$ from the equivalent Gaussian chain. This is because despite the chain is ‘fixed’, it is still a Gaussian chain, which means translation invariance, $\langle (\mathbf{r}_i-\mathbf{r}_j)^2\rangle$ depends only on $|i-j|$, therefore, $P_{0\mathbf{R}}(\mathbf{r},n)$ gives the probability of segment $\mathbf{r}_n-\mathbf{r}_0$, which is any $n$-segment on the Gaussian chain. I tried calculating $P(\mathbf{r}_i-\mathbf{r}_j)$ from the convolution of $P_{0\mathbf{R}}$. This is incorrect because $\mathbf{r}_i$, $\mathbf{r}_j$ are correlated, convolution of $P_{0\mathbf{R}}$ results in dependence of $i$ and $j$ in $\langle (\mathbf{r}_i-\mathbf{r}_j)^2\rangle$, violates the translation invariance of the chain.</p><p>Now if $R^2=Nb^2$, we see that $R_g^2=\frac{1}{6}Nb^2$; and we have $\frac{Nb^2}{36}+\frac{R^2_{x,y,z}}{12}=\frac{Nb^2+R^2}{36}$ for each dimension, especially, if $\mathbf{R}_{ee}=(R,0,0)^T$, we have $\frac{Nb^2}{36}$ in $y$ and $z$ direction and $\frac{Nb^2}{36}+\frac{R^2}{12}$ in $x$-direction.</p><p>Simple simulation code:</p><pre><code class="python">rg2_ree = rg2 = 0<br />for _ in range(5000): <br /> ch = np.random.normal(size=(1000,3)) <br /> ch = np.append(np.zeros((1,3)),np.cumsum(ch, axis=0),axis=0) <br /> ch = ch - ch.mean(axis=0) <br /> ree = ch[-1]-ch <br /> ree = ree/np.linalg.norm(ree) <br /> rg2_ree += np.sum(ch.dot(ree)**2) <br /> rg2 += np.sum(ch**2)<br />rg2_ree/rg2<br /># Result is 0.666...<br /></code></pre>呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-82186876887772075952019-07-12T11:13:00.000-07:002019-07-12T12:19:10.324-07:00Flory characteristic ratio of hindered rotation chain<ol><p>This is an exercise on Rubinstein's textbook of <i>Polymer Physics</i>.</p><li>Definition of Flory characteristic ratio:<br />$$C_\infty:=\lim_{n\to\infty}\frac{\langle \mathbf{R}^2 \rangle}{nb^2}$$<br />where $\langle \mathbf{R}^2 \rangle$ is the mean square end-to-end vector, $b$ is Kuhn length of the polymer and $n$ is corresponding chain length.</li><li>Calculation of $\langle \mathbf{R}^2\rangle$:<br />Let $\mathbf{r}_i$ be the bond vector between $i$ and $(i-1)$th particle, and $\mathbf{r}_1=\mathbf{R}_1-\mathbf{R}_0\equiv0$; for an $n$-bead chain,:<br />\begin{align}\langle \mathbf{R}^2 \rangle&amp;=\left\langle\left(\sum_{i=1}^n \mathbf{r}_i^2\right)\cdot\left(\sum_{j=1}^n \mathbf{r}_j^2\right)\right\rangle\\<br />&amp;=\sum_i\sum_j\langle \mathbf{r}_i\cdot\mathbf{r}_j\rangle\end{align}</li><li>Calculation of $\langle\mathbf{r}_i\cdot\mathbf{r}_j\rangle$:<br />Now consider a local coordinate frame that $\mathbf{r}_i=(b,0,0)^T$, then $\mathbf{r}_{i+1}$ could be considered as rotating $\mathbf{r}_i$ $\theta$ by $z$-axis for bond angle and $\phi_{i}$ by $x$-axis for torsion. The rotation matrix is thus<br />$$\mathbf{T}_i:=\left(<br />\begin{array}{ccc}<br />\cos (\theta ) &amp; -\sin (\theta ) &amp; 0 \\<br />\sin (\theta ) \cos (\phi_i) &amp; \cos (\theta ) \cos (\phi_i) &amp; -\sin (\phi_i) \\<br />\sin (\theta ) \sin (\phi_i ) &amp; \cos (\theta ) \sin (\phi_i ) &amp; \cos (\phi_i ) \\<br />\end{array}\right)$$<br />or $\pi-\theta$, $\pi - \phi$ according to the definitions of bond angle $\theta$ and torsion angle $\phi$. In every reference coordinate frame $R_i$, the bond vector is $(b,0,0)^T$, and in $R_i$, $\mathbf{r}_{i+1}=\mathbf{T}_i\cdot\mathbf{r}_i=(b \cos (\theta ),b \sin (\theta ) \cos (\phi_i ),b \sin (\theta ) \sin (\phi_i ))^T$. Now consider a simple case of $\mathbf{r}_i\cdot\mathbf{r}_{i+2}$, the $\mathbf{r}_{i+2}$ is calculated in the $(i+1)$th reference frame $R_{i+1}$ where $\mathbf{r}_{i+1}$ is $(b,0,0)^T$ and $\mathbf{r}_{i+2}=\mathbf{T}_{i+1}\cdot\mathbf{r}_{i+1}$, here we must 'rotate' one of the vector into the other frame to do the inner product, i.e. rotate $\mathbf{r}_i=(b,0,0)^T$ from $R_i$ to $R_{i+1}$ or vice versa. Now note that $\mathbf{r}_{i+1}$ in the $R_i$ frame is $(b \cos (\theta ),b \sin (\theta ) \cos (\phi_i ),b \sin (\theta ) \sin (\phi_i ))^T$ and $(b,0,0)^T$ in the $R_{i+1}$ frame, therefore if we want to transform some vector in $R_i$ into $R_{i+1}$, we need a transform matrix to transform the $(b \cos (\theta ),b \sin (\theta ) \cos (\phi_i ),b \sin (\theta ) \sin (\phi_i ))^T$ into $(b,0,0)^T$ which is $\mathbf{T}_i^{-1}$, or $\mathbf{T}_i^T$, because in frame $R_i$, we obtain $\mathbf{r}_{i+1}$ by $\mathbf{T}_i\cdot(b,0,0)^T$ and $\mathbf{T}_i$ is a rotation matrix, which is orthonormal. By transform $\mathbf{r}_i$ into $R_{i+1}$, the inner product $\mathbf{r}_i\cdot\mathbf{r}_{i+2}$ is<br />$$\langle\mathbf{T}_i^T\mathbf{r}_i,\mathbf{T}_{i+1}\mathbf{r}_{i+1}\rangle=\langle\mathbf{r}_i,\mathbf{T}_i\mathbf{T}_{i+1}\mathbf{r}_{i+1}\rangle=(b,0,0)\mathbf{T}_i\mathbf{T}_{i+1}(b,0,0)^T$$<br />By induction, $\mathbf{r}_i\cdot\mathbf{r}_j=(b,0,0)\mathbf{T}_i\mathbf{T}_{i+1}\mathbf{T}_{i+2}\cdots\mathbf{T}_{j-1}(b,0,0)^T$, since $\theta$ for every bonds are same and $\phi_{1,2,\dots,n}$ are independently distributed, let $\mathbf{T}$ be the average transform matrix of ${\mathbf{T}_i}$:<br />\begin{align}\mathbf{T}&amp;:=\frac{\int_{-\pi}^{\pi}\mathbf{T}_i(\phi)\exp{(-U(\phi)/k_BT)}\mathrm{d}\phi}{\int_{-\pi}^{\pi}\exp{(-U(\phi)/k_BT)}\mathrm{d}\phi}\\<br />&amp;=\left(<br />\begin{array}{ccc}<br />\cos (\theta ) &amp; -\sin (\theta ) &amp; 0 \\<br />\sin (\theta ) \langle\cos (\phi) \rangle &amp; \cos (\theta )\langle \cos (\phi)\rangle &amp;0 \\<br />0&amp; 0&amp; \langle\cos (\phi)\rangle \\<br />\end{array}\right)\end{align}<br />We therefore have $\langle\mathbf{r}_i\cdot\mathbf{r}_j\rangle=(b,0,0)\mathbf{T}^{|j-i|}(b,0,0^T)=b^2(\mathbf{T}^{|j-i|})_{11}$. Here every $\sin(\phi)$ term vanishes in the integral because $U$ is even.</li><li>Now the Flory characteristic ratio<br />\begin{align}C_\infty&amp;=\lim_{n\to\infty}\frac{1}{nb^2}\sum_i\sum_j \mathbf{r}_i\cdot\mathbf{r}_j\\<br />&amp;=\lim_{n\to\infty}\frac{1}{n}(\sum_i\sum_j T^{|j-i|})_{11}\\<br />&amp;=\lim_{n\to\infty}\left(-\frac{1}{n}\frac{-2 \mathbf{T}^{n+1}+\mathbf{T}^2 n+2 \mathbf{T}-n\mathbf{I}}{(\mathbf{I}-\mathbf{T})^2}\right)_{11}\\<br />&amp;=\left(\frac{\mathbf{I}+\mathbf{T}}{\mathbf{I}-\mathbf{T}}\right)_{11}\\<br />&amp;=\frac{1+\cos(\theta)}{1-\cos(\theta)}\frac{1-\langle\cos(\phi)\rangle}{1+\langle\cos(\phi)\rangle}\end{align}<br />Here we have $\frac{\bullet}{n}=0$ and $\mathbf{T}^n=0$ at $n\to\infty$, because $\mathbf{T}$ is constant and correlation between 2 beads goes to $0$ as distance goes to infinity.</li></ol>呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-11571204557423691202019-07-01T22:19:00.002-07:002019-07-24T08:02:35.571-07:00RTFM, pls RTFM!!!I was trying to write a parallel version C-extension with <code>Cython</code> several days ago, to calculate Coulomb energy of $n$ points. I wrote the code as follows:<br /><pre><code class="python">@cython.cdivision(True)<br />@cython.boundscheck(False)<br />@cython.wraparound(False)<br />def u(double[:,:] x):<br /> cdef long i<br /> cdef long j,k<br /> cdef double ret=0,tmp<br /> with nogil, parallel():<br /> for i in prange(x.shape-1, schedule='static'):<br /> for j in range(i + 1, x.shape):<br /> tmp = 0<br /> for k in range(x.shape):<br /> tmp = tmp + pow(x[i,k]-x[j,k],2)<br /> ret = ret + 1 / sqrt(tmp)<br /> return ret<br /></code></pre><a name='more'></a><br />It passed the compilation but produced an NaN result. I Googled about half an hour with "cython parallel yield nan" but no answers were found, I also tried to add variables tracing the <code>tmp</code> variable... After about 1 desperate hour of aimlessly Googling with every possible combinations of meaningless keywords, reading the sample code in <a href="https://cython.readthedocs.io/en/latest/src/userguide/parallelism.html">Cython doc</a> over and over or seperating the modulus part as an independent function... suddenly I found on the top of the doc, under "Thread-locality and reductions.." line it said clearly about how the variables work in/out the <code>prange</code> loop. Therefore I tried to modify the code:<br /><pre><code class="python">@cython.cdivision(True)<br />@cython.boundscheck(False)<br />@cython.wraparound(False)<br />def u(double[:,:] x):<br /> cdef long i<br /> cdef long j,k<br /> cdef double ret=0,tmp<br /> with nogil, parallel():<br /> for i in prange(x.shape-1, schedule='static'):<br /> for j in range(i + 1, x.shape):<br /> tmp = 0<br /> for k in range(x.shape):<br /> tmp = tmp + pow(x[i,k]-x[j,k],2)<br /> ret += 1 / sqrt(tmp)<br /> return ret<br /></code></pre>Just by changing <code>ret = ret + ...</code> to <code>ret += ...</code>, then the problem was solved. What was the meaning of wasting all this time of aimless trials? Why not just READ THE F**KING MANNUL?呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-7640248193839159772019-06-16T23:51:00.000-07:002019-06-17T00:30:38.886-07:00Find intersections numerically -- Using NumPy<h3 id="intersects-of-2-functions">Intersects of 2 functions</h3><p>Assuming function $f$ and $g$, <code>scipy.optimize.fsolve</code> would give an elegant solution:</p><pre><code data-language="python">from scipy.optimize import fsolve<br />def f(xy):<br /> x, y = xy<br /> return (y - x ** 2, y - np.sin(x))<br />fsolve(f, [1.0, 1.0])<br /></code></pre><p>gives <code>array([0.87672622, 0.76864886])</code> is the intersect of $y=x^2$ and $y=\sin(x)$.</p><h3 id="intersects-of-2-arrays">Intersects of 2 arrays</h3><p>There is a function called <code>numpy.intersect1d</code> that returns the sorted, uniq values in both arrays, and <code>reduce(np.intersect1d, list_of_arrays)</code> gives intersect of all arrays in the list. Index can also be returned by <code>return_indices=True</code> option.</p><p>If the 2 arrays are data values, using <code data-language="python">np.flatnonzero(np.abs(arr1-arr2))&lt;tol)</code> seems to be a good solution; this method returns the indices of values in <code>arr1</code> and <code>arr2</code> which are closed by <code>tol</code>.</p><p>Another method is based on idea that there is a change in sign of $\lim_{x\to x_0^+}f(x_0)-g(x_0)$ and $\lim_{x\to x_0^-}f(x_0)-g(x_0)$, therefore, if $\mathrm{d}x$ is small enough, this method would give a very good estimation of the intersects.</p><pre><code data-language="python">def intersects(x, arr1, arr2):<br /> return x[np.flatnonzero(np.diff(np.sign(arr1 - arr2))]<br /></code></pre>呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-71508677482179469042019-04-22T10:31:00.001-07:002019-04-22T12:08:39.756-07:00CAPVT II -- notes on Wheelock's Latin<h2 id="first-declension-nouns-and-adjectives">First declension nouns and adjectives</h2><h3 id="endings">Endings</h3><table><thead><tr> <th></th> <th>Singular</th> <th>Plural</th> </tr></thead> <tbody><tr> <td><i>Nom.</i></td> <td>-a</td> <td>-ae</td> </tr><tr> <td><i>Gen.</i></td> <td>-ae</td> <td>-ārum</td> </tr><tr> <td><i>Dat.</i></td> <td>-ae</td> <td>-īs</td> </tr><tr> <td><i>Acc.</i></td> <td>-am</td> <td>-ās</td> </tr><tr> <td><i>Abl.</i></td> <td>-ā</td> <td>-īs</td> </tr><tr> <td><i>Voc.</i></td> <td>-a</td> <td>-ae </td> </tr></tbody> </table><a name='more'></a><br />Most 1st declension nouns are feminine, a few nouns denoting individuals engaged in what were among the Romans traditionall male occupations are masculine, e.g., <b>poeta</b>, <i>poet</i>; <b>nauta</b>, <i>sailor</i>; <b>agricola</b>, <i>farmer</i>; <b>auriga</b>, <i>charioteer</i>; <b>incola</b>, <i>inhabitant</i>; <b>pirata</b>, <i>pirate</i>, etc.<br /><br /><h3 id="word-order">Word order</h3>An adjective (sg. <b>adiectivum</b>, pl. <b>adiectiva</b>, <i>set next to</i>, <i>added</i>) adds information to the noun or pronoun. An adjective often comes next to the noun (except for poetry, the grammer would be much freer). Adjective always agrees its noun in <i><b>gender</b></i>, <i><b>number</b></i> and <i><b>case</b></i>, if an adjective modifies more than one noun, then the adjective agrees in gender with the <i><b>nearest</b></i> one, though sometimes the <i><b>masculine predominates</b></i>. Adjectives denoting size, number, as well as demonstratives, like <b>magna</b>, <b>hic</b> and <b>ille</b> often precede.<br /><br /><h2 id="vocabvla">Vocabvla</h2><b>fama famae</b>, f., rumor, report<br /><b>forma formae</b>, f., form, shape; beauty<br /><b>fortuna fortunae</b>, f., fortune, luck<br /><b>ira irae</b>, f., anger<br /><b>nauta nautae</b>, m., sailor<br /><b>patria patriae</b>, f., fatherland, native land, (one’s country)<br /><b>pecunia pecuniae</b>, f., money<br /><b>philosophia philosophiae</b>, f., philosophy<br /><b>poena poenae</b>, f., penalty, punishment; poenas dare, idiom, to pay the penalty<br /><b>poeta poetae</b>, m., poet<br /><b>porta portae</b>, f., gate, entrance<br /><b>puella puellae</b>, f., girl<br /><b>rosa rosae</b>, f., rose<br /><b>sententia sententiae</b>, f., feeling, thought, opinion, vote, sentence<br /><b>vita vitae</b>, f., life; mode of life<br /><b>antiquus antiqua antiquum</b>, adj., ancient<br /><b>magnus magna magnum</b>, adj., big, large<br /><b>meus mea meum</b>, adj., my<br /><b>multus multa multum</b>, adj., much, many<br /><b>tuus tua tuum</b>, adj., your, when speaking to only one person<br /><b>et</b>, conj., and; even<br /><b>sed</b>, conj., but<br /><b>O</b>, interj., O!, Oh!, inducing voc.<br /><b>sine</b>, prep. + abl., without<br /><b>est</b>, is<br /><b>venia veniae</b>, f., favor, pardon<br /><b>sanus sanua sanum</b>, adj., sound, sane;<br /><b>immodicus immodica immodicum</b>, adj., immoderate, excessive<br /><br /><h2 id="sententiae-antiqvae">Sententiae antiqvae</h2><ol><li>Slave, O patria! (Plautus.)</li><li>Fama et sententia volant. (Vergil. – <b>volare</b>, to fly, move quckly;)</li><li>Da veniam puellae, amabo te. <i>Please give the girl a favor.</i></li><li>Clementia tua multas vitas servat. <i>Your clemency saves many lives.</i></li><li>Multam pecuniam deportat. (Cicero. – <b>deportare</b>, to carry away)</li><li>Et fortunam et vitam antiquae patriae saepe laudas sed recusas. (Horace. – <b>recusare</b>, to refuse, reject;) <i>You often praise both life style and fortune of your acient country, but you reject them.</i></li><li>Me vitare turbam iubes. (Seneca. – <b>vitare</b>, to avoid; – <b>turba</b>, -<b>ae</b>, f., crowd, multitude; – <b>iubere</b>, to order;) <i>You order me to avoid the crowd.</i></li><li>Me philosophiae do. <i>I give myself to philosophy.</i></li><li>Philosophia est ars vitae.</li><li>Sanam formam vitae conservate. <i>(You all) Conserve a sound style of life.</i></li><li>Immodica ira creat insaniam. (Seneca) <i>Excessive anger creates insanity.</i></li><li>Quid cogitas? – debemus iram vitare. <i>What are you thinking? – we ought to avoid anger.</i></li><li>Nulla avaritia sine poena est. (Seneca) <i>No greedy is without penalty.</i></li><li>Me saevis catenis onerat. (Horace. – <b>savus, -a, -um</b>, adj., cruel. – <b>catena, -ae</b>, f., chain – <b>onerare</b>, to load, oppress)</li><li>Rotam fortunae non timent. (Cicero. – <b>rota, -ae</b>, f., wheel; – <b>timere</b>, to fear) <i>They do not fear the wheel of fortune.</i></li></ol><br /><h2 id="translation">Translation</h2><ol><li>The girls save the poet’s life. <b>Puellae vitam poetae conservant.</b></li><li>Without philosophy we often go astray and pay the penalty. <b>Sine philosophia saepe erramus et poenas damus.</b></li><li>If your land is strong, nothing terrifies the sailors and you (sg.) ought to praise your great fortune. <b>Si patria tua valet, nihil nautas terret et magnam fortunam tuam laudare debes.</b></li><li>You (pl.) often see the penalty of my anger and warn me. <b>Poenam irae meae saepe videtis et me monetis.</b></li><li>The acient gate is large. <b>Porta antiquua est magna.</b></li></ol><br /><h2 id="catullus-bids-his-girlfriend-farewell">Catullus bids his girlfriend farewell</h2>Puella mea me non amat. Vale, puella! Catullus obdurat: poeta puellam non amat, puellam non vocat, formam puellae non laudat, puellae rosas non dat, et puellam non basiat! Ira mea est magna! Obduro, mea puella – sed sine te non valeo.<br /><br />↑↑ what a loser. ( ﹁ ﹁ )<br />My girl does not love me. Farewell girl! Catullus is tough: the poet does not love the girl, he does not call the girl, he does not praise the girl’s beauty, he does not give the girl roses and he does not kiss the girl! My anger is great! I am tough, my girl – but without you I am not well.<br /><br /><h2 id="la-la-la">La La La</h2><b>Quid hodie agis?</b> – How are you today?<br /><blockquote><b>Optime!</b> – <i>Great!</i><br /><b>Pessime!</b> – <i>Terrible!</i><br /><b>Bene!</b> – <i>Good!</i><br /><b>Satis bene.</b> – <i>So-so, okay.</i><br /><b>Non bene.</b> – <i>Not well.</i><br /><b>Et tu?</b> – <i>And you?</i></blockquote><br />呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-41974981821947654652018-04-25T22:50:00.001-07:002019-04-22T12:08:39.694-07:00Veritas in lucem emergit.<p>In contrast to put endings on verbs, aka conjugation, declension is to put endings to nouns and adjectives. The 3rd declension of nouns are usually learnt after the 1st and 2nd declension.</p><a name='more'></a><br /><table><thead><tr> <th></th> <th>Singular</th> <th>Plural</th> </tr></thead> <tbody><tr> <td>Nominative</td> <td>/</td> <td>-es</td> </tr><tr> <td>Genitive</td> <td>-is</td> <td>-um</td> </tr><tr> <td>Dative</td> <td>-i</td> <td>-ibus</td> </tr><tr> <td>Accusative</td> <td>-em</td> <td>-es</td> </tr><tr> <td>Ablative</td> <td>-e</td> <td>-ibus</td> </tr></tbody> </table><p>Nominative is derived from Latin word <em>nomen</em>, which means <em>name</em>, this is the form we name things, or, subject of a verb.</p><p>Genitive means <em>of the noun</em>, or <em>belongs to the noun</em>, a word often given by its nominative and genitive form, for the genitive form minus <em>-is</em> is the <strong>stem</strong> of the word, all other form of the word is adding corresponding ends to the stem.</p><p>Dative means the noun is a ‘indirect’ object of a verb, like ‘give sth to sb’, the ‘sth’ is the direct objective to the verb ‘give’, the ‘who’ to give is the indirect object to ‘give’.</p><p>Accusative is the direct object to the verb, the verb does on the accusative form of the noun.</p><p>Ablative means ‘by the noun’, ‘with the noun’ or ‘from the noun’, the noun is an adjective.</p><ul><li>Parsing sentence:<br /><ul><li><em>Luces mensem faciunt.</em></li></ul><blockquote><p><em>luces</em>, days, lights, plural, nominative or accusative of <em>lux</em><br /><br /><em>mensem</em>, month, singular, accusative of <em>mensis</em><br /><br /><em>faciunt</em>, make, 3rd person plural present tense active indicative mood of verb <em>facio</em><br /><br />The subject of <em>faciunt</em> must be 3rd plural, so the lights must be the subject, moreover, <em>mensem</em> is the accusative of <em>mensis</em>, it must be the object to the verb. Therefore, the translation is <em>Days make month.</em></p></blockquote><ul><li><em>Veritas in lucem emergit.</em></li><li><em>Quit est veritas?</em></li><li><em>Veritas lucem non refugit.</em></li></ul></li><li>Verba<br /><p><br />an (conjunction): or<br /><br />lux, lucis, f.: light<br /><br />magis (adverb): more<br /><br />mens, mentis, f.: mind<br /><br />mensis, mensis, m.: month<br /><br />miles, militis, m.: soldier<br /><br />procedo, procedere, processi, processum: go forward, advance<br /><br />quid: what<br /><br />reddo, reddere, reddidi, redditum: give back, render<br /><br />veritas, veritatis, f.: truth<br /><br />virtus, virtutis, f: strength, courage</p></li><li>Translate<br /><ul><li>Caesar’s soldiers are conquering.<br /><blockquote><p><em>Milites Caesaris vincunt.</em></p></blockquote></li><li>Caesar speaks truth to the soldier.<br /><blockquote><p><em>Caesar militi veritatem dicit.</em></p></blockquote></li><li>Let us advance!<br /><blockquote><p><em>Procedamus!</em></p></blockquote></li><li>Let truth be the light of the mind.<br /><blockquote><p><em>Sit veritas lux mentis.</em></p></blockquote></li><li>The soldier’s strength is great.<br /><blockquote><p><em>Virtus militis magna est.</em></p></blockquote></li><li>The woman is learning by the strength of her mind.<br /><blockquote><p><em>Virtute mentis mulier discit.</em></p></blockquote></li><li>Render praise to Caesar!<br /><blockquote><p><em>Reddite Caesari laudem.</em></p></blockquote></li><li>Let us render praise to the truth!<br /><blockquote><p><em>Veritati laudem reddamus.</em></p></blockquote></li><li>The soldiers cannot deceive Caesar!<br /><blockquote><p><em>Milites Caesarem decipere non possunt.</em></p></blockquote></li><li>We are not able to learn the truth.<br /><blockquote><p><em>Veritatem discere non possumus.</em></p></blockquote></li></ul></li></ul><br />呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-61025234093868925472018-04-02T09:06:00.000-07:002019-04-22T12:08:39.730-07:00Esse an non esse?In this lesson, irregular verb sum and possum are learnt.<br />sum, esse,&nbsp;&nbsp; fui,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; futurum: be<br />I am, to be, have been, going to be<br /><br />And pot- (can, be able).<br />possum, posse, potui: be able, can<br />pot- add some be yield can/be able to, the rules are simple: pot- or pos- if the be verb stats with "s".<br /><br /><br /><a name='more'></a><br /><br />Present tense active indicative mood: sum, es, est, sumus, estis, sunt<br />Present subjunctive of sum: sim, sis, sit, simus, sitis, sint<br />Imperatives: Es!/Potes! be/be able singular; Este!/Poteste! plural<br /><br />Add pot-/pos- to be verb:<br />possum potes potest possums potestis possunt: can, be able to<br />possim possis possis possimus possistis possint: can, be able to (subjunctive mood)<br /><br />Infinitives of possum/sum:<br />posse: to be able to<br />esse: to be<br /><br />possum is a verb that means "I can" or "I am able", however, simply say "I am able" is not enough, an object is needed for complementary, this object is an infinitive of a verb.<br /><br />e.g. I am able to read. to read is the object of verb I am able, in Latin:<br /><br />Possum legere.<br /><br /><ul><li>Sentence parsing</li></ul>Possumus legere. We can read.<br />Possumus bibere. We are able to drink.<br />Possunt ineptire. They are able to be foolish.<br />Potest linguam Latinam legere. He/She can read Latin language.<br />Bibimus, ut possimus bene vivere. We drink so that we may be able to (can, would) live well.<br />Vita brevis. Life is short. (omit be here)<br />Ars longa. Art is long.<br />Vita est brevis, sed ars est longa. Life is short, but art is long. Or, simply, Vita brevis; ars longa. Omit the conjunctions (be and the but for contrast) is called asyndeton in rhetoric.<br />Sit vita longa! May life be long.<br />Ars brevis esse potest. Art can be long. (Art is able to be long) Predicate after the object. In better Latin, Vita est brevis -&gt; Vita brevis est. So here is no Ars potest esse brevis.<br />Linguam Latinam legere possumus. We can read Latin language.<br />Potestis ineptire. Y'all cam be foolish.<br />Sumus. We are.<br />Simus. Let us be.<br />Est. It is.<br />Sit. Let it be.<br />Esse an non esse? To be or not to be?<br />Esse est posse. To be is to be able.<br />Pone metum; Valeo. Put away your fear, for I am well. (asyndeton of 'for, because')<br />Ponamus metum! Let us not fear!<br />Ponamus nimios gemitus! Let us put away our excessive sorrow!<br />Caesar populum Romanum decipit. Caesar deceives Roman people.<br />Caesar populum Romanum decipere potest. Caesar is able to deceive Roman people.<br />Fiat lux. Let light be made.<br />Si lux est, possumus bibere. If there is light, we can drink.<br />Si lux fiat, possimus bibere. If there should be light, we would be able to drink. (If you do sth, I'll do sth)<br />Si lux fiat, possimus bibere? If you do sth, would we ...?<br /><ul><li>Verba</li></ul>bene (adverb): well<br />decipio, decipere, decepi, deceptum: deceive<br />lego, legere, legi, lectum: read<br />non: not<br />possum, posse, potui: be able<br />sed (conjunction): but<br />sum, esse, fui, futurum: be<br />nimios: excessive<br />gemitus: sorrow<br />metum: fear<br />Si: if<br /><ul><li>Translate</li></ul>She is able: Potest.<br />She may be able: Possit.<br />They are: Sunt.<br />Let them be: Possint<br />We are able to read: Possumus legere.<br />We may able to read: Possimus legere.<br />The women can learn: Mulieres discere possunt.<br />Can the soldiers conquer? Milites vincere possunt?<br />Are the male and female students able to learn Latin language: Discipuli discipulaeque linguae Latinae discere possunt? <br /><br />You are soldiers, but we are not soldiers: Milites estis, sed non milites sumus.<br /><br /><br />Are you a soldier? Miles es?<br />Let it be: Sit.<br />Caesar potest populum Romanum decipere. Caesar can deceive Roman people.<br />Curate, ut valeatis! Take care, so that you may be well.<br />Bibimus et edimus, ut possimus bene vivere. Eat and drink, so that we may live well.<br />Si lux est, possumus bibere. If there is light, we can drink.<br />Milites possunt vincere sed non vincunt. The soldiers are able to win but not decisive.<br />Vita brevis est. Life is short.<br />Ars longa esse potest. Art can be long.<br />Esse est posse. To be is to be able.<br />Bene legere potestis, discipulae. Y'all can read well, students.<br />Milites non sunt. They are not soldiers. 呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-87804018995171200882018-04-02T07:54:00.000-07:002019-04-22T12:08:39.780-07:00Miser Catulle, desinas ineptire!In this lesson, subjunctive mood was induced. Changing a verb into subjunctive mood from indicative mood is to add vowel "a" and personal endings.<br /><br />Indicative is to tell the truth, to point out something. Subjunctive mood is to exhort or tendence. Imperative mood is to command someone to do something (always command the 2nd person).<br /><br /><a name='more'></a><br />Using subjunctive mood for exhorting: ut/ne, so that/so that may not, induce a result that caused or with the result may not happen.<br /><br />In English, purposes are expressed by infinitive, such as "Casca attends the Senate to put a dagger in Caesar", "to put a dagger in Caesar" is the purpose, in Latin, the expression is "Casca attends Senate so that he may put a dagger in Caesar.".<br /><br />Other uses of the subjunctive include expressing doubt about something someone else has said, when reporting an opinion, when reporting an indirect question, when expressing a general characteristic, and more.<br /><br />"You should/may drink", "So that you may drink" and "you drink" can all be expressed by subjunctive mood in Latin, in Latin, the subjunctive represents the attitude of the speaker to the action. We represent attitude in English differently, hence, the lack of one-to-one correspondence.<br /><br /><ul><li>Parsing</li><ul><li>Miser Catulle, desinas ineptire!</li><ul><li>Unhappy Catullus, you should stop to be a fool. ineptire is the infinitive form of verb ineptio, which means "to be foolish, play fool", the infinite verb here is to complement the verb desinas, which is the 2nd personal singular present tense subjunctive mood form of desino, which means "stop, cease", here is a pep talk that the author write to himself: "Unhappy Catullus, you should stop to be a fool"</li></ul></ul></ul><ul><ul><li>Linguam Latinam disco. -&gt; I learn the Latin language.</li><li>Linguam Latinam discimus. -&gt; We learn the Latin language. discimus is the 1st person plural present tense indicative mood of disco.</li><li>Linguam Latinam discamus. -&gt; Let us learn the Latin language. discamus is the 1st person plural present tense subjunctive mood of disco, "We should learn Latin", yet, however, this sentence is to exhort, to urge, so that "Let us learn" is more appropriate.</li><li>Bibamus, ut vivamus. -&gt; Let us drink, so that we may live. ut, with the result that, vivamus, we may live, therefore, the 1st part of the sentence, bibamus, is more appropriate for "Let us drink", it's exhorting. The result is "urging" the cause.</li><li>Vivimus, ut bibamus. -&gt; We live, so that we may drink. This is for the result, an indicative mood in the 1st part of the sentence, we live, so that, we may drink, live is the cause that we may drink.</li><li>Lesbia bibit, ne Catullus desinas ineptire. Lesbia drinks, so that Catullus will not stop to be a fool. Here the subjunctive mood is for the purpose, Lesbia drinks, so she get the purpose that Catullus will not stop to be a fool.</li><li>Desnatis ineptire, ne Lesbia bibat. Y'all should stop to be fool, lest Lesbia drink. Here the morphology is akin to the Bibamus, ut vivatis: Y'all should do...so that... the purpose is "Let Lesbia not drink", or "lest Lesbia drink", how? Y'all stop to be fool. So, y'all should stop to be fool, so that Lesbia will not drink.</li><li>Linguam Latinam discunt, ut in Roma antiqua vivant. They learn the Latin language, so that the may live in ancient Rome.</li><li>Bibite, Catulle et Lesbia, ut vivatis! ...is this a threat?</li></ul></ul><ul><li>Verba</li></ul>desino, desinere, desii: cease, stop<br />disco, discere, didici: learn<br />fio, fieri, factus sum: to be made, to happen, to become<br />linguam Latinam (direct object form; accusative), Linguae Latinae (of the Latin language; genitive)<br />lux: light<br />ne: used with subjunctive verbs to express negative purpose (so that … not)<br />vivo, vivere, vixi, victum: live<br /><br />Present tense active(without mention, default) subjunctive:<br />ponam, ponas, ponat,ponamus,ponatis, ponant<br />desinam, desinas, desinat, desinamus, densinatis, densinant<br />discam, discas, discat, discamus, discatis, discant<br />bibam, bibas, bibat, bibamus, bibatis, bibant<br /><br />Translate<br />bibimus: We drink<br />bibamus: let us drink/we should drink<br />discunt: they learn<br />discant: Let them learn/they should learn<br />desinitis: Y'all stop<br />desinatis: Y'all should stop<br />The women learn: Mulieres discunt<br />The women may learn: Mulieres discant<br />Let us learn Latin language: Linguam Latinam discamus<br />Stop! Desine! Desinite! (singular/plural)<br />The soldiers are eating so that they may live: Milites edunt, ut vivant.<br />Let us eat and drink: Edamus et bibamus<br />Caesar is conquering: Caesar vincit<br />Let there be light! (Let light come into existence!): Fiat lux!<br />Greetings, (male and female) students! : Salvete, discipuli, discipulaeque Linguae Latinae<br /><br />呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-56082429462336378812018-04-02T06:12:00.000-07:002019-04-22T12:08:39.718-07:00Veni, vidi, viciLatin verbs can exhibit their number, person, tense, voice and mood. In this lesson, only present tense indicative mood is considered.<br /><ul><li>Personal endings of words</li><ul><li>-o/-m first person singular</li><li>-mus first person plural</li><li>-s second person singular</li><li>-tis second person plural</li><li>-t third person singular</li><li>-nt third person plural</li></ul></ul>The present tense: ago<br />The infinite form: agere<br />The perfect tense: egi<br />The supine form: actum<br /><br /><br /><a name='more'></a><br /><br />Supine: A term for an infinite verb form in some languages. In Latin, a type of verbal noun, used for the ablative and accusative case of an infinitive. In Swedish, a form related to the past participle, used to form perfect tenses.<br /><br />Imperative of ago: age for singular and agite for plural.<br /><br /><ul><li>Parsing:</li><ul><li>bellum agere: agere is infinite&nbsp; of ago, means "to do", bellum is <i>war, </i>bellum agere means "war to do" or "to wage the war"</li><li>bellum agunt: agunt is third person plural present tense indicative mood of ago, means "they wage the war"</li><li>Caesar bellum agit: agit is 3rd person singular present tense indicative mood of ago, "he/she/it does", therefore, Caesar wages war.</li><li>Gaius Iulius Caesar, inperator et pontifex maximus, bellum in Gallia agit: G.I.Caesar, general and chief priest, wages war in Gaul.</li><ul><li>Unlike English, verbs always go after the subjects, in Latin, verbs can be every-where, so the ending of the verb indicates what or who is the subject.</li></ul></ul></ul><ul><ul><li>To give a command, we need to use the imperative of the verb:&nbsp;</li><ul><li>Wage war, Caesar! -&gt; Age bellum, Caesar!</li><li>Wage war, soldiers! -&gt; Agite bellum, milites!</li><ul><li>Singular imperative form of verb ends with -e and plural case is -te.</li></ul></ul></ul></ul><ul><li>Verba (Vocabulary)</li></ul>ago, agere, egi, actum: do, drive, act, lead<br />bellum: war (agere bellum -&gt; to wage war)<br />bibo, bibere, bibi, bibitum: drink<br />caedo, caedere, cecidi, caesum: cut, cut down, slay<br />Caesar: Gaius Julius Caeser, politician, author and conquerer of Gaul, famously assassinated on March 15 (the Ides), 44 B.C.E.<br />cibum: food<br />dico, dicere, dixi, dictum: say, speak, tell (Dixitque Deus: and God said, Dixit(he said-&gt;3rd person singular perfect tense indicate mood)+que(and))<br />discipuli (m.), discipulae (f.): students (discipuli, discipulaeque -&gt; male and female students)<br />edo, edere, edi, esum: eat<br />est: is<br />et: and<br />flores: flowers<br />Gallia: Gaul (France)<br />miles/milites: soldier/soldiers<br />mulier/mulieres: woman/women<br />-ne (enclitic particle): attaches to the first word in the sentence to indicate that what follows is a question<br />pono, ponere, posui, positum: put, place, put aside, put away<br />salve (singular) salvete (plural): greetings<br />vale (singular) valete (plural): be well, farewell<br />vendo, vendere, vendidi, venditum: sell<br />vinco, vincere, vici, victum: conquer<br />vinum: wine<br /><br /><ul><li>&nbsp;Practice</li><ul><li>pono: pono, ponis, ponit, ponimus, ponitis, ponunt</li><li>bibo: bibo, bibis, bibit, bibimus, bibitis, bibunt</li><li>vinco: vinco, vincis, vincit, vincimus, vincitis, vincunt</li><li>to say -&gt; dicere</li><li>Put away! -&gt; Pone! (singular) Ponite! (plural)</li><li>to drink -&gt; bibere</li><li>Eat! -&gt; ede! (singular) edite! (plural)</li><li>We sell -&gt; vendimus</li><li>to drive -&gt; agere</li><li>She is driving -&gt; agit</li><li>Drive! -&gt; Age! (singular) Agite! (plural)</li><li>to conquer -&gt; vincere</li><li>They are conquering -&gt; Vincunt</li><li>They drink -&gt; bibunt</li><li>We are cutting -&gt; Caedimus</li><li>Are you cutting -&gt; Caedisne?</li><li>You'all eat -&gt; Editis</li><li>Caesar dicit -&gt; Caesar says</li><li>Dicimus -&gt; We say</li><li>Dicite, mulieres! -&gt; Speak, women!</li><li>Caesar bellum agit -&gt; Caesar wages war</li><li>Caesar flores caedit -&gt; Caesar cuts flowers</li><li>Milites flores caedunt -&gt; Soldiers cut flowers</li><li>Ponite flores, milites, et vincite! -&gt; Put away flowers, soldiers, and conquer!</li><li>Milites cibum edunt -&gt; The soldiers eat food</li><li>Pontifices vinum bibunt -&gt; The priests drink wine.</li><li>Servum vendo -&gt; I sell slave/serf/servant. serf -&gt; work unit</li><li>Vince, Caesar! -&gt; Conquer, Caesar!</li><li>Agite bellum, milites! -&gt; Wage war, soldiers!</li><li>Cibum edimus et vinum bibimus. -&gt; We eat food and drink wine.</li><ul><li>Cibum/vinum -&gt; end of -um is accusative</li></ul></ul></ul><ul><ul><li>Edisne cibum? -&gt; Are you eating food?</li><li>Bibitisne vinum? -&gt; Are you drinking wine?</li></ul></ul><br />呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-65612154228779539562018-04-02T02:15:00.000-07:002019-04-22T12:08:39.743-07:00In principioGenesis 1:1-3<br /><br /><b>In principio creavit Deus caelum et terram.</b><br /><b>Terra autem erat inanis et vacua.</b><br /><b>Et tenebrae super faciem abyssi et spiritus Dei ferebatur super aquas.</b><br /><b>Dixitque Deus fiat lux et facta est lux.</b><br /><br /><br /><a name='more'></a><br /><br /><ul><li>Vowels:</li></ul>A: Short, "uh" in about, long; Long, "ah" in father. Latin A never pronounced as cat or kate in English.<br />E: Short, "eh" in <i>get, bed</i>; Long, "ay" in <i>cake</i><br />I: Short, "ih" in <i>kin, tin</i>; "ee" in <i>machine</i><br />O: Short, "ou" in <i>ought</i>; Long, "o" in <i>go</i><br />U: Short, "u" as in <i>book</i>; Long, "oo" as in <i>food</i><br />Y: Short, "ih" above, used only in words derived from Greek<br /><br /><ul><li>Consonants:</li></ul>C: "k" in <i>car</i><br />G: "guh" in <i>game</i><br />I: "yuh" in <i>yum</i><br />V: "wuh" in <i>what, why</i>...<br /><br /><ul><li>Diphthongs</li></ul>ae: 'i' in <i>ice</i><br />oe: 'oi' in <i>oil</i><br />au: 'ow' in <i>howl</i><br /><br /><ul><li>Syllable stress</li></ul>The stress is not away from the end of words (last syllable, <b>ultima</b>), if a word only has 2 syllables, the accent is always on the first syllable; if a world has more than 3 syllables, there are two rules:<br /><ul><ul><li>The accent is on the second-last syllable (<b>penult</b>) if the syllable is long or counts as long; a short vowel counts as long if it is followed by 2 or more consonants.</li><li>If the second-last syllable is short, the accent falls on the third-last syllable (<b>antepenult</b>)</li></ul></ul><br /><ul><li>Vocabulary</li></ul>libertas: freedom<br />Amanus: a mountain range dividing the coastal region of Cilicia from inland Syria<br />interficimus: we kill (interFIcimus, for the penult is short by nature, the accent is on the antepenult)<br />ad: near, at, toward, up to, for<br />pater: father (male parent), head of household, parent, forefather, honorific title<br />sed: but<br />separo: (se-apart+paro-prepare) divide<br />gemma: a bud or eye for a plant, a jewel, A thing made of precious stones<br />in: in<br />civilis: citizens, civil<br />iam: already, now, soon, anymore<br />bonus:&nbsp; good, honest, brave, noble, kind, pleasant Antonyms: malus, right, useful, valid<br />non: no<br />murus m. (genitive muri): wall<br />ventus m. (genitive venti): a wind<br />Vesta:&nbsp;The goddess of the hearth and the household<br />aetas:&nbsp; lifetime, generation, age<br />moenia (genitive moenium): city wall<br />aut: or (exclusive) not both or<br />spectamus: first person plural present time indicative mood of specto: look at<br />interficimus: fist person plural present time indicative mood of interficio: kill, destroy<br />inanis: void, vain, worthless<br />vacua: empty<br />video: (I) see, note<br />appello: (ad-"to, towards"+pello-"impress"+-o), (I) address, call by name<br />vespere: evening呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0tag:blogger.com,1999:blog-2889082294597625339.post-79296132321238697872015-07-12T23:42:00.002-07:002019-04-22T12:09:02.116-07:00Hello, world!<br /><div>HELLO, WORLD!</div><br />This is MathJax: $E=mc^2$ and<br /><br />$$<br />\begin{equation}<br />L = <br />\begin{cases}<br />1 &amp; \text{if i = j and deg_j \neq 0 } \\<br />stuff &amp; \text{if (i, j) \in E} \\<br />0 &amp; \text{otherwise}<br />\end{cases}<br />\end{equation}<br />$$呵呵http://www.blogger.com/profile/10034675933395730939noreply@blogger.com0