Using the array name without an index gets the first array element in Bash, ok?

Question: GNU Bash 4.4 seems forgiving when accessing the first element or only element of an array by using just the array name or accessing a variable with array syntax. Both ${var[0]} and ${var[@]} return "Value" when the variable var='Value'.
I can simplify my code by using one of the arrays as a variable when only a variable is needed. For this package I'm more concerned with it not braking with the next Bash update than with portability.
Is it safe to write code that accesses the first element of an array using variable syntax?
declare -a foo='Value'
declare -p var
declare -a var=([0]="Value")
echo ${foo}
Value

Comment: Better use standard `"${var[0]}"` to access first element.
Answer: This is a documented behavior:

Referencing an array variable without a subscript is equivalent to referencing with a subscript of 0.

However, I recommend you still use the subscript, to make your code clearer.
Answer: I confirmed that it is documented as far back as bash 2.0 (Dec 31, 1996):
curl -sL https://ftpmirror.gnu.org/bash/bash-doc-2.0.tar.gz \
| tar -xz 'bash-doc-2.0/doc/bashref.html' --to-stdout \
| grep -F --after-context=1 'without a subscript'

Result:
Referencing an array variable without a subscript is equivalent to
referencing element zero.

I couldn't find it documented in the bash 1.14 documentation (Aug 29, 1996) found at https://ftpmirror.gnu.org/bash/. The behavior might exist in v1.14 (I didn't test) but it isn't documented as far as I could tell.


Converting a graph to a biparte to find the maximal matching

Question: Im trying to get the maximal matching via trial and error (for the matching problem) derived from the following graph:

But before I do this, I know I need to convert it into a biparte graph?
Ive constructed a biparte before by using independent sets, but here if i use {3,7,8} i get a very redundant biparte. Is there an algorithm for conversion?
I know this graph has a matching of size 4 {{1,2},{5,9},{6,10},{11,12}} but it is not maximal. The only way I can figure how the maximal can be found is by converting to a bipate, or is there another way?
Thanks in advance!
Comment: I think you may be confusing the terms "maximal matching" and "maximum matching". By the Wikipedia definition, your current matching is a maximal matching. http://en.wikipedia.org/wiki/Matching_(graph_theory)
Comment: The easiest way to split the vertices in two classes to make the graph bi-partite is to $2$ color the vertices.
Answer: To partition your bipartite graph, just take any vertex, say 1, put it in A, and put all its adjacent neighbours 2 and 4 in B. You continue until all the vertices are partitioned into one of A or B, if you run into trouble it's not a bipartite graph.
Thus you will have: A = {1, 5, 3, 7, 8, 10, 11} and B = {2, 4, 6, 9, 12}. The maximum matching is size 5.
Now you find any matching, your current one is fine so let's use that. Mark the edges that are in that matching, {1,2},{5,9},{6,10},{11,12}.
Observe that there is an alternating path, 5 - 9, that starts and ends on vertices in the matching.
Furthermore we can augment this alternating path since 5 connects to free vertex 4 and 9 connects to free vertex 8.
We create the augmented path 4 - 5 - 9 - 8, and reverse the matching status of each edge each edge in the augmented path. Thus the matching in the augmented path becomes {{4,5},{8,9}}.
Our matching is now size 5, and includes {{1,2},{4,5},{6,10},{8,9},{11,12}}. This is the maximum matching.
Comment: Why is {5,9} eliminated, as this was contained in the original set, is it because of the augmented path you have demonstrated? Thanks
Comment: In order to augment an alternating path, you have to be able to add vertices that are not in the matching to both ends of the alternating path. {5,9} is not the only possible alternating path you could have augmented. In fact, you could have taken the alternating path `1 - 2 - 5 - 9` and augmented it to get `4 - 1 - 2 - 5 - 9 - 8`, and then "inverted" the matchings in the augmented path so your final matching is `{{4,1},{2,5},{9,8},{6,10},{11,12}}`, also size 5.
Comment: In a bipartite graph with bipartition $(A,B)$, the maximum size of a matching is less than or equal to $|A|$. It need not be equal.
Comment: @ChrisGodsil For a connected bipartite graph, the maximum matching is equal to the minimum of (|A|,|B|). It's an implication of Koenig's theorem as both A and B are covers.
Comment: @Reila Lee: Take two copies of the path on three vertices, and add an edge joining the two vertices of degree two. This is connected and has three vertices in each colour class. But there is no matching of size three.
Comment: @ChrisGodsil Oops you're absolutely right, I'll fix it.


How to query a map field

Question: I am developing the Spectra Analytics module on drupal.org, and one of the interesting new features in Drupal 8 is the ability to create "map" fields in the database. These fields are simply serialized data, such that you can save an associated array to the field, and Drupal will automatically serialize/unserialize the data.
For the main purpose of the module (querying by category and printing large amounts of custom data), this has been great. However, I am looking at applications where it might be useful to query the map data.
How can I do that?
Additional note:
I am reading up on MongoDB and other cases where this kind of data would be stored & query-able as a JSON array, so it seems like this is possible. One example application would be a list of alerts, and in a map field we have an associative array of data about the alert, such as "message," "severity," and "dismissed," and in this case we are looking for a particular "dismissed" property. The alternative solution is to use Field API fields, i.e. create an extra table to hold data that is queried in the traditional way.
Comment: For instance, note the db specific functions injected to db_query on this module: https://www.drupal.org/project/jsonb - I believe that was an example for Postgres. But MySQL has them now, too: https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html - if your database field is a JSON type, you can leverage all of this.
Comment: You can't query within serialized blobs, you can only do this if the table field is JSON type and use special functions of MySQL or Postgres to do this. But for regular serialized arrays, no. There are a couple of modules on Drupal displaying this as a proof of concept.
Comment: Right. I know it isn't possible to query serialized arrays with MySQL by default, which is why I'm looking at what changes I could do now, while this particular module (and possible future modules) are still in alpha. I could look at the JSON field case, and then test it versus using the Field API.
Comment: I've tried it, it's definitely possible. I POC'd it in drupal 7
Comment: Thanks, I will look at the JSONB field module. Go ahead and make it an answer so I can upvote/accept it.
Answer: OK, here's what I've developed so far. I did take Kevn's comment into account, and switched from the Map field to JSONB Field, but the example below does work on a map field if you remove the json_decode() part.
This is the render function for my data viewer, in which users can specify a key. The code will print_r() arrays, or return a string, depending on what it finds. If there is no key, it will print_r the entire field.
This doesn't cover querying, i.e. Views filters, just getting the data out for reporting.
/**
 * {@inheritdoc}
 */
public function render(ResultRow $values)
{
  $render_key = $this->options['spectra_data_render_key'];
  $data_entity = $this->getEntity($values);
  $data_m = $data_entity->get('data_data')->getValue();
  $data_map = isset($data_m[0]['value']) ? json_decode($data_m[0]['value'], TRUE) : FALSE;
  if ($data_map === FALSE) {
    return array(
      '#markup' => '',
    );
  }
  if (!$render_key) {
    return array(
      '#markup' => '
' . print_r($data_map, TRUE) . '
',
    );
  }
  else {
    if (isset($data_map[$render_key])) {
    $item = $data_map[$render_key];
      $markup = is_array($item) || is_object($item) ? '
' . print_r($item, TRUE) . '
' : (string) $item;
      return array(
        '#markup' => $markup,
      );
    }
    else {
      return array(
        '#markup' => '',
      );
    }
  }
}

Note: 'data_data' is a base field for a "spectra_data" entity, and $this->options['spectra_data_render_key'] is a custom field that is added to the settings for the Views field.
If the stored JSON is {"this": "that"}, then passing a key of "this" would return the string "that," and no key would return array("this" => "that").

How to query a map field


Ways to arrange AABBBCCCDD?

Question: Consider the following question:
How many ways are there to order AABBBCCCDD?
My intuition would be to pick two spots from the 10 for letter A, then 3 spots from 8 for the letter B and so on. So our solution would be (10C2)(8C3)(5C3).
However I saw a solution formatted as the following:
10!/(2!3!3!2!)
However I do not understand how they derive this solution. What is the intuition behind that expression?
Comment: Have you tried simplifying $\binom{10}{2}\binom{8}{3}\binom{5}{3}$?
Comment: @N.F.Taussig How would you simplify the above?
Comment: $\binom{10}{2}\binom{8}{3}\binom{5}{3} = \frac{10!}{2!8!} \cdot \frac{8!}{3!5!} \cdot \frac{5!}{3!2!} = \frac{10!}{2!3!3!2!}$.
Comment: Ah I see. Thanks for the help.
Answer: They are all forms of multinomial coefficient which you should look up.
$$\binom{10}{2,3,3,2} \equiv \binom{10}2\binom83\binom53\binom22 \equiv \frac{10!}{2!3!3!2!}$$
Although you can use any of the equivalent forms, I like to think of the three forms as:
(i) putting distinct (=labeled) objects into boxes with matching labels
(ii) forming labeled teams from a pool of people
(iii) permuting a word which has some repeating letters
An intuitive understanding of (iii) can be seen in this answer
Comment: Does the `\Large\binom` look as wonky to you as it does to me? The parentheses aren't large enough at that size. I wonder why that happens.
Comment: @BrianTung: Idk, when i use normal size, on my laptop the figures jump out of the parentheses in the multinomial. (but not on my phone). I am editing it to normal size, could you please let me know if it looks ok.
Comment: Yeah it looks fine now, though of course it is smaller now.
Comment: @BrianTung: Ok, thanks. $\;\;$ :)
Comment: Oh, it didn't even occur to me that you weren't using a display mode equation.
Answer: Instead of a,b,c, and d if we had 10 different numbers we would do 10!. This 10! factorial would be our starting point.
Now let's say you have a set of two numbers, AB and AA
AB would have two rearrangements, AB and BA.
AA would have one arrangement, AA.
When we have a set of numbers and we have values that are the same, they are counted as the same number. Because of this, you would divide the number of ways where the same values could rearrange.
An example is the set ABCDD
If we had ABCDE, the number of rearrangements would be 120.
If you do 5! for ABCDD, you are counting ABC(D1)(D2) and ABC(D2)(D1) as different arrangements. Because of this, AABBBCCCDD would have 10!/2!(A's) 3!(B's) 3!(C's) 2!(D's).

Ways to arrange AABBBCCCDD?


How to find the integral curves that are orbits of one-parameter groups?

Question: Consider $\mathbb{R}^2$ with standard symplectic structure and inner product. Consider a Hamiltonian $$H=(x,y)A(x,y)^t$$ where $$A=\begin{pmatrix} \alpha & \beta \\ \beta & \delta \end{pmatrix}$$ with entries in $\mathbb{R}.$ I have to determine for which $A$ are the integral curves given by orbits of one-parameter groups acting by isometries of $\mathbb{R}^2$ and need to give explicit formula for such an orbit. I have problems here. One is I don't understand what I am supposed to do.
I understand the following:

Let $M$ be a smooth manifold. If $\theta: \mathbb{R} \times M \to M $
   is a global flow, then we immediately have following maps:
$\forall t \in \mathbb{R}, \quad \theta_ t: M \to M$ is diffeomorphism.
$\forall \ p \in M,$ we have smooth curve $\theta ^ {(p)}: \mathbb{R} \to M$ with image as the orbit of $p$ under the group action.
And lastly, $\mathbb{R} \to Diff(M)$ is a group homomorphism.

I don't know how to use this understanding to solve my problem. Please help!
Comment: Patience, my friend, I'm working on it!
Comment: Let me know if you have any questions!  One more time, Cheers!
Comment: So glad you decided to "undelete" this question!  I think it is very good, and was dismayed by its (fortunately temporary) disappearance!  New Years Cheers!
Comment: @RobertLewis: New year to you too! Please give some ideas about what I am supposed to do in this question!
Comment: @RobertLewis: got time to look at the above problem? Thanks!
Comment: Yes, I hope to post in a couple of hours!   Will keep you "posted"!  New Year's Cheers!
Comment: No problem! I look forward to that!
Comment: Almost done . . . 20 minutes!
Comment: Whoops!  *Really* almost done . . . need another 20!  Cheers!
Comment: No problem! I can afford to wait until everything is settled.
Comment: You sir are a gentleman and a scholar!
Comment: Posted!  Sorry about the delays, and thanks for your patience once again!  Now go party your ass off!  Happy New Years!
Comment: @RobertLewis Thanks a lot! Yes, I hope I understand this very soon, and would like to take a break! Happy new year to you as well! Thanks again!
Answer: The standard symplectic structure on $\Bbb R^2$ is given by the two-form
$\omega = dx \wedge dy, \tag{1}$
and the standard inner product $\langle \cdot, \cdot \rangle$ is
$\langle \mathbf r_1, \mathbf r_2 \rangle = \mathbf r_1^T \mathbf r_2 = x_1 x_2 + y_1 y_2, \tag{2}$
where
$\mathbf r_i = \begin{pmatrix} x_i \\ y_i \end{pmatrix} \in \Bbb R^2, \; \; i = 1, 2. \tag{3}$
We note that taking
$\mathbf e_x = \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \dfrac{\partial}{\partial x} \tag{4}$
and
$\mathbf e_y = \begin{pmatrix} 0 \\ 1 \end{pmatrix} = \dfrac{\partial}{\partial y},\tag{5}$
we have
$\omega (\mathbf e_x, \cdot) = dx (\dfrac{\partial}{\partial x}) dy = dy \tag{6}$
and
$\omega(\mathbf e_y, \cdot) = (dx \wedge dy)(\dfrac{\partial}{\partial y }) = -(dy \wedge dx)(\dfrac{\partial}{\partial y }) = -dy(\dfrac{\partial}{\partial y })dx = -dx. \tag{7}$
$\omega$ may of course be construed as a linear map $T_\omega: \Bbb R^2 \to (\Bbb R^2)^\ast$, the dual space of $\Bbb R^2$, by defining, for $\mathbf v \in \Bbb R^2$,
$T_\omega(\mathbf v) = \omega(\mathbf v, \cdot); \tag{8}$
then
$(T\omega(\mathbf v))(\mathbf w) = \omega(\mathbf v, \mathbf w). \tag{9}$
(6) and (7) show that the matrix of $T_\omega$, using the bases $\mathbf e_1$, $\mathbf e_2$  of $\Bbb R^2$, and $dx$, $dy$ of $(\Bbb R^2)^\ast$, is given by
$[T_\omega] = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}; \tag{10}$
this matrix representation of $\omega$ will prove convenient in the computations which follow.  We also recall that we may, with the aid of the inner product $\langle \cdot, \cdot \rangle$ on $\Bbb R^2$, identify vectors $\mathbf v$ in $\Bbb R^2$ with dual vectors in $(\Bbb R^2)^\ast$, via the map $\phi$ which sends $\mathbf v$ to $\phi(\mathbf v) = \langle \mathbf v, \cdot \rangle$, that is
$(\phi(\mathbf v))(\mathbf w) = \langle \mathbf v, \mathbf w \rangle, \tag{11}$
holding for all $\mathbf w \in \Bbb R^2$.  The map $\phi$ of course identifies elements of $\Bbb R^2$ with those of $(\Bbb R^2)^\ast$, but in a different way than $\omega$; it is easy to see that
$\phi(\mathbf e_x) = dx \tag{12}$
and
$\phi(\mathbf e_y) = dy; \tag{13}$
for example,
$(\phi(\mathbf e_x))(\mathbf e_x) = \langle \mathbf e_x, \mathbf e_x \rangle = 1 = dx(\mathbf e_x), \tag{14}$
and
$(\phi(\mathbf e_x))(\mathbf e_y) = \langle \mathbf e_x, \mathbf e_y \rangle = 0 = dx(\mathbf e_y), \tag{15}$
establishing (12); of course (13) is similarly shown.  (12)-(15) are illustrative of the self-duality property of inner product spaces; that is, vectors in such spaces may be identified with elements of the dual space via maps such as $\phi$ which arise naturally from an inner product structure.  Of course, the matrix of $\phi$ with respect to the bases used above for $\omega$ is
$[\phi] = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = I, \tag{16}$
and we observe that the map $\phi^{-1} \circ T_\omega : \Bbb R^2 \to \Bbb R^2$ satisfies
$\phi^{-1} \circ T_\omega(\mathbf e_x) = \mathbf e_y \tag{17}$
and
$\phi^{-1} \circ T_\omega(\mathbf e_y) = -\mathbf e_x \tag{18}$
with matrix
$[\phi^{-1} \circ T_\omega] = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}. \tag{19}$
(18) in fact may clearly be regarded as an expression of the symplectic form $\omega$ in terms of the corresponding representation as an opertor on $\Bbb R^2$; either form may be used in computations, and I will so do in the following.
I have belabored these preliminary points at some length in order to resolve any ambiguities with the definitions my readers may experience due to possibly differing backgrounds.
Having seen these things, we turn to the Hamiltonian at hand,
$H = (x,y)A(x,y)^T, \tag{20}$
where
$A = \begin{bmatrix} \alpha & \beta \\ \beta & \delta \end{bmatrix}; \tag{21}$
we see from (20), (21) that
$H = (x, y)\begin{bmatrix} \alpha & \beta \\ \beta & \delta \end{bmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = (x, y) \begin{pmatrix} \alpha x + \beta y \\ \beta x + \delta y \end{pmatrix} = \alpha x^2 + 2\beta xy + \delta y^2. \tag{22}$
We pause to observe that there is no loss of generality in taking $A$ to be a symmetric matrix, i.e., taking $A_{12} = A_{21} = \beta$ rather than, say $A_{12} = \beta$, $A_{21} = \gamma$, since in this case the Hamiltonian would be
$H = \alpha x^2 + (\beta + \gamma) xy + \delta y^2. \tag{23}$
Inspection of (22) reveals that the coefficient of the $xy$ term in $H$ depends only on the sum $\beta + \gamma$, and not on $\beta$ and $\gamma$ separately.  Another way to see this is to write
$A = A_+ + A_-, \tag{24}$
where $A_+$, $A_-$ are the symmetric and skew-symmetric parts of $A$:
$A_+ = \dfrac{A + A^T}{2} = A_+^T = \begin{bmatrix} \alpha & \dfrac{\beta + \gamma}{2} \\ \dfrac{\beta + \gamma}{2} & \delta \end{bmatrix}, \tag{25}$
$A_- = \dfrac{A - A^T}{2} = -A_-^T = \begin{bmatrix} 0 & \dfrac{\beta - \gamma}{2} \\ \dfrac{\gamma - \beta }{2} & 0 \end{bmatrix}. \tag{26}$
Since for any skew-symmetric matrix $K$ and vector $\mathbf z$ we have
$\mathbf z^T K z = 0, \tag{27}$
we see that
$(x, y) A (x, y)^T = (x, y) (A_+  + A_-)(x, y)^T$
$= (x, y)A_+(x, y)^T + (x, y)A_-(x, y)^T = (x, y)A_+(x, y)^T, \tag{28}$
i.e., the quadratic form $(x, y) A (x, y)^T$ only depends on the symmetric part of $A$; the independence of $\beta$ and $\gamma$ "washes out", as it were; we need only consider the case $A_{21} = \gamma = \beta = A_{12}$ when evaluating quadratic forms such as $H$.
Returning to the problem at hand, we have from (21)
$dH = \dfrac{\partial H}{\partial x}dx + \dfrac{\partial H}{\partial y}dy = (2\alpha x + 2\beta y)dx + (2\beta x + 2\delta y)dy. \tag{29}$
The vector field $\mathbf X_H$ driving the corresponding Hamiltonian dynamical system
by definition satisfies
$dH = \omega(\mathbf X_H, \cdot) = T_\omega(\mathbf X_H); \tag{30}$
setting
$\mathbf X_H = \begin{pmatrix} X_x \\ X_y \end{pmatrix}, \tag{31}$
we may apply (17)-(19) to (30), (31) and find
$\phi^{-1} \circ T_\omega (\mathbf X_H) = \phi^{-1}(dH) = \phi^{-1}(\dfrac{\partial H}{\partial x}dx + \dfrac{\partial H}{\partial y}dy) = \dfrac{\partial H}{\partial x} \phi^{-1}(dx) + \dfrac{\partial H}{\partial y} \phi^{-1}(dy)$
$= \dfrac{\partial H}{\partial x} \mathbf e_x + \dfrac{\partial H}{\partial y} \mathbf e_y, \tag{32}$
and
$\phi^{-1} \circ T_\omega(\mathbf X_H) = \phi^{-1} \circ T_\omega(X_x \mathbf e_x + X_y \mathbf e_y)$
$= X_x \phi^{-1} \circ T_\omega(\mathbf e_x) + X_y\phi^{-1} \circ T_\omega(\mathbf e_y) =  X_x \mathbf e_y - X_y \mathbf e_x. \tag{33}$
Comparing (32) and (33) we see that
$\mathbf X_H = \begin{pmatrix} X_x \\ X_y \end{pmatrix} = \begin{pmatrix} \dfrac{\partial H}{\partial y} \\ -\dfrac{\partial H}{\partial x} \end{pmatrix} = \begin{pmatrix} 2 \delta y +  2\beta x \\ -2\alpha x - 2 \beta y \end{pmatrix} = \begin{bmatrix} 2\beta & 2\delta \\ -2 \alpha  & -2 \beta \end{bmatrix} \begin{pmatrix} x \\ y \end{pmatrix}; \tag{34}$
the Hamiltonian vector field is thus linear with coefficient matrix
$B = \begin{bmatrix} 2\beta & 2\delta \\ -2 \alpha  & -2 \beta \end{bmatrix}, \tag{35}$
and the Hamiltonian differential equations in this case become, setting
$\mathbf r = \begin{pmatrix} x \\ y \end{pmatrix}, \tag{36}$
$\dot {\mathbf r} = B \mathbf r. \tag{37}$
At Last, we are now and finally in a position to dispose of the posed questions in rather short order.  First, and explicit formula for the flow $\theta_t$ may be written
$\theta_t(\mathbf r_0) = e^{Bt} \mathbf r_0, \tag{38}$
as follows for any constant-coefficient linear system.  Here $\mathbf r_0 = (x_0, y_0)^T$ is the initial point.  Explicit formulas for $\theta_t(\mathbf r_0)$ may now be derived in the usual fashion by computing $e^{Bt}$ explicitly using the Jordan form of $B$, that is, by calculating its eigenvalues and their invariant subspaces.  However, a lot of this effort may be short-circuited by addressing the first question, that is, for which $A$ does the flow $\theta_t(\mathbf r_0) = e^{Bt} \mathbf r_0$ act by isometries? this is pretty easy.  One-parameter groups of such linear isometries of the form $e^{Bt}$ of $\Bbb R^2$ are characterized by the property that
$\langle e^{Bt} \mathbf r_1, e^{Bt} \mathbf r_2 \rangle = \langle \mathbf r_1, \mathbf r_2 \rangle; \tag{39}$
for any and all vectors $\mathbf r_1, \mathbf r_2 \in \Bbb R^2$.  Differentiating (38) with respect to $t$ yields
$\langle Be^{Bt} \mathbf r_1, e^{Bt} \mathbf r_2 \rangle + \langle e^{Bt} \mathbf r_1, Be^{Bt} \mathbf r_2 \rangle = 0; \tag{40}$
setting $t = 0$ in (40) yields
$\langle B\mathbf r_1,  \mathbf r_2 \rangle + \langle  \mathbf r_1, B \mathbf r_2 \rangle = 0; \tag{41}$
in the usual manner (41) implies
$\langle \mathbf r_1,  B^T \mathbf r_2 \rangle + \langle  \mathbf r_1, B \mathbf r_2 \rangle = 0, \tag{42}$
or
$\langle \mathbf r_1, (B^T + B)\mathbf r_2 \rangle = 0. \tag{43}$
Since $\mathbf r_1$ and $\mathbf r_2$ are arbitrary, this yields
$B^T + B = 0, \tag{44}$
or
$B^T = -B; \tag{45}$
$B$ must be skew-symmetric.  Examining (35) in the light of this discovery shows that $\alpha = \delta$, $\beta = 0$; from (21) we see that $A$ must be of the form
$A = \begin{bmatrix} \alpha & 0 \\ 0 & \alpha \end{bmatrix} = \alpha I; \tag{46}$
when written out in terms of components the Hamiltonian equations thus become
$\dot x = 2 \alpha y, \tag{47}$
$\dot y = -2 \alpha x; \tag{48}$
after a little fiddling around (47)-(48) may be written
$\ddot x + 4 \alpha^2 x = 0; \tag{49}$
this is the equation of a harmonic oscillator with force constant-to-mass ratio $4\alpha^2$; at this point it's probably safe, explanation and derivation-wise, to cut to the chase scene and realize we can write the solutions of (47)-(48) as
$x(t) = x_0 \cos 2\alpha t + y_0 \sin 2 \alpha t, \tag{50}$
$y(t) = y_0 \cos 2\alpha t - x_0 \sin 2 \alpha t; \tag{51}$
(50), (51) explicitly describe the flow $\theta_t$ of our system, to wit:
$\theta_t((x_0, y_0)^T) = (x_0 \cos 2\alpha t + y_0 \sin 2 \alpha t, y_0 \cos 2\alpha t - x_0 \sin 2 \alpha t)^T. \tag{52}$
And I think we're finally done!!!
Note:  the definitive formula (30) and one hell of a lot of other stuff about Hamiltonian systems may be found in Abraham and Marsden's awesome classic, Foundations of Mechanics, available for free and legal download from Caltech; see here.  A very thorough and advanced work, chock full of the good stuff.  End of Note.
Hope this helps.  New Year's Blessings to One and All,
and as ever,
Fiat Lux!!!
Comment: @monomorphic:  I am deeply honored by your kind words.  I don't think I have ever been complemented so nicely on MSE.  Reward me by continuing to probe these deep questions.  I look forward to more insightful queries and answers on your part.  And thanks for the "acceptance"!  And don't forget to party!  Cheers!
Comment: Hello my friend, I cannot thank you enough for such a great exposition! You explained things like no one has done before for me. Everything is clear! Please accept my deepest gratitude! Thanks a lot!


sum of maximum and minimum value of $\frac{1}{1+\left(2\cos x-4\sin x\right)^2}$

Question: What is sum of maximum and minimum value of $\frac{1}{1+\left(2\cos x-4\sin x\right)^2} $ over $x \in \mathbb{R}$?
for fraction to be maximum demoninator has to be minimum, that is $(2\cos x-4\sin x)^2$ has to be minimum OR abolute value of $(2\cos x-4\sin x)$ is minimum.
if $2\cos x-4\sin x=0 \implies \tan x=\frac{1}{2}$  so there does exist values of x such that $2\cos x-4\sin x=0$ so maximum value of $\frac{1}{1+\left(2\cos x-4\sin x\right)^2} $ is $1$
how to find minimum of this function.
Comment: $(\cos x, \sin x) $   is a unit vector in the plane.  The expression $2 \cos x - 4 \sin x$  is the ordinary dot product of the unit vector with $(2,-4)$    Extremes of the dot product occur when either the two vectors are perpendicular  or they are parallel. What could be a unit vector parallel to $(2,-4)   \; \; ? \; \; \;  $
Comment: Take derivative of $(2\cos x-4\sin x)^2$. You'll find 2 conditions.
Answer: \begin{align}
2\cos(x) - 4\sin(x) &= R\cos(\alpha + x) \\
\implies 2\cos(x) - 4\sin(x)& = R\cos(\alpha)\cos(x) - R\sin(\alpha)\sin(x)
\end{align}
Equating coefficients, we have
$$R\cos(\alpha) = 2 \; \text{and} \; R\sin(\alpha) = 4$$
It follows that
$$R^2 = 2^2 + 4^2 \implies R = \pm 2\sqrt{5}$$
Hence,
$$\frac{1}{1+\left(2\cos x-4\sin x\right)^2} = \frac{1}{1 + 20\cos^2(\alpha + x)}$$
Recall that $0 \le \cos^2(x) \le 1$.
Therefore,
$$\max\left(\frac{1}{1+\left(2\cos x-4\sin x\right)^2}\right) = \frac{1}{1 + 20\cdot0} = 1 \tag{1}$$
$$\min\left(\frac{1}{1+\left(2\cos x-4\sin x\right)^2}\right) = \frac{1}{1 + 20\cdot1} = \frac{1}{21} \tag{2}$$
$$(1) + (2) = 1 + \frac{1}{21} = \boxed{\frac{22}{21}}$$


Block yum from installing or updating a package (mariadb) in future

Question: We've just set up a Centos 8 server, and had to install MySQL on there instead whilst migrating services for the time.
All is working, we've removed MariaDB and MySQL is working fine.
What I would like to do, is block MariaDB from every being installed with yum by accident via some dependency (so happy if we later remove it from some exclude list for example).
I was looking at /etc/yum.conf and the line exclude= but it's unclear if that's just for updates, and if someone typed yum install somepackage that had a mariadb dependency if that would overwrite our mysql install.
So, is there a way to permanently block a package from being found or installed, and also to try and indicate that it's blocked if you try ?
Answer: This answer from the unix stack exchange is pretty much on point.
It essentially says yum won't allow you to exclude a package as a dependency because then it would be doing a terrible job at being a package manager. There is a work around, in that you can use:
rpm -i --nodeps [package].rpm
to install the package without any dependencies, but then you'll be stuck managing that package manually.
Personally, I would just add the exclude=mariadb* line to your yum.conf and live with the risk that somewhere down the road mariadb gets accidentally installed as a dependency.


Meaning of variables and applications in lambda calculus

Question: The wikipedia definition of lambda terms is:

The following three rules give an inductive definition that can be
  applied to build all syntactically valid lambda terms:

a variable, $x$, is itself a valid lambda term
if $t$ is a lambda term, and $x$ is a variable, then $(\lambda x.t)$ is a lambda term (called a '''lambda abstraction''');
if $t$ and $s$ are lambda terms, then $(ts)$ is a lambda term (called an '''application'''). Nothing else is a lambda term. Thus a
  lambda term is valid if and only if it can be obtained by repeated
  application of these three rules. However, some parentheses can be
  omitted according to certain rules. For example, the outermost
  parentheses are usually not written.

However, I cannot understand what variables are. Are they numbers? Or are they functions?
What is the result of an application? Is it a number or is it a function?
Reading many explanations regarding lambda calculus, I often see expressions like:
$$\lambda x.x+3$$
But, according to the definition above, those expressions are not valid lambda terms, because integers and operators are not valid lambda terms. So I guess I cannot express arithmetic expressions in lambda calculus. How can I describe functions?
Comment: $\lambda$-calculus is pure syntax – everything is just a symbol. But you _can_ actually do arithmetic in $\lambda$-calculus using Church numerals.
Comment: @ZhenLin Church encoding is what I was looking for. If you post it as an answer, I will accept it.
Answer: Pure $\lambda$-calculus is rather restrictive. Nevertheless, you can extend it to contain "$3$" and "$+$" (either by really extending the language, or perhaps by denoting by $3$ some special lambda term like $\lambda f.\ \lambda x.\ f(f(f x))$).
Variables are unique symbols (most often strings), which make it easier to construct lambda-terms and define the whole affair. Compare for example De Brujin  index, which uses plain numbers for the same task.
When thinking about lambda-terms, think about ordinary functions, only defined on some weird domain, e.g. for your example it would be
$x \mapsto x+3,$
or using different notation
$$f$$
where
$$f(x) = x+3.$$
Also, note the difference, $f(x)$ is not $f$, that is, $f$ is a function, while $f(x)$ is a symbol $x$ applied to function $f$; in other words you can write $f = x \mapsto x+3$, but $f(x) = x \mapsto x+3$ would be nonsensical (or it could yield falsehood, depending on your interpretation of "$=$", but that's different story).
The type of result of an application depends on a function. For $f$ it would be a number, e.g. $f(4) = 7$, but for a diffrent function like $g$ it could be another function, for example
$$g = y \mapsto (x \mapsto x + y),$$
or in other notation
$$g(y)(x) = x+y.$$
Now, the result of $g(3)$ is a function, and it happens that $g(3) = (x \mapsto x+3) = f$, or to put it different way $g(3)(x) = x+3 = f(x)$. This happens because $f : \mathbb{N} \to \mathbb{N}$, while $g : \mathbb{N} \to (\mathbb{N} \to \mathbb{N})$, or as set-theorists would sometimes write $g : \mathbb{N} \to \mathbb{N}^\mathbb{N}$, hence $g(3) : \mathbb{N} \to \mathbb{N}$. Of course, in $\lambda$-calculus I could write these applications withouth parentheses, e.g. $g\ 3\ 5 = 8$ (and the equality sign isn't actually good, there are many types of equality, and here it could mean reduction which is yet a different kind of beast than equality).
I hope this helps $\ddot\smile$
Answer: The point is that $\lambda$-calculus is pure syntax. The symbols are just symbols and don't stand for anything in particular. However, it is possible to do arithmetic in $\lambda$-calculus using Church numerals.
This is not to be confused with the simple notion of $\lambda$-abstraction, which finds use outside $\lambda$-calculus as a convenient way of defining function terms.


Sencha Extjs - How to use grid getRowClass() dynamically from Controller

Question: I have a checkbox column in my grid that displays Yes/No based on checkbox selection.
Requirement:
If checkbox value == Yes, change row color Green
Else Leave as is (default).
Steps I have taken so far:
On Ext.grid.View set the getRowClass function, something like this:
<code> viewConfig: {
 getRowClass: function(record, rowIndex, rowParams, store) {
 if (record.get('isApproved') == true)
   {
     return 'highlight-rowgreen';
   }
 },
</code>
This works perfectly fine. However I want achieve this in a store.sync callback which is not happening at the moment. There is no error, nothing. Just doesnt work.
<code>var store = Ext.getStore('MyApp.MyStore');
        store.proxy.url = MYAPP.globals.url + "myapplication/" + branchNo + "/event/" + branchEventId;
        store.sync({
            scope: this,
            callback:function (records, operation, success) {
                if(records.proxy.reader.rawData.success){
                // Success. Set the rows color to green if not already done.
                   alert('Update Completed');
                   eventsGrid.getView().getRowClass = function(record, rowIndex, rowParams, store){
                       console.log('I am here');
                       if (record.get('isApproved') == true)
                       {
                        return 'highlight-rowgreen';
                       }
                      };
                  }
                  else{
                     alert('Update failed');
                  }
                }
        });
</code>
What I cant see is my console log "I am here". I can see the Alert message alright.
I have tried other solutions as well like this but not happening.
Any help is appreciated. Thanks
Comment: Grid rows are re-rendered *whenever* the relevant record's data changes, and `getRowClass` will be called every time. It does not matter how the data gets changed — locally only or with the involvement of remote sync. Therefore there is no need to re-define `getRowClass` anywhere like you are doing in sync callback. Data change will result in re-rendering the row and placing or removing your `highlight-rowgreen` class accordingly. See [this example](https://fiddle.sencha.com/#fiddle/pn4).
Answer: You do not need to set rowclass again in store sync callback. It should work just as is. It could be that your grid view needs a refresh. Try this..
<code> store.sync({
        scope: this,
        callback:function (records, operation, success) {
            if(records.proxy.reader.rawData.success){
            // Success. Set the rows color to green if not already done.
               alert('Update Completed');
               eventsGrid.getView().refresh(); //refresh grid view
              }
              else{
                 alert('Update failed');
              }
            }
    });
</code>
Comment: Thanks for that. But eventsGrid.getView().refresh(); doesnt do anything. The value of the record is correct, its only on the screen that it is not refreshed.
Comment: Hmm... as @DrakeES said, there is nothing to be done as such, it should work just as is. The getView().refresh() simply refreshes the grid view with your new data. Another thing to check is if the store instance in your grid is same as the one you are calling sync on. Sorry for the answer, I don't have enough reputation to add a comment so my hand was forced.


Flutter setState adding items dynamically

Question: So I wanna the user type in the TextFormField then pop in the Text field above using setState or if anyone has better suggestion to implement that. I'd improve that text field afterwards with a list or something...
setState Code
  TextEditingController textcontroller = TextEditingController();

  Widget addtasks() {
    setState(() {
      Text(textcontroller.text);
    });
    return Text(textcontroller.text);
  }

Form Maker CODE
Widget form_maker(textcontroller) {
  return TextFormField(
    controller: textcontroller,
    keyboardType: TextInputType.text,
    onFieldSubmitted: (String value) {
      print(value);
    },
    onChanged: (String value) {
      print(value);
    },
    decoration: const InputDecoration(
      labelText: 'Add task...',
      prefixIcon: Icon(
        Icons.add,
      ),
      border: OutlineInputBorder(),
    ),
  );
}

Also the FloatingActionButton have plans for it i implemented the ShowBottomSheet but couldn't link it to anything from the body onPressed func in it
FAB CODE
floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.add),
        backgroundColor: Colors.red,
        hoverColor: Colors.white,
        splashColor: Colors.white,
        onPressed: () {
          showModalBottomSheet(
              context: context,
              builder: (context) {
                return Wrap(
                  children: [
                    InkWell(
                      child: const ListTile(
                        leading: Icon(Icons.edit),
                        title: Text('Add Task'),
                      ),
                      onTap: () {},
                    ),
                    const ListTile(
                      leading: Icon(Icons.share),
                      title: Text('Share'),
                    ),
                    const ListTile(
                      leading: Icon(Icons.link),
                      title: Text('Get link'),
                    ),
                    const ListTile(
                      leading: Icon(Icons.remove_outlined),
                      title: Text('Remove'),
                    ),
                  ],
                );
              });
        },
      ),

Answer: Just use setState in onChanged callback
import 'package:flutter/material.dart';

const Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatefulWidget {

  @override
  _MyWidget createState() => _MyWidget();
}

class _MyWidget extends State<MyWidget> {

  String text = "";
  TextEditingController _controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      Text(
        text,
        style: Theme.of(context).textTheme.headline4,
      ),
      const Divider(),
      TextFormField(
        controller: _controller,
        decoration: const InputDecoration(
          labelText: 'Add task...',
          prefixIcon: Icon(
            Icons.add,
          ),
          border: OutlineInputBorder(),
        ),
        keyboardType: TextInputType.text,
        onChanged: (val) {
          setState(() {
            text = _controller.text;
          });
        },
      )
    ]);
  }
}

You can also do the same without TextEditingController by putting value of the field
        onChanged: (val) {
              setState(() {
                text = val;
              });
            }


Did Elliott Smith use Chromatic Mediants?

Question: Just a quick question. So I'm watching this video about theory on Elliott Smith and the guy that made this says: "I think that the number one most important thing that you'll hear in his songs. Moving major chords in minor thirds. If you take nothing else from this video that is definitely it."
Then he gives some examples of chord progressions that do this:
Miss Misery: F major to Aflat major
Son of Sam: E major to G major
Distorted Reality: D major to F major.
Sweet Adeline: G major to Bflat major.
Now he never actually says it in the vid, but aren't all these just examples of chromatic mediants?
Comment: Knock on Wood, Proud Mary, possibly Smoke on the Water intros - Chrom. meds?
Answer:
In music, chromatic mediants are "altered mediant and submediant chords."A chromatic mediant relationship defined conservatively is a relationship between two sections and/or chords whose roots are related by a major third or minor third, and contain one common tone (thereby sharing the same quality, i.e. major or minor).

Source: Wikipedia
So yes.
If you want an example with minor chords (not from Elliot Smith though), first that comes to my mind is the beginning of the verse from Depeche Mode - Enjoy the Silence, Cm to Ebm.


Finding expression of $n$-th derivative, when $n$ is large

Question: For completeness, assume $C$ is an Archimedean copula with some generator function $\varphi$, which is usually assumed to have nice properties. It is known that $$ C(u_1, u_2, \ldots, u_n)=\varphi^{-1}(\varphi(u_1) + \ldots +\varphi(u_n))$$If my math is correct, for an $n-$variable copula, we can estimate its density function by
$$ \frac{\partial^n C}{\partial u_1 \partial u_2 \cdots \partial u_n } = \{\varphi^{-1}\}^{(n)}(\varphi(u_1) + \ldots +\varphi(u_n))\prod_{j=1,\ldots,n} \varphi'(u_j) $$
However, with large $n$, it is not a surprise that it's quite computationally/memory intensive finding $\varphi^{-1}$ derivatives of the $n-$th order.
My question: what are the most well known/fastest strategies for quick derivations of $\{\varphi^{-1}\}^{(n)}$? I'm not entirely sure what exactly I'm looking for here -- either a faster/cleaner way of finding the expression for density that wouldn't involve derivatives (if such exists?), or some sort of an approximation, that would make finding the expressions a more feasible task?
As a side note, I'm trying to get the expression of the density function and plug-in various values to it. Currently I've tried using deriv function on R, which is able to handle the derivations up to say $n \sim 15$.
A possible workaraound would be to simulate a sample from the wanted copula distribution and non-parametrically estimate its density via some kernel smoother, but as far as I know, kernel smoothers also are quite complex and slow in large dimensions.
Comment: @whuber thanks for the good hint. For some particular families I am able to find some derived expressions, say [in this paper](https://arxiv.org/pdf/1108.6032.pdf), will just have to look more into it. Though I was hoping for some trick that would help with all (or most) generators, this here is a nice start and will try to learn some tricks from here on.
Comment: It depends on what you know about $\phi^{-1}$ and how you know it.  For instance, if it is given as a power series, a Fourier transform, or a Laplace transform, then there are very efficient accurate solutions available.  What, then, can you tell us about your $\phi^{-1}$?
Comment: Thanks! The most common generators [are listed in the second table here on Wiki](https://en.wikipedia.org/wiki/Copula_(probability_theory)#Most_important_Archimedean_copulas). Probably, exponent functions could be written as power series to some extent (would approximation to some degree work too?), will have to look more into the other two cases you mentioned.
Answer: I am not an expert in this area, so please take this answer with a grain-of-salt.  Since you have not specified a functional form for your objects I am going to give an answer that applies at a broad level of generality.  (No doubt there are better methods if you are willing to specify more about your particular forms.)  Anyway, one way to compute this problem, in a specification that encompasses a broad class of functional forms, is to take a finite difference approximation to the partial derivative (see e.g., here).  I do not know if this will give good performance for large $n$, but it is an avenue worth exploring, so I add it here as a suggestion.
Let $\Delta_h$ denote the forward difference operator so that $\Delta_h f(x) = f(x+h) - f(x)$ for a scalar function $f$.  Extend this to a multivariate setting by defining the multivariate operator:
$$\Delta_h^{(k)} \equiv (1, ..., 1, \Delta_h, 1,..., 1),$$
where the finite difference element in the latter vector occurs in the $k$th position, and the unit operators operate on a function multiplying it by one (i.e., leaving it unchanged).  Now, from the first principles definition of Riemann differentiation we have:
$$\frac{\partial}{\partial u_k} C(\mathbf{u}) = \lim_{h \downarrow 0} \frac{\Delta_h^{(k)}}{h} C (\mathbf{u}) \approx \frac{\Delta_h^{(k)}}{h} C (\mathbf{u}) \quad \quad \quad \text{for small } h \approx 0.$$
Hence, if you choose some small value $h \approx 0$, you should get:
$$\begin{equation} \begin{aligned}
\frac{\partial^n C}{\partial u_1 \cdots \partial u_n}(\mathbf{u})
= \frac{\partial}{\partial u_1} \cdots \frac{\partial}{\partial u_n} C(\mathbf{u})
\approx \frac{\Delta_h^{(1)} \cdots \Delta_h^{(n)}}{h^n} C(\mathbf{u})\\[6pt]
\end{aligned} \end{equation}$$
It should be possible computationally to form the function $\Delta_h^{(1)} \cdots \Delta_h^{(n)} C$ for arbitrary $h$ via combinatorial sums, and since you are using a small values of $h$ you might be able to further approximate this by ignoring some terms.  I'm not sure how computationally-intensive this would be for large $n$, but it is something worth investigating.  That's all I can really add here --- I'm not sure this method would yield a helpful solution, but it is an avenue that I think is worth exploring.
Comment: Unfortunately, the directions you suggest augment the problems rather than resolve them.  The $h^n$ denominator is a clue about the potential numerical instability of this approach.  Moreover, this is an *exponential* algorithm: to compute  these repeated derivatives in a stable, unbiased way you need $2^n$ evaluations of $C.$ I believe the key to any effective solution is to turn away from such black-box generic approaches and find ways to exploit the particular form of this copula function.
Comment: Thanks, good point, I was considering a similar idea, plus also maybe a reversed Taylor (up to a certain feasible $n$), but will have to try it out in practice. As for the concrete functional expressions, I've commented a link to wiki under @whuber comments after the original question. I might want to edit the question for future clarification, but a broad level approximation you're suggesting is also of interest! Thanks again


Calculation of radical ideal in $\mathbb Z_{36} $

Question: Let $R$ be the ring $\mathbb Z_{36}$.
How can I calculate  $ \sqrt{\langle 0\rangle} , \sqrt{\langle 9\rangle} $?
Answer: $\DeclareMathOperator{\Z}{\mathbf{Z}}$You're calculating radicals in $\Z/36\Z$. Ideals in that ring correspond to ideals of $\Z$ which contain $36$, and this correspondence preserves the property of an ideal being prime. Remember that the radical of an ideal is equal intersection of all prime ideals containing it. So, for example, which two prime ideals of $\Z$ contain $36$?
Answer: If $\mathfrak m_1,\dots,\mathfrak m_n$ are distinct maximal ideals of a Dedekind domain, and if $k_1,\dots,k_n$ are positive integers, then the radical of
$$
\prod_{i=1}^n\ \mathfrak m_i^{k_i}
$$
is
$$
\prod_{i=1}^n\ \mathfrak m_i.
$$
EDIT. The following fact is also relevant. If $\mathfrak a$ is an ideal of a commutative ring $A$, then the correspondence between ideals of $A/\mathfrak a$ and ideals of $A$ containing $\mathfrak a$ is compatible with radicals.


Making Span tag cover entire width of button

Question: I have the following structure:

  <button class="wrap">
    Hello
  </button>

I have the following CSS:
.top{
  background-color:yellow;
  width: 216px;
  height: 70px;
}

.wrap, .text{
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
}

I have seen several posts regarding the "span taking the entire width of their parent" and the most popular answer was to make it display: block;
But in this case, it doesn't work. If you inspect, you will see that the span is taking 200px width instead of 216px width (width of button).
How can I fix this problem? Here is the fiddle
Comment: Try setting the padding on your button to zero
Answer: There is padding in your .wrap class.  Set padding to 0 on your .wrap, .text declaration.
.top {
  background-color:yellow;
  width: 216px;
  height: 70px;
}

.wrap, .text {
  padding: 0px;  //set padding to 0px
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
}

Comment: I just figured out the answer too by looking at the computed styles! I was about to post my answer but you were fast! Thanks a lot :)


Different versions of R, lme4 and OS X give different fixed-effects significance results in glmer

Question: I am running a logit mixed-effects model using glmer() in package lme4.
The experiment used a within-subjects within-items design with Subjects and Items as crossed random effects.
My problem: different versions of R and lme4 (run on different OS X) produce different standard errors estimates for the fixed effects, and consequently, different significance results.
Here is a subset of my data (data from the last two subjects):
structure(list(SubjN = c(87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L,
87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L,
87L, 87L, 87L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L,
88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L, 88L,
88L), Items = structure(c(3L, 10L, 11L, 5L, 1L, 12L, 2L, 6L,
9L, 6L, 3L, 4L, 8L, 11L, 12L, 7L, 8L, 2L, 7L, 10L, 9L, 5L, 1L,
4L, 10L, 3L, 5L, 11L, 12L, 1L, 2L, 6L, 9L, 6L, 3L, 4L, 8L, 11L,
12L, 7L, 2L, 8L, 10L, 7L, 9L, 5L, 1L, 4L), .Label = c("a", "c",
"k", "f", "g", "i", "d", "l", "e", "j", "b", "h"), class = "factor"),
IV1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("N", "L", "P"
), class = "factor"), DV = c(0, 0, 1, 0, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,
0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
IV1.h = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), contrasts = structure(c(-1,
0.5, 0.5, 0, -0.5, 0.5), .Dim = c(3L, 2L), .Dimnames = list(
    c("N", "L", "P"), c("N_vs_L&P", "L_vs_P"))), .Label = c("N",
"L", "P"), class = "factor"), N_vs_LP = c(-1, -1, -1, -1,
-1, -1, -1, -1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -1, -1, -1, -1, -1, -1,
-1, -1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 0.5, 0.5), L_vs_P = c(0, 0, 0, 0, 0,
0, 0, 0, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5,
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0, 0, 0, 0, 0, 0,
0, 0, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)), .Names = c("SubjN",
"Items", "IV1", "DV", "IV1.h", "N_vs_LP", "L_vs_P"), row.names = c("3099",
"3100", "3101", "3102", "3103", "3104", "3119", "3120", "3107",
"3108", "3109", "3110", "3097", "3098", "3105", "3106", "3115",
"3116", "3117", "3118", "3111", "3112", "3113", "3114", "3147",
"3148", "3149", "3150", "3151", "3152", "3167", "3168", "3155",
"3156", "3157", "3158", "3145", "3146", "3153", "3154", "3163",
"3164", "3165", "3166", "3159", "3160", "3161", "3162"), class = "data.frame")

Each subject was tested on 24 trials on 3 different conditions (factor IV1, levels: N, L, P).
I recorded whether they produced a target linguistic structure (DV == 1) or not (DV == 0).
In the analysis, I only included those subjects who produced the target structure at least one.
Nonetheless, most of them produced the target structure only on very few occasion. This is the proportion of DV == 1 produced by each subject in each condition:
library(plyr)
#dput(ddply(mydata, .(SubjN, IV1), summarise, l = length(DV), y = round(mean(DV),2)))

structure(list(SubjN = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L,
4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L,
9L, 9L, 10L, 10L, 10L, 11L, 11L, 11L, 12L, 12L, 12L, 13L, 13L,
13L, 14L, 14L, 14L, 15L, 15L, 15L, 16L, 16L, 16L, 17L, 17L, 17L,
18L, 18L, 18L, 19L, 19L, 19L, 20L, 20L, 20L, 21L, 21L, 21L, 22L,
22L, 22L, 23L, 23L, 23L, 24L, 24L, 24L, 25L, 25L, 25L, 26L, 26L,
26L, 27L, 27L, 27L, 28L, 28L, 28L, 29L, 29L, 29L, 30L, 30L, 30L,
31L, 31L, 31L, 32L, 32L, 32L, 33L, 33L, 33L, 34L, 34L, 34L, 35L,
35L, 35L, 36L, 36L, 36L, 37L, 37L, 37L, 38L, 38L, 38L, 39L, 39L,
39L, 40L, 40L, 40L, 41L, 41L, 41L, 42L, 42L, 42L, 43L, 43L, 43L,
44L, 44L, 44L, 45L, 45L, 45L, 46L, 46L, 46L, 47L, 47L, 47L, 48L,
48L, 48L, 49L, 49L, 49L, 50L, 50L, 50L, 51L, 51L, 51L, 52L, 52L,
52L, 53L, 53L, 53L, 54L, 54L, 54L, 55L, 55L, 55L, 56L, 56L, 56L,
57L, 57L, 57L, 58L, 58L, 58L, 59L, 59L, 59L, 60L, 60L, 60L, 61L,
61L, 61L, 62L, 62L, 62L, 63L, 63L, 63L, 64L, 64L, 64L, 65L, 65L,
65L, 66L, 66L, 66L, 67L, 67L, 67L, 68L, 68L, 68L, 69L, 69L, 69L,
70L, 70L, 70L, 71L, 71L, 71L, 72L, 72L, 72L, 73L, 73L, 73L, 74L,
74L, 74L, 75L, 75L, 75L, 76L, 76L, 76L, 77L, 77L, 77L, 78L, 78L,
78L, 79L, 79L, 79L, 80L, 80L, 80L, 81L, 81L, 81L, 82L, 82L, 82L,
83L, 83L, 83L, 84L, 84L, 84L, 85L, 85L, 85L, 86L, 86L, 86L, 87L,
87L, 87L, 88L, 88L, 88L), IV1 = structure(c(1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L), .Label = c("N", "L", "P"), class = "factor"), l = c(8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 8L, 7L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 8L, 8L, 8L, 8L, 8L, 8L,
7L, 8L, 6L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 8L, 8L, 7L, 7L, 8L, 7L, 8L,
8L, 7L, 8L, 8L, 7L, 8L, 8L, 7L, 8L, 8L, 7L, 8L, 8L, 7L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 6L, 8L, 4L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L,
8L, 8L, 7L, 8L, 8L, 7L, 8L, 8L, 7L, 8L, 8L, 7L, 8L, 8L, 7L, 8L,
8L, 7L, 8L, 8L, 7L, 8L, 8L, 7L, 8L, 8L, 7L, 8L, 7L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L), y = c(1, 0.88, 1, 0.5, 0.25, 0.62,
0, 0, 0.25, 0, 0.25, 0, 0.12, 0, 0, 0, 0.12, 0, 0, 0.12, 0.12,
0, 0, 0.12, 0.38, 0, 0.25, 0, 0.12, 0, 0.12, 0, 0.25, 0, 0, 0.12,
0.5, 0.25, 0.5, 0, 0, 0.12, 0, 0.25, 0.12, 0, 0, 0.12, 0, 0.12,
0, 0, 0.12, 0.12, 0.12, 0.62, 0, 0, 0.5, 0.25, 1, 0.88, 1, 0,
0, 0.12, 0, 0.12, 0.12, 0.12, 0.12, 0, 0.62, 0.62, 0.38, 0.5,
0.88, 0.12, 0.12, 0, 0, 0.12, 0.12, 0, 0, 0.12, 0, 0, 0.12, 0,
0, 0.12, 0, 0, 0.25, 0, 0, 0.14, 0, 0.5, 0.57, 0.29, 0, 0.12,
0, 0, 0.12, 0, 0.25, 0.5, 0.25, 0, 0.12, 0.12, 0.25, 0, 0.38,
0, 0, 0.12, 0, 0, 1, 0.25, 0.12, 0.25, 0, 0.12, 0.12, 0, 0, 0.12,
0, 0, 0.12, 0.12, 0, 0, 0.12, 0, 0.14, 0.14, 0.12, 0, 0.12, 0,
0, 0.12, 0.12, 0, 1, 0.88, 1, 0, 0.12, 0, 0.12, 0, 0, 0.12, 0,
0.12, 0, 0, 0.12, 0.12, 0.12, 0.12, 1, 1, 1, 0.12, 0, 0, 0.12,
0.38, 0, 0, 0.12, 0, 0, 0, 0.5, 0.5, 0, 0.25, 0, 0.12, 0.29,
0, 0, 0.38, 0, 0, 0.62, 0.5, 0, 0.12, 0, 0.12, 0.12, 0.25, 0.12,
0.25, 0.12, 0, 0.12, 0, 0, 0.12, 0, 0, 0.12, 0, 0.12, 0.12, 0,
0.12, 0.12, 0, 0, 0.12, 0.12, 0.12, 0, 0.38, 0.12, 0.57, 0, 0.12,
0, 0, 0.12, 0, 0, 0.12, 0, 0, 0.12, 0.14, 0.88, 0.88, 0.86, 0,
0, 0.14, 0, 0.12, 0.14, 0, 0.12, 0, 0, 0, 0.12, 0, 0, 0.12, 0.38,
0, 0, 0.5, 0.12, 0)), .Names = c("SubjN", "IV1", "l", "y"), row.names = c(NA,
-264L), class = "data.frame")

I run the following model including IV1 as fixed effect with helmert-contrast coding;
first contrast: N vs. L & P, second contrast: L vs. P.
m1 <- glmer(DV ~ IV1.h + (1 + IV1.h|SubjN) +  (1|Items) + (0 + N_vs_LP|Items) + (0 + L_vs_P|Items), family ='binomial', mydata)

The model does not allow for the correlation between the by-Items random variables (I did this by creating separate slopes for the two contrasts), since when correlation was allowed they were perfectly correlated (which I interpreted as a sign of over-parametrization).
1) Results using
os x 10.8.5 mountain lion
R version 3.0.2 (2013-09-25)
lme4_1.0-5
(the original analysis I run)
Generalized linear mixed model fit by maximum likelihood ['glmerMod']
 Family: binomial ( logit )
Formula: DV ~ IV1.h + (1 + N_vs_LP + L_vs_P | SubjN) + (1 | Items) + (0 + N_vs_LP | Items)     + (0 + L_vs_P | Items)
   Data: mydata

      AIC       BIC    logLik  deviance
1492.5408 1560.2050 -734.2704 1468.5408

Random effects:
 Groups  Name          Variance  Std.Dev. Corr
 SubjN    (Intercept)   2.3885505 1.54549
          N_vs_LP       0.4394195 0.66289  -0.69
          L_vs_P        1.9287559 1.38880   0.04  0.08
 Items    (Intercept)   0.0531518 0.23055
 Items.1  N_vs_LP       0.0001950 0.01396
 Items.2  L_vs_P        0.0003619 0.01902

Number of obs: 2077, groups: SubjN, 88; Items, 12

Fixed effects:
                              Estimate Std. Error z value Pr(>|z|)
(Intercept)                    -2.2998     0.1964 -11.710  < 2e-16 ***
IV1.hN_vs_L&P                   0.3704     0.1378   2.689  0.00717 **
IV1.hL_vs_P                     0.2060     0.2320   0.888  0.37459
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
              (Intr) IV1.N_
IV1.hN_vs_L&P -0.388
IV1.hL_vs_P    0.014  0.019

2) Results using:
OS X 10.9.4 Mavericks
R version 3.1.1 (2014-07-10)
lme4_1.1-7
optimizer 'bobyqa'
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation)     ['glmerMod']
 Family: binomial  ( logit )
Formula: DV ~ IV1.h + (1 + N_vs_LP + L_vs_P | SubjN) + (1 | Items) + (0 +
    N_vs_LP | Items) + (0 + L_vs_P | Items)
   Data: mydata
Control: glmerControl(optimizer = "bobyqa")

     AIC      BIC   logLik deviance df.resid
  1492.5   1560.2   -734.3   1468.5     2065

Scaled residuals:
    Min      1Q  Median      3Q     Max
-2.4174 -0.3364 -0.2595 -0.1706  4.6028

Random effects:
 Groups  Name        Variance Std.Dev. Corr
 SubjN   (Intercept) 2.38791  1.5453
         N_vs_LP     0.43935  0.6628   -0.69
         L_vs_P      1.92629  1.3879    0.04  0.07
 Items   (Intercept) 0.05319  0.2306
 Items.1 N_vs_LP     0.00000  0.0000
 Items.2 L_vs_P      0.00000  0.0000
Number of obs: 2077, groups:  SubjN, 88; Items, 12

Fixed effects:
              Estimate Std. Error z value Pr(>|z|)
(Intercept)    -2.2998     0.2095 -10.975   <2e-16 ***
IV1.hN_vs_L&P   0.3703     0.1892   1.958   0.0503 .
IV1.hL_vs_P     0.2063     0.2679   0.770   0.4413
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
            (Intr) IV1.N_
IV1.hN__L&P -0.379
IV1.hL_vs_P -0.001  0.003

I really don't know which outcome I should trust. Any help would be very much appreciated.
Ps. Sorry if something is not clear - it's my first post :)
Thanks very much!
Comment: Hi, try cross-validated if you want this answered as a technical stats question otherwise can you reduce this to a minimal example - this is wayy too much for a StackOverflow question -  see http://stackoverflow.com/help/mcve
Answer: From lme4's NEWS file, for version 1.1-4

Standard errors of fixed effects are now computed from the approximate Hessian by default (see the use.hessian argument in vcov.merMod); this gives better (correct) answers when the estimates of the random- and fixed-effect parameters are correlated (Github #47)

The description of the problem is here
You should be able to retrieve the old standard errors from the newer (1.1-7) model by sqrt(diag(vcov(fitted_model,use.hessian=FALSE))), but the new version is more likely to be correct.
For more precise confidence intervals/p values, you can do a likelihood ratio test (use anova to compare nested models) and/or compute the profile confidence intervals with confint(fitted_model,which="beta_").


Show that $q$ is prime

Question:
Let q be a positive integer such that $q \geq 2$ and such that for any
  integers $a$ and $b$, if $q|ab$ then $q|a$ or $q|b$.Show that $q$ is a prime
  number.

It will probably be proved by contradiction, so I assumed $q$ is a prime, i.e $q=xy$ where $x$ and $y$ are some positive integers and not equal to $1$ or $q$, and tried to a contradiction but I couldn't figure out how to proceed from here.
Comment: Contradiction works...if $q$ is not a prime then $q=ab$ for $1<a,b<q$.  Clearly $q$ does not divide either factor.
Comment: If $q=xy$, where $xy$ are not equal to $1$ or $q$, then isn't that a contradiction, because of course $q$  doesn't divide either $x$ or $y$? (it is larger than both of them). So if $x,y$ take the place of $a,b$ in the yellow box then you have a contradiction.
Comment: @астонвіллаолофмэллбэрг with that logic, 6 is also a prime number
Comment: But $6 = 2*3$, whereas $6 \nmid 2$ and $6 \nmid 3$! So it does not hold true that for every pair of numbers $a,b$, $6 |ab$ implies $6|a$ or $6|b$. Let us sort out this confusion quickly.
Answer: It is correct that this can be proven via contradiction. If $q$ is not a prime, then we can find two integers $x, y > 1$ such that $q = xy$. But this means $q|xy$, so by our assumption we have $q|x$ or $q|y$. But neither of these can be true, since $x = \frac{q}{y} < q$ by the assumption $y > 1$ resp. $y = \frac{q}{x} < q$ by the assumption $x > 1$.
Comment: I did not understand why they can not be true quietly ?
Comment: I don't understand what you are trying to say.
Comment: :D "But neither of these can be true, since x=py1
y
>
1
 resp. y=px1
x
>
1
." What do you mean by that ?
Comment: We have $x > 1$, so this means $y = \frac{q}{x} < q$. But this implies that $q$ does not divide $y$, since a divisor of a positive integer can't be greater than the integer itself.
Comment: I'm sorry I guess my brain is stuck, but if $x > 1$, then y < q, so I still can't  see the point.
Comment: $y < q$ implies that $q$ is not a divisor of $y$. Similarly, $q$ is also not a divisor of $x$. This is a contradiction to the assumption that $q|x$ or $q|y$ must hold.
Comment: yes, but it also holds for $6=2*3$ ?
Comment: And $6$ is also not a prime number. Please take your time to think precisely about the proof before you post further comments.
Comment: After a good sleep, I got it :)
Answer: Suppose $q$ is composite. Then you can write $q=nk$ for some $n,k\geq2$. Clearly $q|nk$ as every natural number divides itself, which implies by hypothesis that $q|n$ or $q|k$. In particular $q\leq n$ or $q\leq k$ which is a contradiction.
Comment: what do you mean by "composite" ?
Comment: ["Composite"](https://en.m.wikipedia.org/wiki/Composite_number) means "not a prime number nor $1$".

Show that $q$ is prime


setting the length of an array's string element to a variable in a for loop in javascript

Question: I have this code. and for some reason i get the error: Uncaught TypeError: Cannot read property 'length' of undefined. I can't seem to figure out why.

function findShort(s) {

  var c = s.split(' ');
  var l = c[0].length;
  var wordlength;

  for (var i = 1; c.length; i++) {
    console.log(c[i].length);

    wordlength = c[i].length;
    if (l < wordlength) {
      l = wordlength;

    }
  }
  return l;

}

console.log(findShort("hello dog cat 12 asdsad wuidhuiwqhd"));

the error is with the line wordlength = c[i].length;
When i console.log it, it shows the length of each string in the array. However, when i try to store that length it says it's undefined.
Comment: You have an infinite loop, since `c.length` doesn't change during the loop. So you keep going past the end of the array.
Comment: doh! i can't believe i didn't notice that. thank you so much
Comment: `console.log(Math.min.apply(null, 'the quick brown fox jumped'.split(' ').map(w=>w.length))); // outputs "3"`
Comment: whoa. way better solution. I will have to learn more about arrow functions and mapping. thank you!
Answer: You need to change this line
for ( var i = 1; c.length; i++ ) {

to
for ( var i = 1; i<c.length; i++ ) {

The second componenet of a for loop is a boolean condition that is checked for every round of the loop to determine if the loop should continue or not. By putting c.length, you are giving a constant value which will make the loop to either never run (if c.length is 0), or to run forever (if c.length not 0).
You should also be careful with the following line:
var l = c[0].length;

It might cause a problem too as it is not guaranteed that c will have at least one element.
Comment: I am a moron. Didn't notice that and i poured over the code 100 times. thank you very much


Causation doesn't imply correlation and correlation does not imply causation

Question: Let P := |corr($X,Y$) > .5|
let Q := exits a relation F:$X\implies Y$
Then the often stated line of correlation does not imply causation is simply !($P \implies Q$).
It is also true that causation does not imply correlation. So !($Q \implies P$)
But $(P\implies Q) \lor (Q\implies P)$ is a tautology.
I know I am not seeing clearly, but I don't see it.
Sorry if this is answered, I didn't see and also sorry if this is too simplistic. I just don't get where my thinking is off.
Thanks
Comment: If two events have a causal relationship, they are necessarily correlated. Where have you seen otherwise? Correlation does not imply causation is a true statement, but causation always implies correlation.
Comment: There are tons of examples of nonlinear causal relationships that have near zero correlation. Feel free to google or ill post specific examples if necessary.
Comment: I should add that I specifically mean linear correlation.     https://en.m.wikipedia.org/wiki/Correlation_and_dependence
Comment: @InterstellarProbe: Causation does imply mutual information, but not correlation.
Answer: Your $P$ and $Q$ are not propositions; they  are predicates.  That is, the truth value of $P$ varies depending on $X$ and $Y$.
The correct translation of "Correlation does not imply causation" is not $!(P\rightarrow Q)$.  Instead it is
$$!((\forall X,Y)( P(X,Y)\rightarrow Q(X,Y))$$
Given this, you'll find that you can't formulate your paradox.
Note, incidentally, that the key issue here has nothing to do with correlation and causation.  You could take statement "P" to be "Chris is a women" and "Q" to be "Chris is a parent".  If we allow for the fact that there are many people named Chris in the world, these statements are predicates with truth values that depend on which Chris you're talking about.
Now it is not true that "All women are parents" and it is not true that "All parents are women", so if your logic were correct, you could apply it here equally well and get the same paradox without ever mentioning causation  or correlation.  The resolution remains the same.
Comment: I realized there was quantification happening, and I should have written it all out. But in my head I was using the existential quantifier rather than the universal.

In my head I was having the following conversation:
It is true that for some sets, X and Y  correlation doesn't imply causation and causation doesn't imply correlation.

But When we casually say, "correlation does not imply causation", we really mean that with the universal quantifier.

Thanks for helping to think though this Asura Path.
Comment: @JeremyBall : It sounds like you're on top of this now, so you probably don't need this further explanation but:  "All women are parents" is identical in meaning to "If Chris is a woman then Chris  is a parent" --- one thing to keep in mind if you want to formalize all this.


Complex analysis residue calculus

Question: Would you know how to calculate:
$\int_{0}^{\pi} \frac{1}{6+\sin^2(z)} dz$?
Thanks.
Comment: It seems like you know what to try. Just give it your best attempt. My personal opinion is that I don't like self defeatest attitudes like "I am lost." It means you don't give your intelligence enough credit - you are not lazy so don't act that way. What makes a pole? How can you set an equation to find where the poles are? Try writing these up and editing your post, I will not downvote it.
Comment: What have you tried? Do you want to do it an easier way that doesn't require complex analysis?
Comment: Maybe find out poles?
Comment: I don't know what to try. I am lost.
Answer: An hint:
Write $\sin z= \frac 1 2 (w-\frac{1}{w})$ and note that:
$$2\int_{0}^{\pi} \frac{1}{6+\sin^2(z)} dz=\int_{0}^{2\pi} \frac{1}{6+\sin^2(z)} dz=\int_{\gamma}\frac{1}{6+(\frac 1 2 (w-\frac{1}{w}))^2}\frac{1}{iw}dw$$
where $\gamma(t)=e^{it}$ for $t \in [0,2\pi]$.
Use finally the Residue Theorem to compute the last one.
Comment: Why is there equation, with $\pi$ and $\2pi$? :)
Comment: @lida I edited the question. That equation holds because $\sin^2(z+\pi)=(-\sin(z))^2=\sin^2z$ thus $\int_{0}^{\pi} \frac{1}{6+\sin^2(z)} dz=\int_{\pi}^{2\pi} \frac{1}{6+\sin^2(z)} dz$
Comment: Ok. I tried to do one fraction of it and find out poles, but there are terrible numbers.
Comment: In denominator there is: $z^4 - 26z^2+1$
Comment: If I want to find poles, it is very complicated.
Comment: Can I ask how to use the Residue Theorem to compute the last one? :)

Complex analysis residue calculus


Duvida sobre CSS em herança

Question:
A configuração do Pai 'li' não esta sendo herdada pelos filhos 'li#foto01' e 'li#foto02' não entendo porque
Comment: Coloque também o código do html para podermos ver.
Answer: Quando você define a propriedade background, na verdade você está definindo uma lista de propriedades com os seguintes valores padrões:

background-image: none
background-position: 0% 0%
background-size: auto auto
background-repeat: repeat
background-origin: padding-box
background-clip: border-box
background-attachment: scroll
background-color: transparent

Então você sobrescreve o valor de background-position
Para corrigir isso você pode:

Inverter a ordem (colocar o estilo ul#album-fotos li depois)
Colocar o !important depois da propriedade background-position (método não recomendado)
Trcar background por background-image e background-repeat

Duvida sobre CSS em herança


Speed of Tampura app during Bansuri practice

Question: I understand Tampura app (I use Tampura droid) must be on during Bansuri practice so player learns to tell (by ear) whether they are in tune.
Since I have A-Scale Bansuri the Tampura is on A-Scale and note PA (from Sa RecGa Ma PA DHA NI SA)
But what 'speed' to keep it. By default the slider is in the middle. When do I speed up the Tampura? When do I slow down the Tampura?
Answer: It is up to you to use which speed to use. I prefer it a bit slow (slider at about 1/4th position) so that I can hear all the four notes separately. Also before start practicing just keep listening to the tanpur will help you get adjust to it


Autocorrelated residuals is a problem for a within-subjects ANOVA?

Question: When participants arrived at the lab, I showed them curriculum vitae with different profile pictures and different types of university information. After viewing each curriculum, I asked participants to rate the competence of the person from 1 to 7.
So I have a within-subjects design with a Likert scale dependent variable and two categorical predictors (3 levels each). I am considering running a repeated measures ANOVA, but I am still checking the assumptions. Are autocorrelated residuals a problem?
Answer: Yes they are. RM ANOVA assumes sphericity, which means that the variances of the differences are equal across time. If there is autocorrelation, then they won't be. Assuming that the autocorrelation is positive, the variances will be smaller between time 1 and 3 then between time 1 and 2 or 2 and 3.
I suggest using a multilevel model, which does not assume this.
Comment: Note that a multilevel model that only has random intercepts also assumes sphericity.  RM ANOVA is a step worse as many practitioners don't do the needed sphericity correlation-adjustment.


When is it time to switch to NoSQL?

Question: I am dealing with a large database that is collecting historical pricing data.  The schema is relatively simple and does not change.
Something like:
SKU (char), type(enum), price(double), datetime(datetime)
The issue is that this table now has over 500,000,000 rows and is around 20gb and growing.  It is already getting a bit difficult to run queries.  One common query is to get all skus from a specific date range consisting of maybe 500,000 records.  Add any complexity like group by, and you can forget it.
This db is mostly writes.  But we obviously need to crunch the data and run queries occasionally.  I understand that better index planning can help speed up the queries, but I am wondering if this is the type of data that would benefit from a noSQL solution like MongoDB?  Can I expect mysql (probably moving to MariaDB) to continue to work for us, even after it grows beyond 100-200 gb in size? Or should I explore alternatives before things get unweildly?
Answer: NoSQL is not a solution to a "large database" problem; NoSQL--specifically document databases--are designed for scenarios where the nature of the data you're storing varies, so you don't want to define rigid schemas and relationships up front.
What you have is simple, well-defined data. This is ideally suited for a relational database, but for something of that scale I would recommend looking something either commercial (i.e. SQL Server or Oracle, depending on your platform). The databases I work with in SQL Server are around four terabytes in size with several tables in the hundreds-of-millions records like you have. A relational database can easily accommodate the simple data you've outlined.
Answer: You actually have an ideal use-case for SQL, and a rather bad fit for NoSQL. MySQL devs report people using databases of 5,000,000,000 records. Some other SQL servers will be even more scalable than that. However, if you don't have a proper index support, it should be impossible to manage even a fraction of that.
BTW, what is your table schema, including indices?
Comment: Innodb - id (int,primary), SKU (char), type(enum), price(double), datetime(datetime), also, since I need to be able to sort or run queries based on any of those fields, I have recently created a single index on each one.  Previously it was just id and sku.
Comment: Each query can only use only one index per table; so if you have a WHERE and a GROUP BY, it is very likely your indices do not cover everything; you most likely will need a composite index or three. Can't say more without seeing the exact query.
Answer: You could switch to mariadb and then use the spider engine. The spider engine makes it possible to split your data across multiple mariadb instances without loosing the abillity to run queries against your existing instance.
So you can define your own rules for partitioning and then create one instance per partition. So in the end you have multiple instances of mariadb but all your records are virtual sumed up in one table with the spider engine.
Your performace gain would be because you split your data across multiple instances and therefore reduce the amount of records per table or instance and of course by using more hardware ressources.

When is it time to switch to NoSQL?


Wpf Custom Popup control and application theming: Resources not found

Question: I have an app where I set a theme (ResourceDictionary) on the main Window. Then all children "inherits" styles, themes etc. via the DynamicResourceExtension. This works.
However, i have a custom Popup control to handle long press animation on buttons:
class LongPressAnimationControl : Popup
{
    static LongPressAnimationControl()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(LongPressAnimationControl),
            new FrameworkPropertyMetadata(typeof(LongPressAnimationControl)));
    }
    /* Various DP's, events, properties, methods ETC. */
}

with a default style in Generic.xaml:

This works. the properties change to the ones set in the style.
However, i would like the popup to use a style defined in the Theme.xaml so the properties etc. can be themed.
If i move the style to my Theme.xaml, then the style is not picked up (properties does not change).
I've also tried to add a key to the Style, and a resource reference in code, like so:
public LongPressAnimationControl()
{
    SetResourceReference(StyleProperty, "LongPressAnimationControlStyle");
    //....
}

Anyone with an idea of how to solve this?
Comment: That's great i have update this as answer, so i might be useful for some else.
Comment: Your Theame.xaml include in app resources?
Comment: Moved the Theme.xaml from the Main Window Resources to the App.xaml Resources and now it works.. Thank you @Firoz.
Answer: You should include Theme.xaml in App.xaml resource, so WPF can find the resource.


Are differences in sexual orientation statistically significant?

Question: please be kind its been a long time since I have done any statistics!
I have some sexual orientation data for three teams, which are are very different sizes from Organisation (A) to Directorate (B) and a smallish Team (C).
My null hypothesis is that the three sets of data are not statistically different.
There are obviously differences in the data but I would like to determine if these are statistically significant when the team sizes are taken into consideration?
Could you please explain to me what the best tool would be to do this?
Thank you
Andy
Comment: In that case, this seems like a good candidate for the chi-squared test. (I would use something called the G-test, but the theory involves more sophisticated statistical notions like likelihood, and the results will be similar to results produced by a chi-squared test.)
Comment: Are the smaller teams subsets of the larger ones, meaning that the same person appears more than once in the table? Also, it is important how the teams were formed, as if this is at least partly personal choice and some involved people know each other, and this has an influence on to what team they belong, the independence assumption required for the chi-squared test (as well as the G-test) is in doubt.
Comment: I like it because of how it can be extended to include covariates and experimental design, much like ANOVA can be extended to larger regression models.
Comment: Do you mean that you want to test if the A, B, and C groups have the same distributions of the seven orientations in your chart? // Your chart says that the subjects form a population, not a sample. If you have the population, there is no notion of hypothesis testing. Do you have a sample, or are you just interested in the 6,493 people you observed?
Comment: Too lazy to do the test but looks like they're not. Definitely not close to a $10^{-10}$ p-value
Comment: Hmm I think so!  for example for the first orientation listed Team C appear to have a higher incidence compared to A + B.  Is it genuinely different or is the apparent difference related to the small population size?  I'm sorry if that doesn't clarify things!
Comment: Thanks Dave much appreciated!
Comment: @Dave I had not seen the G-test before. I like the property of its proportionality to the Kullbach-Leibler divergence; very nice.
Comment: @Lewian Good point - yes the smaller teams are also included in the larger numbers, i guess I could subtract these each from the larger teams.  The teams are depts in a real organisation - to my knowledge staff didn't choose a team to work in based upon the factors being examined.
Answer: From the discussion, I assume that B and C are disjoint.
To the extent that B and C can be taken as samples from
larger populations, it seems reasonable to do a chi-squared
test on B and C.
With some rearrangements of response categories, I put all of your data into contingency table TBL.
a = c(3361, 28, 21, 41,  9, 67, 1448)
b = c(1101,  9, 10, 12,  6, 21,  435)
c = c(  84,  3,  1,  0,  1,  3,   29)
TBL = rbind(a,b,c);  TBL

TBL = rbind(a,b,c);  TBL
  [,1] [,2] [,3] [,4] [,5] [,6] [,7]
a 3361   28   21   41    9   67 1448
b 1101    9   10   12    6   21  435
c   84    3    1    0    1    3   29

Restricting attention to B and C, we have
TABbc = TBL[c(2,3),];  TABbc
  [,1] [,2] [,3] [,4] [,5] [,6] [,7]
b 1101    9   10   12    6   21  435
c   84    3    1    0    1    3   29

A standard chi-squared test runs into difficulties
because of the small counts.
chisq.test(TABbc)

        Pearson's Chi-squared test

data:  TABbc
X-squared = 8.9769, df = 6, p-value = 0.1749

Warning message:
In chisq.test(TABbc) :
 Chi-squared approximation may be incorrect

As implemented in R, it is possible to simulate a more
useful P-value, which does not reject the null hypothesis
that proportions in the various response categories are equal.
chisq.test(TABbc, sim=T)

        Pearson's Chi-squared test
        with simulated p-value
        (based on 2000 replicates)

data:  TABbc
X-squared = 8.9769, df = NA, p-value = 0.1689

A more traditional approach is to collapse the table to get
fewer cells with larger counts.
The reason for the warning message is that several of the
expected counts (computed from row and column totals, assuming
the null hypothesis to be true) are smaller than $5,$ so
that the chi-sqared statistic may not have approximately
a chi-squared distribution.  Expected counts are as follows;
it is small counts in columns 2-6 that are causing most of the trouble.
hisq.test(TABbc)$exp
        [,1]       [,2]       [,3]       [,4]      [,5]      [,6]      [,7]
b 1101.39359 11.1533528 10.2239067 11.1533528 6.5061224 22.306706 431.26297
c   83.60641  0.8466472  0.7760933  0.8466472 0.4938776  1.693294  32.73703
Warning message:
 In chisq.test(TABbc) : Chi-squared approximation may be incorrect

c1 = c(  84,  3+  1+  0+  1,  3,   29)
TBL1 = cbind(a1,b1,c1)
TBL1
       a1   b1 c1
[1,] 3361 1101 84
[2,]   99   37  5
[3,]   67   21  3
[4,] 1448  435 29

chisq.test(TBL1[c(2,3),])

        Pearson's Chi-squared test

data:  TBL1[c(2, 3), ]
X-squared = 0.32154, df = 2, p-value = 0.8515

Warning message:
In chisq.test(TBL1[c(2, 3), ]) :
 Chi-squared approximation may be incorrect

We still get a warning message, but this time only one of the
expected counts is below $5,$ but not below $3.$ which many
statisticians would find good enough.
chisq.test(TBL1[c(2,3),])$exp
            a1    b1       c1
[1,] 100.88793 35.25 4.862069
[2,]  65.11207 22.75 3.137931
Warning message:
In chisq.test(TBL1[c(2, 3), ]) :
 Chi-squared approximation may be incorrect

The bottom line is that we find no significant differences between
responses of groups A and B.


How to pass JSON object to PHP

Question: I have the following code snippet below.  When the "Create Order" button is clicked, the user inputted data (not shown in the code) is converted to JSON, via the function "convertToJson".  I am able to convert the data to JSON.  My problem is passing the JSON object to PHP so that I can insert the object to the database.  PHP is returning a "Null" value when I run $var_dump.
Note that I am trying to POST to the same page, which is "orders.php"
<code>     <head>
        <script type="text/javascript">
        function convertToJson()
        {
            var tableData = $('#productOrder').tableToJSON({
            ignoreColumns: [0]
            });

            var xhr = new XMLHttpRequest();
            xhr.open("GET","orders.php",true);
            xhr.setRequestHeader("Content-Type", "application/json");
            xhr.send(JSON.stringify(tableData));
        }
        </script>
     </head>
    ...more code...

    <button type="button" class="btn btn-success btn-md" style="float: right;" onclick="convertToJson();">Create Order</button>
    <div>
    <?php
        $data = json_decode(file_get_contents('php://input'));
        var_dump($data);

    ?>
    </div>
</code>
Comment: Check if the request gets sent.
Answer: you should use an actual ajax request to do post your data
<code>        $.ajax({
            url: 'yourscript',
            type: 'POST',
            data: { data: tableData }
            dataType: "json",
            beforeSend: function() {
              //do something
            }
        }).done(function(msg){
            //do something when done
        }).fail(function(msg){
            //error handling
        }).complete(function(msg){
            //do something when completed
        });

    }
</code>
and get the data with $_POST["data"]
also note that as stated before you need to take care of your script lifecycle as you are now working with async requests
Comment: is it possible to post to the same page?
Comment: @wowomg No, posting to the same page results in [this](http://stackoverflow.com/questions/17973386/ajax-request-callback-using-jquery/17974843#17974843)
Comment: sure you can post to the same script. you have to read the data ofcourse and do something with it. note the code sequence tho. My Recommendation however is to seperate the Code from the View completely and also handle the ajax reqiest in an explicit controller function
Comment: @SteVoi How does one post AJAX request to the same page that contains the ajax code block? I am aware it can be done, but not without some significant challenges that are well beyond the abilities of most novices. Specifying a secondary, independent, PHP page in the `url: "secondary_page.php",` parameter of the ajax code block is by far the easiest way for the OP to solve his problem, and is the way 90% of coders would solve it. Why would you remark that it can be done without pointing out the significant inherent difficulties with that approach?
Comment: @gibberish: just handle the ajax call on top of the script. again i do not recommend doing this but if you would like to its abolutely possible: if(ajax_data) { do somehting } Rest of the script. the proper way is to route the ajax call do a dedicated function, return the reply and handle the reply using JS in the actual script. Basically just like you recommended
Comment: @SteVoi Please have a look at [this post](http://stackoverflow.com/questions/17529509/values-not-updated-after-an-ajax-response/17530014#17530014), and even reproduce in a test environment at your location  (too bad jsFiddle doesn't handle AJAX - grrrr). It *is* possible to post to the same page using AJAX, but coded backflips are necessary -- the linked post is the usual result. It's one of these things that is good to see for yourself.

How to pass JSON object to PHP


my module template_preprocess is not called

Question: I can't figure out how to correctly implement the theme mechanism in my module. The hook just doesn't get called, after flushing registry ofc.
My mymodule.module contains a function (this function gets called, no problem, I give it just for illustration):
function mymodule_node_view($node, $view_mode) {
  ...
  $node->content['mymodule_tocteasers'] = array(
    '#markup' => theme('tocteasers', array('tocteasers' =>  "whatever")),
  );
}

As I understand the theme mechanism, in order to render tocteasers hook, the module should implement it. Here is my module's implementation, which is not called at all, ever:
function template_preprocess_tocteasers(&$variables) {
  $variables['content'] = "something!!!";
  dsm($variables); print "hello";
}

^^I also tried function mymodule_preprocess_tocteasers(&$variables) without success
In addition, I have a file named tocteasers.tpl.php in my module directory, containing:

  <?php print "!!"; ?>
  <?php print $content; ?>

This also does not get printed or called.
Can someone plese advise me, how to make this implementation so that the tocteasers.tpl.php file is used and gets the $content variable as intended?
Comment: Can you show the code for your `hook_theme()` implementation?
Comment: I didn't implement it! (it's the first time I use this kind of theme in a module) Now all is working after implementing hook_theme. Thanks and please make an answer so I can accept.
Comment: No problem...I think @kiamlaluno has it pretty much covered though, I'd accept that one if I were you :)
Answer: What you don't report in your question is the hook_theme() implementation, which is necessary for Drupal to know the theme functions a module implements. In your case, the array returned from hook_theme() should be something similar to the following (supposing that your module defines just a theme function).
  return array(
    'tocteasers' => array(
      'variables' => array('content' => 'the default value'),
      'template' => 'tocteasers',

      // Use it only if the template is not in the same directory the module is located.
      // This path should be relative to the Drupal root directory.
      'path' => 'the directory where the template file is located',
    )
  );

Notice that:

You call the theme function with theme('tocteasers', array('tocteasers' =>  "whatever")), but the template file is not using $tocteasers.
The template filename must be the same used for the theme name; in your case as the theme function is tocteasers, the reported template filename must be "tocteasers". The extension ".tpl.php" is not used, as it is automatically added by Drupal when it looks for the template file. The only allowed difference between the theme name and the template filename is that the template filename can use "-" where the theme name uses underscores. This is because the "-" character is not allowed in a theme name, which must use the same characters used in a PHP function name. (This means it cannot start with a number, for example.)
If you are altering the code of an existing, enabled module, Drupal caches the data returned from hook_theme(); the result is that you had a theme function that was not using a template file, and that has been modified to use it, Drupal will not use the template file because it still referring to the old definition. hook_theme() is called in some specific cases, such as when a module is disabled, enabled, or updated. To force Drupal to update its cached data, you should disable and re-enable the module from the administration interface.
dsm($variables) could not show anything, if it is called too late, i.e. when the messages set with drupal_set_message() (the function used from dsm()) are already rendered. For those type of debug messages it's better to use watchdog(), which saves the message in a database table. Drupal allows to see those messages in admin/reports/dblog, and defines WATCHDOG_DEBUG for this very purpose.
Both template_preprocess_tocteasers() and hook_preprocess_tocteasers() are used, the difference is that template_preprocess_tocteasers() is defined from the module implementing the theme function, and it is called before hook_preprocess_tocteasers(). The purpose of the preprocess functions is not printing anything, but altering the variables passed to the template file, or the theme function. As consequence, the following code doesn't work as expected (i.e. "hello" is not in the output of the theme function).
function template_preprocess_tocteasers(&$variables) {
  $variables['content'] = "something!!!";
  print "hello";
}

Comment: THanks for detailed answer and interesting point is about the hook_theme caching, that's probably why it is necessary to flush all caches in order to make Drupal notice it. Flushing only theme registry is not enough from my observations.
Comment: When you disable, and enable a module, Drupal clears many of the caches it uses, not just the theme registry cache. Actually, the function called by [system_modules_submit()](http://api.drupal.org/api/drupal/modules%21system%21system.admin.inc/function/system_modules_submit/7) is [drupal_flush_all_caches()](http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_flush_all_caches/7)
Answer: Definitely hook_theme() should be implemented by your module instead of the preprocess.
To use preprocess_tocteasers(), you would have to call it yourself in hook_preprocess().
Comment: `hook_theme()` needs to be implemented in any cases, not instead of the preprocess function. The preprocess function could still be used, even if `hook_theme()` is implemented; one doesn't exclude the other.


Which two would be an example of non-equivalent metrics on $\mathbb{R}$.

Question: Additionally, it's required that neither of them induces the discrete topology.
Comment: what all metrics do you know on $\mathbb{R}$?
Answer: The following metric is not topologically equivalent to the standard Euclidean metric:
$$d ( x , y ) = \begin{cases}
\min \{ | x - y |,1\}, &\text{if }x,y\text{ are either both rational or both irrational} \\
1, &\text{otherwise}
\end{cases}$$
(The underlying idea can be used to generate lots of inequivalent metrics on $\mathbb{R}$.)
Comment: Thank you, that was an interesting example.


Different definitions for the complex inner product.

Question: I have asked this question on P.S.E. and have gotten some nice answers, but I felt I might get even more satisfactory answers if I post it here.
"I have just now noticed that Griffiths (in his book Introduction to Quantum Mechanics) defines the complex inner product as $\big<z,w\big>=\sum_{i=1}^n\overline{z}_iw_i$. In all mathematics books (I study math and physics) I have ever come across, it is defined as $\big<z,w\big>=\sum_{i=1}^nz_i\overline{w}_i$. Maybe there is an answer to this question, maybe there isn't, but why on earth is this defined differently in physics than in math?"
https://physics.stackexchange.com/questions/215783/why-does-griffiths-define-the-complex-inner-product-differently
I'll be glad to see someone make the case for mathematics, and let me know if the question shouldn't be asked here.
Comment: Because we physicists like to keep our vectors in the same order when we convert to matrix expressions: $$\langle v, w \rangle = [v]^\dagger [w] = \pmatrix{v_1^* & \cdots & v_n^*}\pmatrix{w_1 \\ \vdots \\ w_n}$$ and mathematicians don't (presumably just to make it harder on themselves :p).
Answer: It was von Neumann who was the first to axiomatically define the inner product as a pairing in the manner it is done today. So he set the standard. Interestingly, von Neumann was the one who coined the term Hilbert Space, and effectively tied Hilbert's name to this abstract development, instead of his own (von Neumann was Hilbert's assistant during that time.) Von Neumann then developed the abstract theory of normal and Hermitian operators in a series of 3 papers from 1929-1932 which remain, in substance, the basis of modern accounts. Dirac introduced bra-ket in 1939.
Comment: @littleO : There was a lot going on those years, and a lot of credit to go around. Dirac and Schrodinger were brilliant; they did the Physics.
Comment: @littleO : There are a couple of brilliant early examples that come to mind in Quantum that are way beyond any Math-only development, such as where Schrodinger first introduced operator formalism to solve the Quantum Harmonic Oscillator problem, and diagonalize the Fourier transform. And, where Dirac's operator methods were used to explain strange particle tracks through the existence of anti-matter.
Comment: So was it Von Neumann who came up with the idea that for every observable quantity there is a corresponding self-adjoint linear operator, and the eigenvalues of this operator are the possible values for that observable quantity? And to get the probability of observing any particular eigenvalue, you take the state of your physical system and write it as a linear combination of the eigenvectors for the relevant self-adjoint operator; the squares of the magnitudes of the coefficients in that expansion are interpreted as probabilities. Was that all Von Neumann's idea? What a genius.
Answer: It is just a convention.
@Bye_World's explanation is a good justification of the physicists point of view.
We mathematicians probably just thought "We want it to be complex linear in one slot, and complex antilinear in the other slot.  Might as well make the first one complex linear."


Is the sum of cubic Bezier curve segment arc lengths the arc length of the whole spline?

Question: I have created a spline made of several cubic Bezier curve segments. I have been able to calculate the arc length of each of these cubic segments. I would like to know in the sum of all the individual arc lengths would give the arc of the whole spline. If not, how can I calculate the arc length of the spline?
Answer: A spline is simply the concatenation of its constituent segments, so its total length is naturally the sum of the lengths of its segments. Your intuition is correct.