Showing $trace\left(\sum_{i=1}^j u_i u_i^T D\right) \leq \sum_{i=1}^j \lambda_i$, where $u_i$ orthonormal & $D$ a diag. matrix w/ $\lambda_i$ entries?

Question: Suppose $\{u_i:1 \leq i \leq j\}$ are a set of orthonormal vectors,  and $D$ is a diagonal marix such that $D = diag(\lambda_1, \ldots, \lambda_p)$, arranged so that $\lambda_1 \geq \lambda_2 \geq \cdots \geq \lambda_p >0$. Then, I would like to show that:
$$
trace\left(\sum_{i=1}^j u_i u_i^T D\right) \leq \sum_{i=1}^j \lambda_i
$$
My approach is to do the following:
\begin{align*}
trace\left(\sum_{i=1}^j u_i u_i^T D\right) &= \sum_{i=1}^j \sum_{l=1}^p u_{il}^2 \lambda_l \\
&= \sum_{l=1}^p u_{1l}^2 \lambda_l + \sum_{l=1}^p u_{2l}^2 \lambda_l + \ldots + \sum_{l=1}^p u_{jl}^2 \lambda_l \\
& \leq \lambda_1 + \ldots + \lambda_j
\end{align*}
However, I cannot figure out how the last step follows. I understand we have that:
$$
\sum_{l=1}^p u_{1l}^2 = \sum_{l=1}^p u_{2l}^2 = \ldots = \sum_{l=1}^p u_{jl}^2 = 1
$$
But I don't see how this allows us to get the last inequality. In particular, it seems that we are just concentrating all the weighting to $u_{11}^2 = u_{22}^2 = \ldots = u_{jj}^2 = 1$ for each term.
Finally, if the last inequality holds, would it hold for any arbitrary reordering of the indices?
Comment: In order for this to be true, we need an assumption such as $\lambda_1 \geq \lambda_2 \geq \cdots \geq \lambda_p$
Comment: Thanks, I have changed it!
Comment: We can obtain the result using the [Von Neumann trace inequality](https://en.wikipedia.org/wiki/Trace_inequalities#Von_Neumann.27s_trace_inequality), but perhaps that's a bit much
Comment: Indeed, that last step is the tricky bit.  I agree that it is not clear, a priori, that we should concentrate the weights as you describe.  Some tricky optimization needs to be done at some point.  To me, this problem has the flavor of the Eckhart Young theorem.
Comment: We can also get a proof using the [Weyl matrix inequality](https://en.wikipedia.org/wiki/Weyl%27s_inequality#Weyl.27s_inequality_in_matrix_theory)
Comment: Let me know if you're interested in seeing either of those proofs. You haven't given much context, so I don't know how much matrix analysis I'm allowed to assume.
Comment: Thanks for your responses, am I right to say that there are two constraints going on? The first being the decreasing order of the $\lambda_i$'s, and the second being that the sets of vectors $u_{1l}^2, u_{2l}^2, \ldots,  u_{jl}^2$ (when $l$ is taken from $1$ to $p$ for each and put in a row vector) must all be orthonormal to each other? I am pretty familiar with matrix analysis and would be interested in seeing either proof, thank you so much!!
Comment: I wouldn't consider the decreasing order of $\lambda_i$s a constraint in the usual sense, but I agree with the second bit.
Answer: Let $x_i = u_{1,i}^2 + u_{2,i}^2 + \cdots + u_{j, i}^2$ for $1 \leq i \leq p$. Exactly we want to find the maximum value of
$$
x_1\lambda_1 + x_2\lambda_2 + \cdots + x_p\lambda_p \tag{$\bigstar$}
$$
There are at least two constraints for $x_i$s, namely,
$$
x_1 + x_2 + \cdots + x_p = j \tag{$\spadesuit$}
$$
and
$$
0 \leq x_i \leq 1 \text{ for } 1 \leq i \leq p \tag{$\clubsuit$}
$$
With only constraints $(\spadesuit)$ and $(\clubsuit)$, along with the fact that $\lambda_1 \geq \lambda_2 \geq \cdots \geq \lambda_p > 0$, $(\bigstar)$ attains its maximum value when $x_1 = x_2 = \cdots = x_j = 1$ and $x_{j+1} = x_{j+2} = \cdots = x_p = 0$. That is, the maximum value of $(\bigstar)$ under $(\spadesuit)$ and $(\clubsuit)$ is $\lambda_1 + \lambda_2 + \cdots + \lambda_j$. Because we obtain this value under weaker constraints than that of the original problem, the value $\lambda_1 + \lambda_2 + \cdots + \lambda_j$ is also an upper bound for the original problem.
Comment: Fantastic! A very interesting approach.
Answer: Here's a quick approach: let $U$ be the matrix whose columns are $u_1,\dots,u_j$. Notably, we have
$$
\sum_{i=1}^j u_iu_i^TD = (UU^TD)
$$
And we note that $UU^T$ is a $p \times p$ orthogonal projection matrix, which is to say that it is orthogonally similar to
$$
\pmatrix{I_j & 0\\0& 0}
$$
Both $UU^T$ and $D$ are positive definite, so their eigenvalues are also their singular values.  In particular, $\sigma_i(D) = \lambda_i(D)$, $\sigma_i(UU^T) = 1$ for $i \leq j$ and $\sigma_i(UU^T) = 0$ for $i > j$. Applying the Von Neumann matrix inequality, we have
$$
trace\left(\sum_{i=1}^j u_i u_i^T D\right) =
trace([UU^T]D) \leq \sum_{i=1}^p \sigma_i(UU^T)\sigma_i(D) = \sum_{i=1}^j \lambda_i
$$


Git keeps showing file to be committed

Question: Git keeps telling me that a file needs to be committed:
D:\ecs [master +0 ~1 -0]> git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   core/src/main/resources/templates/html/core/ContentStoreView.ftl
#

I don't see a change to that file:
D:\ecs [master +0 ~1 -0]> git diff core/src/main/resources/templates/html/core/ContentStoreView.ftl

I tried committing:
git commit -m "commiting you" .

I get
# On branch master
nothing to commit, working directory clean

As well as checking out:
D:\ecs [master +0 ~1 -0]> git checkout core/src/main/resources/templates/html/core/ContentStoreView.ftl

What's wrong with this file and how can I fix it? (I'm using git version 1.8.0.msysgit.0 on windows)
UPDATE: The problem disappeared after doing a commit from Netbeans IDE. This is of course not a generic solution and doesn't help me undertand what the problem was.
Comment: What are your newline settings?
Comment: did the git server time sync with your workstation ?
Comment: Have you tried checking what's in the staging area (`git status`), then `git commit -m ` [note the lack of period `.`]? The file that's changed isn't in the current directory, and I'm *fairly* sure that `git commit .` will only commit the changes from current directory.
Comment: @simont I did also try with the full path, but . ususally works and does commit thing in subdir.
Answer: git diff --staged (or git diff --cached) will show you the modifications that have been staged but not committed.

Git keeps showing file to be committed


What is the correct hand position for this chord?

Question: I'm a beginner (2 months playing, no teachers so far), and I'm trying to learn how to play Sonic the Hedgehog - Green Hill Zone's piano sheet. However, I cannot figure out how to position my hand for the chord presented in Figure 1 below.

Figure 1 - Chord in question, C, G, B.
The C is two octaves down (I think), and I can't figure out how to play it. Thanks for the help.
Source:Full music Sheet
Answer: The only way this is playable with two hands is to 'catch' the G and B from the bar before with the sostenuto pedal That's the middle one of three. Assuming that isn't a practice pedal, like it is on lots of pianos.
The sostenuto pedal is designed so that it works like a sustain (damper) pedal, but only holds the notes that were actually played as it is pressed. If you use the sustain pedal instead, you'll have all sorts ringing out where they shouldn't be.
That way, your l.h. is free to play the low Cs, and r.h. for the high notes.
If you happen to be asking where the B and G notes are, they're above middle C on the piano. But they are in the music earlier, so I guess it's not that.
Answer: I don't know if this is a proper answer, but ... here is a video of the arranger playing the song:

It looks like he's not playing the G and B notes at all in that bar! And to me it doesn't sound like he's pressing the pedal either. :) The answer to the mystery is probably that the arranger should have been more careful with writing the notes - but then again he did provide a video example.
I found that from the site that was mentioned on the Scribd PDF:
http://www.gamemusicthemes.com/sheetmusic/segagenesis/sonicthehedgehog/greenhillzone/index.html
Comment: @pedroaugustomiranda No problem. It's a nice piano version, I think I know people who might be interested in learning to play it!
Answer: This is just another bad online "piano arrangement."
If it were a real piano arrangement, the "arranger" would have put in pedal markings or some other indicator at the point you highlighted.
There is also no tempo indication. Old Baroque scores often had no tempo markings, but there were tempo conventions for certain meter and typical rhythm patterns. In a modern score leaving off the tempo isn't normal. This isn't just a quibble. When looking at the left hand repeated note figure with doubled thirds played simultaneously in the left hand I wonder just how fast it's expected to be played!
Signs like these tell me there was no thought put into how a performer is actually supposed to play the music. That's a stranger indifference to the performer when the whole point of arranging is to make music available to performers on  different instruments. Quite a bit of change can go into an arrangement for the sake of performance on a specific instrument.
Just putting notes in notation software doesn't make an "arrangement." My suspicion is the "arranger" has never even played this from their own "arrangement." They only listed to the notation software playback.
Comment: An effective comment on the plethora of bad arrangements, but not an answer to the question.
Comment: This was my initial thought as well, but as it turns out, the arranger very much plays the arrangements himself, and I think it's nice stuff, completely playable - if you play it like he does. :) But he could have been more careful with writing notes.
Answer: Listening to a recording of the piece (around 0:12), the arranger of the score above created an accurate transcription, but not a playable one at that point. However, in the recording the bass part doesn't become prominent until the second half of the measure shown. My recommendation is to leave the bass C as middle C for the first half of the measure and then play as written in the second half, dropping the chord. This will have the effect of preserving the melody -- the chord -- as long as possible while still maintaining the bass run up to the next measure of the arrangement.
<code>X:1
T:Green Hill Zone
T:Sonic the Hedgehog
K:C
M:C
%%score (V1) | (V2 V3)
V:V1
V:V2 clef=bass
V:V3 clef=bass
[V:V1]c'bag c'bag | c'bag c'bag |
[V:V2][Ac]3 [GB]4-[GB]- | [GB]4 x4 |
[V:V3]CCCC CCCC | CCCC C,C,D,E, |
</code>
NOTE: In the video provided in @piiperiReinstateMonica's answer, the arranger drops the chord entirely when entering the second measure of the OP.


What is the contraposive of this statement?

Question: I have to prove the negation of this statement:
$$\forall a,b,c\in\mathbb{Z}{\;if\;a\;|\;b\} $$
But the fact that there is a "and" is very disturbing. I think that I am missing something because my "version" of the contraposive is obviously wrong. (take a = 3 , b = 7,  c = 4)
Comment: $\forall a,b,c\in\mathbb Z\left( \text{ if } a\mid b+c, \text{ then either } a\mid b\text{ and } a\mid c \text{ or } a\not\mid b \text{ and } a\not\mid c\right)$, because the opposite of "$a$ divides exactly one of $b,c$" is "$a$ divides none or all of $b,c$".
Comment: No, it is "if not B, then not A".
Comment: Wait the contraposive of A then B isn't B then A?
Comment: @user314 To prove the contraposive can I negate the second part of your statement which become: $$(a\nmid b\lor a\nmid c) \wedge (a|b \lor a|c)$$ take for example $$a\nmid b \wedge a|c$$ and show that there is a contradiction. is that enough?
Comment: Let's call your original statement $P\implies Q$. Then I gave you the contraposition (an equivalent statement to yours), which is $\lnot Q\implies \lnot P$. And now you're asking whether you can assume $P$ **and not Q** and arrive at a contradiction. Yes, you can do this, but such a proof will not be called a _proof by contraposition_. It will instead be called a _proof by contradiction_. The difference is that, when you prove something by contradiction, to prove $P\implies Q$, you assume $\lnot Q$ and $P$ to arrive at a contradiction, while a contraposition requires a direct proof.
Comment: I.e., when you want to prove $P\implies Q$ by contraposition, you prove $\lnot Q\implies \lnot P$ _without assuming P_.
Comment: I honestly have no idea how I can directly prove the contraposition starting from $$a|(b+c)$$ any hints?
Comment: Please edit the LaTeX in your question.
Answer: Your statement is equivalent to
$$\forall a,b,c\in\mathbb Z\left( \text{ if } a\mid b+c, \text{ then either } a\mid b\text{ and } a\mid c \text{ or } a\not\mid b \text{ and } a\not\mid c\right)$$
Assume $a\mid b+c$. Then $b+c=ak, k\in\mathbb Z$. Now check two cases, which are exhaustive:
$1)$ $a\mid b$. Then $b=am, m\in\mathbb Z$ and so $b+c=am+c=ak\iff c=a(k-m)$.
Thus $\exists n\in\mathbb Z \left(c=an \right), a\neq 0$, which means $a\mid c$ by the exact definition of divisibility.
$2)$ $a\not\mid b$. Then $b=am-r, 0<r<|a|$ and $b+c=am-r+c=ak\iff c=a(k-m)+r$.
Since $0<r<|a|$, we know that $r$ is the remainder of $c$ when $c$ is divided by $a$.
Since the remainder is not zero, we have that $a\not\mid c$.
Comment: @torr You should read the definition of [remainder](http://en.wikipedia.org/wiki/Remainder). As for your second question, since we know that $b$ is not divisible by $a$, we can write it was $b=am\pm r$ for some $m\in\mathbb Z$ and $0 (true or false) <=> not A -> true so not A -> not B
Comment: @torr Proving the statement right in the beginning of my answer is equivalent to proving by contraposition the statement in your main question. We assume $a\mid b+c$ and then we want to prove that either $(a\mid b)\wedge(a\mid c)$ or $(a\nmid b)\wedge(a\nmid c)$. There are exactly two cases that can then happen - either $a\mid b$ or $a\nmid b$. I then proceed to prove that if $a\mid b$, then $(a\mid b)\wedge(a\mid c)$ and if $a\nmid b$, then $(a\nmid b)\wedge(a\nmid c)$. Both these agree with what we wanted to prove, and so we are done.


Open sets in quotient map

Question: Take the closed interval [0,1] with the equivalence relation $t\sim t$, and $0\sim 1$. Let $\pi:[0,1]\rightarrow[0,1]/\sim$ be the quotient map. The set $U=[0,\frac{1}{2})$ is open in [0,1]; show that $\pi(U)$ is not open in $[0,1]/\sim$.
My confusion is that $V\subseteq X/\sim$ is open if and only if $\pi^{-1}(V)$ is open in $X$, so if we let $X=[0,1]$ and $V=\pi(U)$, shouldn't $\pi(U)$ be open?
Comment: Actually, $\pi$ is a homeomorphism.  Are you sure that only $t\sim t$ and not perhaps also $0\sim 1$?
Comment: Rereading the question, I actually think that is what was meant. I will edit.
Answer: $\pi(U)$ isn't open because the equivalence class $[0]$ of an endpoint isn't an interior point of $\pi(U)$. (This is quite clear if you think of $[0,1]/{\sim}$ as a circle.) Indeed, any neighborhood $N$ of $[0]$ is pulled back by  $\pi$ to a neighborhood of $\{0,1\}$ in $[0,1]$, which contains a subset of the form $[0,\epsilon) \cup (\epsilon,1]$ for some small enough $0 < \epsilon < 1$. Thus $N = \pi(\pi^{-1}(N))$ contains $[1 - \frac{\epsilon}{2}]$, whereas $[1 - \frac{\epsilon}{2}] \notin \pi(U)$.

Open sets in quotient map


Number theory based problem.

Question: Problem statement,

The greatest number which on dividing 1657 and 2037 leaves remainder 6 and 5 respectively.

Not sure how to begin with this problem. Is there any trick to these kind of problems?
Comment: Please find better titles. Your frequent use of "word problem" and "based" as the full description is not good enough, and frankly, a problem.
Comment: Don't misuse the tags. This, just like your previous one, is `[elementary-number-theory]`
Comment: Find the common divisors of $1657-6$ and $2037-5$. Do you see why?
Comment: When you start a paragraph with long indentation, the software interprets it as a "verbatim" paragraph. It it displayed with no line breaks, no formatting, nothing. To get a paragraph that looks indented on display, precede the first character with `>` instead.
Comment: @ArturoMagidin Sorry about that. I will try to be more price in future.
Comment: look up the Chinese remainder theorem
Comment: @DavidLui CRT is the wrong tool here.
Answer: Let $n$ be the greatest positive integer such that $1657 = 6 \text{ (mod n)}$ and $2037 = 5 \text{ (mod n)}$.
This implies that $n$ divides $1651$ and $2032$ evenly.
The prime factorizations of these numbers are $1651 = 13 \times 127$ and $2032 = 2^4 \times 127$.
$n$ must be the greatest common divisor of these numbers, so $\boxed{n = \gcd(1651, 2032) = 127}$.
Comment: Please strive not to post more (dupe) answers to dupes of FAQs & PSQs, cf. recent site policy announcement [here](https://math.meta.stackexchange.com/q/33508/242).

Number theory based problem.


C++ char sequence function always return empty string

Question: Just start learning C++ and trying to make a simple function that do substring with following code:
char* substring(int start, int end, const char* target)
{
    size_t length = strlen(target);

    char result[(length + 1)];

    int iterator = 0;

    for(int i = start; i < length; i++)
    {
        if(i <= end)
        {
            result[iterator] = target[i];

            iterator++;
        }
    }

    result[iterator] = '\0';

    cout << result << endl; // This give correct result "aya";

    return result;
}

When I use these function on main method:
int main(int argc, char** argv) {

    char some_text[] = "Saya Makan";

    char* sub = substring(1, 3, some_text); // No string returned

    cout << "Substring Result is: " << sub;

    return 0;
}

It give output is like this:
aya
Substring Result is:
RUN SUCCESSFUL (total time: 44ms)

As seen on the result, my function isn't returning anything but empty string although a line of code before return, the "result" variable echoed result correctly. Would you please explain to me what is happening inside my function, am I missing something?
Comment: Looks more like C than C++ (the problem is that you're returning a pointer to a local variable which undefined behavior)
Comment: What make it more like C than C++? Is it because i use char* rather than std::string?
Comment: Yes. Ideally you should use `std::string`, but since you're learning it's okay to use `char*`. You should also use things like `std::copy` instead of that `for` loop.
Comment: Oh, I see. Thank you very much for your advice Sir. It took so much time for me to figure out what is exactly this char sequence things.
Answer: You are returning pointer to a local array which is not required to live beyond the function.
You need to make the buffer persist beyond the scope of the function by allocating it dynamically using malloc. And ofcourse remember to free it later.
Oh just noticed its C++.
So drop the idea of malloc and free simply use std::string and not char *.
Comment: Rather than `malloc`, just pass a pointer to a string buffer which you will write into.
Comment: Thanks. But is it better to use std::string than char sequence? What will you recommend me to use? Char sequence or std::string? I really need advice about this.
Comment: @yunhasnawa: Use `std::string`, it saves you all the problems of manual memory management which come with using `char *` and provides u everything that a `char *` provides u.


Is this axiom self-contradicting?

Question: I was on physics stackexchange and came across an unusual answer where it was stated that the axiom,
$$\forall x ((x \in x) \land (x \notin x))$$
Creates an axiom system where "nothing" exists in it. I kind of misquoted here, here's an exact,
"From that single axiom we can conclude that nothing exists, that the universe of discourse of this axiom system is exactly the empty universe of discourse."
Needless to say, I got into a heated debate on the self-consistency of the axiom. My position is that it can't create a universe or universe of discourse because there are no entities within it. See wikipedia's definition
In English, I interpret the axiom to say,
For all X, X is an element of itself and X is not an element of itself.
This seems self contradicting, akin to Russell's paradox, but the Op insists that it isn't.
I'm open to either take on the issue, but a simple yes/no response will not cut it. A definition review might also help quantify the dialogue.
If it helps, from a semi philosophical-mathematical I consider nothing to be the null set.
Comment: Nothing creates universes. That interpretation is not mathematics, I am afraid.
Comment: If you are after is  axiom which only admits empty models (and you should consult a book on logic to be sure!), you can consider $\forall x(x\neq x)$.
Comment: @MarianoSuárez-Alvarez I added the exact quote to avoid any possible misrepresentation.
Comment: Is there a missing $\lnot$ in your axiom?
Comment: Well, that means precisely what I suggested: he is after an axiom which only admits empty models.
Comment: So considering empty-models might help clear some of the confusion?
Comment: I think you meant $\not\in$ somewhere
Comment: I don't understand what possible confusion there is, honestly. It is clear that a model of «$\forall x(x\neq x)$» has to be empty.
Comment: Ha, ha so this is a bit of a confusing subject :)
Comment: I think if you want contradiction you'd need something like $\forall x(x\in x)\land\exists x(x\not\in x)$?
Comment: @RobArthan that was a silly mistake, fixed :)
Comment: @Mariano I fixed the title as well.
Comment: I recall discussion on [an answer](http://math.stackexchange.com/a/412396/72995) to another question (disclaimer, the answer mine) about universe of discourse that's relevant here.  In standard first order logic, there's the principle of "existential import," which means that the universe of discourse is non-empty.  See the comments on that answer as well.
Answer: Working in classical logic, the rules of logic dictate that $x\in x\land x\notin x$ is a false statement.
Therefore the only structure satisfying $\forall x(x\in x\land x\notin x)$ is the empty structure. However due to superficial reasons, we choose not to accept the empty structure as a valid interpretation of a first-order language, so it is not a model of this axiom.
In particular it means that any theory including this axiom is inconsistent. If you want to argue in non-classical logic, perhaps paraconsistent logics, that is a whole other things which should be explicitly mentioned.
(I took a quick look at the Phy.SE answer, and I'd probably stay away from that answer and as a rule of thumb largely ignore any claims about mathematical logic made on Phy.SE without references.)
Comment: @Rob: I was on the other side of this before, but still this answer is interesting: http://math.stackexchange.com/a/45208
Comment: @JoshuaTaylor: Yes, but in a certain sense those inference rules are also superficially chosen. The intended **semantics** of the universal quantifier is that if you **have** an object of the type quantified, then you can **instantiate** the quantified statement for that object. There is no problem even if the universe is empty, because with a consistent formal system you would not be able to **obtain** any object at all and so cannot instantiate any universally quantified statement. The rule you mention, on the other hand, **assumes** a non-empty universe.
Comment: @Zach: Classical logic is a collection of basic axioms and inference rules. In mathematics, unless stated otherwise, the underlying logic is classical logic. In particular ZFC is using classical logic. There are systems of set theory which use variants of ZF with non-classical logic (specifically, intuitionsitic and constructive logics) called IZF and CZF. But ZFC and CZF are very far from one another. :-)
Comment: @AsafKaragila: I fail to see why you say "superficial" above. A structure has to interpret all the symbols in the signature. You could equally well say that for superficial reasons we exclude the empty set from being a complex number.
Comment: A structure for a non-empty language cannot be empty! I will elevate the comment I was just typing up into an answer. (And as an aside, $\phi \land \lnot\phi$ false in intutionistic logic too.)
Comment: @Rob: Arguably a structure to a language without constants *can* be an empty set. But it is easier to accept that the empty set is not permitted to be a structure at all.
Comment: To make things clearer, I should have "structure for a non-empty signature". The language here is over a signature with a predicate symbol $\in$ and a structure for this signature cannot be empty.
Comment: I have a question. Is it simple to determine whether or not ZFC, or any logical structure, falls into the category of classical logic?
Comment: There is a misunderstanding here. When you say "empty model/structure" you mean "model/structure with an empty universe". I was thinking that you meant that the empty set could somehow be viewed as a model or structure of $\phi \land \lnot\phi$. I retract my comments.
Comment: So, can saying "paraconsistent logic" to "classical logic" as "nonstandard" is to "standard analysis" a good analogy?
Comment: @Zach: I don't know, but I don't think so.
Comment: Ok, would you say non-classical logic is an uncommon topic or occurrence in set-theory?
Comment: @Zach: Depends on who you ask. I cannot think of many people I'd call set theorists that work in non-classical settings. Most of those, I'd probably brand as "logicians" instead. Maybe other people feel differently.
Comment: Thank you for engaging with my questions. I definitely learned some interesting things :)
Comment: If we allowed empty models, would $\exists x\land(\forall x(x\in x)\land(x\not\in x))$ be contradictory?
Comment: @AsafKaragila "However due to superficial reasons, we choose not to accept the empty structure as a valid interpretation of a first-order language"*  I don't think the reasons are entirely superficial.  We'd typically like universal instantiation to let infer $\phi(\tau)$ from $\forall x \phi(x)$ to $\phi(\tau)$ for any term $\tau$, and to infer $\exists x.\phi(x)$ from any ground formula $\phi(\tau)$. That lets us do $\forall x.x=x$ to $a=a$ to $\exists x.x=x$. With those inference rules, we'd need to reject $\forall x.x=x$ if the domain can be empty.
Comment: @Zach466920 Paraconsistent logics are an interesting field, but not necessarily what you need in order to consider non-empty universes of discourse.  The field of logics that permit empty universes of discourse are *free logics*.  There's a bit of discussion in [this answer](http://math.stackexchange.com/a/412396/72995) (disclaimer, it's mine) and the comments on it.
Comment: @Joshua ha, ha I kind of feel like that theorem could be stated as the "begging the question theorem".
Comment: In order for us to be able to "choose not to accept the empty structure" and still have the completeness theorem hold, we have to choose axioms of logic for which $\exists x (x=x)$ is a theorem.  Indeed, such logical axioms are included in "classical logic".  Then it's not hard to show directly that this contradicts $\forall x (x \in x \land x \notin x)$, so that any set of sentences containing this one is inconsistent.
Answer: This is an example of how mathematical conventions are often divided on the status of degenerate cases.
Some more modern approaches to logic do indeed allow empty universes of discourse. For example, you'd likely see this in any source that works with first-order logic from the point of view of category theory.
However, more traditional approaches reject empty universes of discourse. In the corresponding formulation of first-order logic, your formula would indeed be a contradiction.
Answer: A formula of the form $\phi \land \lnot\phi$ has no models (other than in the model theory of some rather obscure substructural logics). This is unconnected with Russell's paradox and not at all deep. There is no such thing as an "empty model" for a non-empty language, e.g., a language including he membership symbol $\not\in$.
[I should point out that this answer does not conflict with Asaf Karagilia's answer: if you allow models that have empty universes, then $\forall x(\psi(x)\land\lnot\psi(x))$ does not have the form $\phi\land\lnot\phi$ and may hold in a model with an empty universe. However, allowing models with empty universes puts you in the far from classical realm of free logic.]
Comment: I think that's why it was on PSE. No comment on the correspondence to reality needs to be drawn.
Comment: @Zach466920: OK: I relegate the following observation to this comment and emphasise that it is not a criticism: "In my opinion, to draw conclusions about the physical world from these mathematical facts is outside the scope of MSE."
Comment: @Rob: And outside the scope of any reasonable person who knows anything about mathematics... :-)
Comment: I was honestly skeptical of using set theory to form a physical theory from the get go. Nevertheless, this subject seems very interesting so I'm interested in it for curiosity's sake.
Comment: @RobArthan - I'm not sure allowing models with an empty universe gets you outside classical logic. Hodges, for instance, allows models with an empty universe in his *A Shorter Model Theory*, yet I don't think he's working outside classical logic.
Comment: Hodges doesn't present a logical system (and doesn't seem to care much for logic). $\exists x (x = x)$ is a theorem of classical logic that does not hold if you allow empty universes.

Is this axiom self-contradicting?


Expected number of tosses for two coins to achieve the same outcome for five consecutive flips

Question: Consider two unbiased coins. Toss both until last 5 sequence outcome are same.
That means we stop when output of the sequence of both are as follows:
HTTHTHHTH , HHTTTHHTH.
What is the expected number of trials?
Comment: Encoding two equal outcomes as 1 and two different outcomes as 0, this is the time until 11111 appears in a random equidistributed 0-1 sequence. Can you solve this version of your problem?
Comment: Yes, now I can solve the problem. Thank you for pointing  out the connection.
Answer: Here's a different approach that simultaneously generalizes the solution.
As Didier and David have pointed out, the problem is equivalent to finding the expected number of flips required for a fair coin to achieve five consecutive heads for the first time.  Let $X_n$ denote the toss on which a fair coin achieves $n$ consecutive heads for the first time.  The analysis is just as easy if the coin isn't fair, though, so let's suppose that the coin has probability $p$ of being heads.
Suppose the coin has just achieved $n-1$ consecutive heads for the first time.  Then, with probability $p$, the coin achieves $n$ consecutive heads for the first time on the next flip, and with probability $1-p$, the process restarts after the next flip.  Mathematically, this is saying that $$\begin{align}E[X_n|X_{n-1}] &= p (X_{n-1}+1) + (1-p)(X_{n-1} + 1+ E[X_n])\\ &= X_{n-1} +1+ (1-p)E[X_n].\end{align}$$
Applying the law of total expectation, we have $$\begin{align} E[X_n] &=  E[X_{n-1}] +1 + (1-p)E[X_n] \\ \Rightarrow E[X_n] &= \frac{E[X_{n-1}] +1}{p}.\end{align}$$
Now we have a nice recurrence for $E[X_n]$.  Since $E[X_0] = 0$, unrolling this recurrence shows that
$$\begin{align}E[X_1] &= \frac{1}{p}, \\ E[X_2] &= \frac{1 + p}{p^2}, \\ E[X_3] &= \frac{1 + p+p^2}{p^3},\end{align}$$ and in general
$$E[X_n] = \frac{1+p+p^2+\cdots + p^{n-1}}{p^n}.$$
Using the formula for the partial sum of a geometric series, this expression simplifies to
$$\begin{align}E[X_n] &= \frac{1-p^n}{(1-p)p^n} \\ &= \frac{p^{-n}-1}{1-p}.\end{align}$$
In the case of a fair coin we have $p = 1/2$, and so  $$E[X_n] = 2^{n+1}-2.$$
Thus the answer to the OP's question is $E[X_5] = 2^6-2 = 62,$ as David Mitra has already shown.

This approach also handles the generalization of the OP's question in which the two coins being tossed do not necessarily have the same probability of being heads.  Suppose one has probability $p_1$ of being heads, the other has probability $p_2$ of being heads, and we toss them until the last $n$ flips are the same.  For a single flip, they are the same if they both come up heads, with probability $p_1 p_2$, or both tails, with probability $(1-p_1)(1-p_2)$.  Thus the probability that they are the same on a single flip is $1 - p_1 - p_2 + 2p_1p_2$.  Tossing these two coins until the last $n$ flips are the same is the same problem as tossing a single coin with heads probability $1 - p_1 - p_2 + 2p_1p_2$ until we see $n$ consecutive heads, and so the formula above for $E[X_n]$ tells us that the expected number of tosses of the two coins until the last $n$ flips are the same is $$E[X_n] = \frac{(1-p_1 - p_2+ 2p_1p_2)^{-n}-1}{p_1 + p_2 - 2p_1p_2}.$$
Comment: @MikeSpivey, this is brilliant. Could you look at this : http://math.stackexchange.com/questions/287051/using-recursion-to-solve-coupon-collector
Answer: As Didier points out in his comment, the problem is equivalent to the problem of finding the expected number of flips, $X$, of a fair coin that are made until 5 heads appear in a row.
We condition on whether or not a tail appears in the first five flips.
For $1\le i\le5$,
let $T_i$ be the event that the first tail occurs on flip $i$ and let $T_6$ be the event that the first five flips are all heads.
We have $$\Bbb E(X\mid T_i)=i+\Bbb E(X),\quad 1\le i\le 5$$ (if the first tail occurs on flip 3, for example, then it's as if we are "restarting": the expected number of flips to  obtain 5 heads in a row would be 3 plus the original expected number of flips).
Also, cleary, $$\Bbb E(X\mid T_6)=5.$$
We have:
$$\eqalign{
\Bbb E(X)&= \sum_{i=1}^6 P(T_i)\,\Bbb E(X\mid T_i) \cr
&=\sum_{i=1}^5 \bigl({\textstyle{1\over 2}}\bigr)^{i }\bigl(\,i+\Bbb E(X)\,\bigr)+   P(T_6)\Bbb E(X\mid T_6)\cr
&= \sum_{i=1}^5{i\over 2^i}+ \sum_{i=1}^5{1\over 2^i}\Bbb E(X)+{1\over32}\cdot 5\cr
&={31\over 32}\Bbb E(X)+  {62\over32}
.
}
$$
Solving the above for $\Bbb E(X)$ gives
$$
\Bbb E(X)={62/32\over1/32}=62.
$$

Inspired by Mike Spivey's excellent answer, I'll add that the above can be generalized to the case where $X$ is the number of flips to be made until  $n$ heads in a row are obtained, where the probability that the coin lands heads on one flip is $p$.
Here, for $1\le i\le n$, let $T_i$ be the event that the first tail occurs on flip $i$ and let $T_{n+1}$ be the event that the first $n$ flips are all heads.
Then $$\Bbb E(X\mid T_i)=i+\Bbb E(X),\quad 1\le i\le n$$
and $$\Bbb E(X\mid T_{n+1})=n.$$
Also,
$$
P(T_i)= (1-p) p^{i-1},\quad 1\le i\le n
$$
and
$$
P(T_n)=p^n.
$$
We have:
$$\eqalign{
\Bbb E(X)&= \sum_{i=1}^{n+1} P(T_i)\,\Bbb E(X\mid T_i) \cr
&=\sum_{i=1}^n (1-p) p^{i-1}\bigl(\,i+\Bbb E(X)\,\bigr)+   P(T_{n+1})\Bbb E(X\mid T_{n+1})\cr
&= (1-p) \sum_{i=1}^n{i} p^{i-1} + (1-p)\sum_{i=1}^n{p^{i-1}}
\Bbb E(X)+ p^n\cdot n\cr
&=(1-p){ np^{n+1}-np^n-p^n+1\over( 1-p)^2} +(1-p) {1-p^n\over 1-p }\Bbb E(X) +np^n.\cr
 }
$$
Solving the above for $\Bbb E(X)$ gives
$$\eqalign{
\Bbb E(X)&={ {np^{n+1}-np^n-p^n+1\over1-p} +np^n \over 1-(1-p^n)}\cr
&={ {np^{n+1}-np^n-p^n+1\over1-p} +{np^n (1-p)\over 1-p} \over 1-(1-p^n)}\cr
&={1-p^n\over(1-p)p^n  }.\cr
}
$$

In retrospect, it appears that Mike Spivey's method is much neater.

In the above we used the formula
$$
\sum_{i=1}^n i p^{i-1} ={ np^{n+1}-np^n-p^n+1\over( 1-p)^2}.
$$
Here is a proof of that:
Let $$
\def\ts{\textstyle}
S_n=\ts{p^0}+2 {p}^1 +3 {p}^2+\cdots+n {p}^{n-1}.$$
Then $$\eqalign{
\ts pS_n
&=\ts \bigl[\,{p}^1+2  p^2+3  p^3
               +\cdots+(n-1)  p^{n-1 }\,\bigr]+n p^{n }\cr
&=\ts S_n-
[p^0+ p^1 +p^2 +    \cdots +  p^{n-1 }  ] + np^{n  } \cr
&=\ts S_n-{p^0 -p^{n }\over 1-p}+ np^{n  }.
}$$
Whence
$$
\eqalign{
S_n&={ -{1-p^n\over1-p}+np^n\over p-1}\cr
&=  {1-p^n\over (p-1)^2}+{np^n(p-1)\over (p-1)^2}\cr
&={ np^{n+1}-np^n-p^n+1\over( 1-p)^2},
}
$$
as claimed.
Comment: Thank you very much for such detail answer. Just for information, one can use the idea of of Li (Page 428, Grinstead and Snell's Introduction to Probability) to solve these kind of problem.


Harmony on measures 21/22 of Chopin's Fantaisie-Impromptu, Op. 66

Question: On measure 21, Chopin uses a B major-minor chord followed by a D# minor chord. One might think we're in E major and that he's just borrowing the D# minor, but on measure 19, it seems Chopin has already modulated back to C# minor by preparing us with a iiø V7 like what was in measure 7*. It's clear that he utilizes this D# minor to get to the B# fully diminished seventh in the next measure, but how is this progression described in functional harmony (B major-minor [or B dominant] -> D# minor -> B# diminished seventh)?

*In the larger harmonic context, measures 21-24 seem to extend and amplify the instability of measures 19-20 to take us back to the home chord of C# in measure 25.
Comment: Where are you getting the `B min` from in bars 21 (& 23)? The first chord of 21 is a dominant 9th in 4/2 position. Does that help your analysis?
Comment: @alexsms I would argue the ninth is a suspension and not part of the harmony (since it is resolved immediately). And if you want to label the first beat of bar 21 separately: the B doesn't appear until the C disappears so you would have to call the first beat D# diminished but looking at the left hand this seems counterproductive.
Comment: @DeanRansevycz Isn't it B7-9 to be exact? (i.e. altered 9th dominant)
Comment: @DeanRansevycz I am talking about B maj-min7 not B min. You might call this a dominant chord. The function of this chord is unclear to me since it doesn't resolve down a fifth, hence I didn't refer to it as a dominant chord except in the parentheses. It does not seem to be a dominant chord in this case, however, since we're no longer in E major.
Comment: Thanks for the clarification, @Okoyos. It wasn't clear from your text that you meant `B Maj, min 7`. I stand by the analysis of a dominant harmony as the chord has the shape of a dominant 7th with minor 9th: the root motion doesn't affect that. This especially relevant if the passage in question is analysed in reference to the succeeding bars.
Comment: @DeanRansevycz By dominant harmony, do you mean that it has dominant function? If so, what is it a dominant chord of?
Answer: Chopin was of course very good at harmony, and one of his specialties were chromatic progressions. The particular bars you picked are quite complicated, so I will explain a few different concepts first, before explaining the progression in question.
(Very) broadly speaking, there are two ways to connect chords in a progression: through functional harmony and through counterpoint (voice leading). These two often overlap, since a functionally logical progression typically has very straightforward voice leading.
The two bars you are referring to are not connected through functional harmony, but through voice leading, using some chromatic alterations (these are what makes the progression difficult to fit in a functional progression).
First, let's just consider a B major-minor seventh chord (or B7, for jazz readers). A common chromatic alteration would be to sharpen the root while leaving the rest of the chord as is, creating a B# diminished seventh chord. Of course you can explain this in a functional context (with the diminished chord being a secondary dominant, probably preparing a deceptive cadence) but this is highly dependent on the context (mainly the resolution of the diminished chord). Much simpler is the contrapuntal explanation: a chromatic alteration (raising) of the root note.
A different voice leading trick is voice exchange: two voices exchanging their notes. So let's consider our B major minor chord again, in root position, narrow voicing. This means the bass has the root (B), and the soprano has the seventh (A). The rules of voice leading allow us to change the chord to a third inversion by having the bass descend stepwise to the seventh of the chord (B -> A) and the soprano ascend stepwise to the root of the chord (A -> B). Normally sevenths have to resolve downwards (in strict voice leading) while here the A goes up, but this is fine since we are not resolving it, but merely moving it to a different voice (where it will hopefully resolve properly later). Note that voice exchange doesn't require stepwise motion (an exchange that requires jumps is completely fine too – in fact voice exchange is a common trick to rearrange voices) but this seemed the simplest and most applicable example.
A third technique is the use of passing tones. In simplest terms, if a voice is moving up or down a third it doesn't need to jump, but can go through the tone in between as well, without that note being part of the harmony. So suppose we have a B major triad in four voices with both soprano and alto on the fifth and we want the soprano to move to the seventh we could just have it jump (F# -> A), but it would be fine to include the G# as well (or G natural in minor or as moll-dur). The passing tone (G# here) would normally be between beats or on a weak beat. This would not change the harmony at all. An extension of this principle is the chromatic passing tone: when moving by a major second you can move by a minor second twice instead. For example, let's consider a B major chord with the root in both the bass and the soprano. We want to change the triad to a seventh chord by having the soprano descend to the seventh. As in the previous example, we can do it directly (unlike the previous example, here it would be a stepwise move), but we can put the A# in between, having the soprano go B -> A# -> A with the A# again being on a weak beat. When doing this, you typically wouldn't include a B major seventh chord in your harmonic analysis (since the passing note is irrelevant to the harmony) but fairly frequently there are situations where it is unclear and/or subjective whether a note is a passing note or part of the harmony.
Chopin combined these three things in the two bars you mentioned, which I will now construct in two steps from the above concepts.
If, for a moment, we ignore the D# minor chord in second inversion in the second half of bar 21, we see first a B major minor chord in third inversion, then a B diminished seventh chord in root inversion. This is a combination of voice exchange (basically the reverse of what I described in the relevant paragraph) and chromatic alteration: while the B in the soprano is moving to an A, the A in the bass is moving not to a B, but to a B#!
This leaves us with a problem, though, since this means the bass is moving by an augmented second (A -> B#). We consider this bad voice leading. (Why? Because.) Fortunately, Chopin solved this by putting an A# in between (A# -> B# is only a major second so the voice leading problem is avoided). This is the chromatic passing tone we went over earlier, although slightly extended (since here it's a passing tone between to notes that are an augmented second apart). This is still well within the bounds of passing notes in strict voice leading (it is a stepwise motion between two notes that are part of the current harmony). This combined with the voice exchange I described in the previous paragraph gives us the progression you asked about.
A last side-note: in your analysis you label the D# minor chord as such. You might have noticed that in my analysis, this chord doesn't appear, but is merely a by-product of simultaneous passing notes. As I mentioned earlier, quite often it is unclear whether a note should be consider a passing tone or part of the harmony. Here I think the A# is clearly a passing tone for two reasons:

The D# minor chord would have no clear connection to the rest of the progression (since there are so many As it doesn't even seem to fit in the scale currently used)
Chords in second inversion are unstable and need to be resolved since they include a fourth on the bass which would need to resolve to a third (in the strictest voice leading). I'm not saying it is impossible for a second inversion chord to appear without proper resolution but it is very unusual while at the same time we have a much more "proper" explanation available. Additionally, Chopin is quite strict when it comes to harmony rules (as opposed to for example Liszt who had no problems writing unresolved second inversion chords and did so frequently).

After all this, you might have figured out bar 23-24 already, but it's a combination of the same techniques: first we have a voice exchange (B -> A and A -> B) with a chromatic passing tone (A#) in between, afterwards a chromatic alteration (B -> B#) combined with the resolution of the seventh (A -> G#). Again this is quite difficult to explain using functional analysis, but it obeys all the rules of counterpoint.
I hope this is clear enough. Since Chopin is so elegantly combining so many tricks at once I imagine this can be very confusing (especially if the above material is new to you).

TL;DR
Bar 21-22 is a progression that is connected through counterpoint, not through functional harmony. First we have a chromatic passing note (A#) while exchanging B and A in bass and soprano, leading to a chromatic alteration (B# instead of B) in the bass. Then bar 23-24 has the same passing note (A#) but the chromatic alteration is delayed by half a bar, where it is combined with the resolution of the seventh on the B chord.
Answer: Preface
@11684 Gives a very good explanation in contrapuntal terms of how this passage works. It should be considered carefully. I'll give an explanation in functional analytic terms. Loosely speaking, one could say that @11684 gives a melodic explanation for the passage, and I offer a harmonic one.

TL;DR
Measures 21–22 are an expansion of D# minor; that is, the key of ii. They are the beginning of a ii V i progression leading to C# minor in m. 25.
How is B7 -> D# min -> B# dim7 described in functional harmony?
Within the expansion of D# minor, the progression is bVI aug 6 -> cadential 6-4 -> common-tone dim7.
Within the target key of C# minor, the progression is VII7 -> ii -> viio7

Detailed explanation
In mm. 13 – 16, Chopin establishes a very clear ii V I progression in E major. (See Examples 1a and 1b, below.)
Measures 17–18 and the first half of 19 repeat mm. 13–14 and the first half of 15, but the second half of m. 19 signals a change of key back to C# minor. The F# minor chord that begins m. 19 is a pivot chord, serving as both ii of the old key (E Major) and iv of the new key C# minor. This sets up the V chord of C# minor (G#) in measure 20. (See Example 2, below.)
One way to confirm the transition to C# minor is to return to the main theme at this point: that is, cut measures 21–24, and just jump straight from m. 20 to m. 25.
Measures 21–24 serve to delay and strengthen the eventual arrival, in m. 25, of the C# minor tonic harmony. Measure 21 through the first half of measure 24 elaborates D# minor, the ii harmony, while the second half of measure 25 states the V chord, G#.
Measure 21 comprises two chords.

The B7 chord is both VII in C# minor and bVI (B augmented sixth chord) in D# minor.
The D# minor chord is ii in C# minor and I (or more accurately, cadential 6-4) in D# minor.

The sense of transition can be confirmed by playing the progression shown in Example 3.
The diminished chord is measure 22 is both a common-tone diminished seventh chord relative to D# minor (primarily) but also vii of C# minor (secondarily, as the passage emphasizes the D# minor chord).
Measure 23 repeats measure 21, but measure 24 returns to the augmented sixth chord, ow in root position (via voice exchange: see @11684's answer) and doubling as bVII in C# minor — another pivot chord. The bVII chord proceeds to the V chord of C# minor (Example 4), and then in measure 25 the main theme returns in C# minor.
Conclusion
Measure 21 through the first half of 24 are a prolongation of the D# minor (ii of C# minor) harmony, leading to the dominant chord in the second half of m. 24, and resolving to C# minor with the return of the main theme in m. 25.

Examples
Example 1a: mm. 13–16

(IMAGE SOURCE)
Example 1b: mm. 13–16 reduction
X: 1
T: Chopin Op. 66
T: mm. 13–16
K: C#m
M: C|
L: 1/2
V:V1 clef=treble
V:V2 clef=bass middle=D
%%score V1 | V2
[V:V1]     [Fcf]2   | [DFAd]  [EGBe]   | [Fcf]2   | [FBdf]  [GBeg]   |
[V:V2]"ii"[A,CFA]2|"V"[B,FAB]"I"[E,B,EG] | "ii"[A,CFA]2 | "V"[B,FAB] "I"[E,B,EG] |

Example 2: Measures 19–20
The F# minor chord comprising the first half of m. 19 functions as ii in the key of E major, as previously, but also as iv of C# minor. The subsequent D# half-diminished chord is ii in C# minor (also vii in E major), leading to V of C# minor.

(IMAGE SOURCE)
Example 3: D# minor cadence extending measure 21
X: 1
T: Chopin Op. 66
T: mm. 21 with cadence added
K: C#m
M: C|
L: 1/2
V:V1 clef=treble
V:V2 clef=bass middle=D
%%score V1 | V2
[V:V1] [Bdfb] [^Adf^a] | [^A^^c^e^a]  [DF^Ad]   |
[V:V2] "bVI"[A,DFB] "C6-4"[^A,DF^A] | "V"[^A,^^C^E^A] "i"[D,F,^A,D] |

Example 4: bVII7- V[6-5] progression
Aldwell and Schachter (Harmony and Voice Leading, 2nd ed, 1989) give two examples of VII V i. Their example 24-19 (p. 389) gives a passage from Handel's third harpsichord suite, first movement, measures 11–16. The piece is in F major, and the harmony progresses from G minor to C7, seemingly setting up a ii V return to F. However, the C7 progresses to A7 and then to D minor.

The progression is also discussed in the context of voice exchange on pages 537–38.
(IMAGE SOURCE)
Answer: The "D# minor" chord is a chimera - it is a byproduct of the intersection of passing tones (A-A#-B in bass, C-B-A# in treble) that decorate and prolong the B7 harmony by contrary motion. (Also, I think the B# in the bass on the first beat of m. 22 is wrong.)
Comment: I don't know what you mean by "wrong" but it's what Chopin wrote according to Henle (in both the manuscript and in the Fontana version).


Who can qualify for the Australian Open?

Question: I apologise if this question may sound ridiculous.
 I would like to know if there are any limitations to qualify for the Australian Open.
For example, to qualify for the WTA Finals, WTA players compete throughout the year in over 53 tournaments plus the Slams. By doing so, players earn ranking points and ONLY the first 7 (or 8) top players can have access to the WTA finals.
Is there a similar rule also for the Australian Open?
Comment: I would assume that you would need to be a registered WTA or ATP player in order to qualify, there is also likely a fee to participate. I'm not sure how else they would narrow down the field of players but if I were to outright guess I'd say there's probably a minimum number of ATP or WTA points you would need to have in order to qualify for the right to qualify for the tournament.
Answer: 128 players compete in the singles main draw of Australian Open.

104 spots are given to players with highest ATP/WTA ranking at that moment. If some of the 104 top players will not participate, next top ranked players will replace them.
16 spots are given to qualification winners (Q). Players qualify to qualification based on their ranking, like in main draw. There are 16 qualification brackets consisting of 3 rounds. Player who wins all 3 rounds in a bracket will qualify to the main draw. Additionally, if some players from the main draw will not be able to play the first round due to an illness or so, lucky losers will replace them (LL). Lucky loser is a player who lost in qualification. Lucky loser are chosen based on qualification round they have been eliminated in (higher is better) and then based on their ranking. 119 spots in qualification are given based on ranking, remaining 9 are given to wildcards.
8 spots are given to wildcards (WC). Tournament has the right to give a wildcard to any player. Usually they are given to young talents, local players, or can be earned by winning some small wildcard tournament playoff.
additionally, players can use theirs protected rankings to qualify for the main draw (PR)
in some situations, special exempt (SE) spots in the main draw are given to players who signed up for qualification but are still playing some late rounds in other tournament and due to it could not compete in the qualification


Different aspect on different browsers

Question: I'm using Drupal 7, Webform module, and Bootstrap Sub-Theme.
I'm facing a browser problem and an admin/end-user problem.
As a French speaker I would like to have my error messages in French.
In Safari (as admin), it shows errors in red box as in this example:

This is my result in Chrome (as admin):

And this is my result in Firefox (as anonymous):

Chrome (as admin) is working with translation automatically (as shown in the example above), but not Firefox (as end-user).
Safari and Chrome (as admin) use a different way to display errors.
Safari got red box for every errors.
Chrome uses a red box just for web form validation (module) errors.
I would like to have errors in French and in red box for end-user as well.
End-user have to answer a Captcha.
Any suggestions to resolve these issues?
Answer: Even though you didn't mention it, this is clearly a multilingual site. Which implies that "language detection" is involved (to decide each time in which language a page (or webform) needs to be displayed.
Your problem related to the usage of French or English language might be because of the "language detection" configuration.
So check this configuration via Configuration -> Languages -> detection and selection: experiment a bit with the correct order that should be used. Often times, this should be changed to something like 'URL, Default, User', and not something like 'Default, URL, User' (which I assume you're currently using, and which might explain the difference in the language used in different browsers).
The browser differences to display the errors (red boxes, etc) might be some browser dependency and/or something in your sub-theme (custom or not?). With the few details provided it is hard to tell what might help to resolve that part of your question. I recommend you move that part to a different (new) question, or enhance your question to provide more details about the sub-theme.
Comment: Thanks for the answer in fact as you mentioned I was using the URL, Default, User. I changed it but the problem is still there.
Comment: OK, not (yet) the solution for your issue here, but at least something you had to do anyway, right? Let me think to see if I can come up with an extended answer (2nd attempt) soon ...

Different aspect on different browsers


Event handlers and loops

Question: I have a full screen window that plays a simple animation, and I want to make it so that when I press any key, the full screen is restored and the program stops.
The key listener class looks like this:
import java.awt.event.*;
public class key implements KeyListener {
private framerun animation=new framerun();

public void keyPressed(KeyEvent e){}
public void  keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){
    animation.x=false;
}

}
The animation runs in a method, run, with a while loop which looks like this:
public void run(DisplayMode dm){

        Screen s=new Screen();
        s.setFullScreen(dm, this);
        while(true){
            try{
                System.out.println(x);
                Thread.sleep(300);

            }catch(Exception e){}
            if(!x)
                s.RestoreScreen();
            repaint();
        }
    }

PS: x is a boolean with initial value true, initiated in the constructor.
This is the main method:
public static void main(String args []){
        DisplayMode dm=new DisplayMode(800, 600,    16,DisplayMode.REFRESH_RATE_UNKNOWN);

        framerun f=new framerun();
        key k=new key();
        f.addKeyListener(k);
        f.run(dm);
    }

Now this works perfectly if there is no while loop. The full screen closes and the program stop. But with the while loop there is no response when I press a key. The value of x doesn't change to false as expected.
Ideas?
Comment: Why can't you call `s.RestoreScreen` from the `MouseListener`?
Comment: I tried it, but it's as if it doesn't even notice the action when I press a key. It doesn't even change the value of x to false. That's the problem. Does the while loop clash with event listeners?
Answer: I can't get the DisplayMode switching to work, but it shouldn't make a difference.
Basically, KeyListener is fiddly.  It requires the component that it is attached to is focusable and has focus.
The following example basically uses a combination of requestFocusInWindow and setFocusable on a JPanel to try and force focus to the JPanel, so that when a key is typed, the JPanel can respond to it...
import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.EventQueue;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Test {

    public static void main(String[] args) {
        new Test();
    }

    private DisplayMode defaultMode;

    public Test() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
                defaultMode = gd.getDisplayMode();

                JFrame frame = new JFrame("Testing");
                frame.setUndecorated(true);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new TestPane());
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);

//              DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.BIT_DEPTH_MULTI);
//              gd.setDisplayMode(dm);
                gd.setFullScreenWindow(frame);
            }
        });
    }

    public class TestPane extends JPanel {

        public TestPane() {
            setFocusable(true);
            setLayout(new GridBagLayout());
            add(new JLabel("Test"));
            addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    requestFocusInWindow();
                }
            });

            addKeyListener(new KeyAdapter() {
                @Override
                public void keyTyped(KeyEvent e) {
                    try {
                        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
//                      gd.setDisplayMode(defaultMode);
                        gd.setFullScreenWindow(null);
                    } catch (Throwable exp) {
                        exp.printStackTrace();
                    }
                    SwingUtilities.windowForComponent(TestPane.this).dispose();
                }
            });
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(200, 200);
        }

    }

}

Personlly, I'd recommend using the key bindings API, How to Use Key Bindings, but this focuses on binding a single key to a given action, but overcomes the focus issues related to KeyListener
Comment: I feel it's simpler than this. Are while loops and event listeners normally incompatible?
Comment: Depends on where the loops are running.  Swing is a single threaded environment, meaning that if you run a loop within the context of the Event Dispatching Thread, the UI will stop responding as the EDT can no longer process the Event Queue
Comment: Could you recommend something that would satisfy my goals, which wouldn't be mindbogglingly difficult for a beginner like me? Something that would allow my animation to play but still give me the power to stop it using a key press.
Comment: I don't know, what's you goal?
Comment: Play the animation in full screen, but when I press a key on my keyboard the program stops and the screen returns to normal size.
Comment: You could use a Swing `javax.swing.Timer` to act as the main animation loop.  You could use a separate `Thread` to run the animation loop, but Swing it not thread safe, so you will need to ensure that any updates to the UI are done from within the context of the Event Dispatching Thread. See [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) and [How to use Swing Timers](http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html) for more details

Event handlers and loops


Sonar in Maven build stopped working

Question: I had a project built with maven on a Jenkins CI server, and recently the Sonar portion of the build began to fail with the well known
<code>  org.sonar.core.persistence.BadDatabaseVersion: Database must be upgraded. Please browse http://x.x.x.x:9000/setup
</code>
I browsed to http://x.x.x.x:9000/setup, and the message there was green and said my database was up to date.  The database looks good and the sonar server doesn't throw any Exceptions as far as I can tell from the output, and this installation had been working well up until a few days ago.
I checked that the id was the same between the running server and the database, and insured that only one instance of Sonar was talking to the H2 DB.
My next step is to step through Sonar code, which I'm not eager to do.   Any pointers as to what's wrong would be appreciated.
Thanks.
Comment: I know this doesn't address your question directly, but you should seriously consider hosting your Sonar database in something other than H2. I've done this on one project and after a couple of days Sonar analysis time went up from 1 to 5 minutes and it was getting worse by the day :)
Comment: Now that I think of it, is your Maven plugin version aligned with your Sonar install?
Comment: @Spiff -- that is it.  I hadn't set the sonar plugin version in the pom, and about a week ago maven picked up 3.6-RC1, while my server was still running 3.5.1.  Simple fix, frustrating error message though.  If you put your comment as the answer, I'm happy to select it.
Comment: Glad to see it's working!
Answer: Your Maven plugin version is probably not aligned with your Sonar install.

Sonar in Maven build stopped working


Modify next element in array during foreach() loop

Question: How can I modify the next element in a foreach() loop, during the loop? I think it has something to do with talking to the variable by reference but I'm not sure how. i.e.:
$arr = array( array('color' => 'red',    'type' => 'apple'),
              array('color' => 'yellow', 'type' => 'banana'),
              array('color' => 'purple', 'type' => 'grape')
            );

foreach($arr as $k => $v) {
   echo "
 The ".$v['type'].' fruit is '.$v['color'];

   // change the color of the next fruit?
   if($v['type'] == 'apple') { $arr[$k+1]['color'] = 'green'; }
}

I'd like this to tell me the banana is green, but it stubbornly sticks to the banana being yellow...
(UPDATE: fixed a stupid logic error in my original question. The answer marked below is correct.)
Answer: foreach loops through an array by taking a copy of the array and not by reference. You need to loop through the array by reference using the ampersand & on the array value.
foreach($arr as $k => &$v) {
   echo "
 The ".$v['type'].' fruit is '.$v['color'];

   // change the color of the next fruit?
   if($v['type'] == 'banana') { $arr[$k+1]['color'] = 'green'; }
}

Comment: Well, I don't know. Using the reference solves the programming error. But he also stated *I'd like this to tell me the banana is green*, in which case he also has a logic error. But your answer should get him to the right track.
Comment: That's only one part of the solution (but nevertheless very important one). When `$v['type'] == 'banana'` is true, the next fruit which is modified is `grape`. If the banana should be green it must be `$v['type'] == 'apple'`.
Comment: I misread, I assumed when the original poster was refering to the next element he meant to change the color of the grape to green.
Comment: Oops, my bad on the logic (I wrote that script quickly here on StackOverflow without actually testing it)... but you understood what I was after and your answer is working for me, so... thanks!
Answer: $k=array_keys($yourarray);
    for($i=0; $i<sizeof ($k); $i++) {
       if($yourarray[$k[$i]] == "something") {
           $yourarray[$k[$i+1]] = "something else";
       }
    }
}

sorry formatting is all wonky as i am replying from a phone...
Answer: The counter has to remain the same
$arr = array( array('color' => 'red',    'type' => 'apple'),
          array('color' => 'yellow', 'type' => 'banana'),
          array('color' => 'purple', 'type' => 'grape')
        );

foreach($arr as $k => $v) {
  echo "
 The ".$v['type'].' fruit is '.$v['color'];

  // change the color of the next fruit?
  if($v['type'] == 'banana') { $arr[$k]['color'] = 'green'; }

  // now echo the new color from the original array
   echo "
 The ".$arr[$k]['type'].' fruit is now '.$arr[$k]['color'];
}


using og:video for facebook

Question: I'm trying to set up my video in og:video on my site so that when someone shares the link in facebook it shows the video instead of the og:image.
The problem is that it requires a flash player url, but I don't have the slightest idea how to get that to work. All I have is the .mp4 file. I tried looking into jwplayer but all I got was an embed code which doesn't help.
I'm completely ignorant when it comes to this area. Any help would be greatly appreciated!
<meta property="og:video" content="https://???">
<meta property="og:video:height" content="281" />
<meta property="og:video:width" content="500" />
<meta property="og:video:type" content="application/x-shockwave-flash" />

Answer: Originally Facebook accepted only Flash videos, but recently HTML5 support was added, so you can use the following:
<meta property="og:video" content="path_to_video.mp4" />
<meta property="og:video:type" content="video/mp4" />

<meta property="og:video" content="fallback/?video=path_to_video.mp4" />
<meta property="og:video:type" content="text/html" />

As you can see you can define multiple sources of a video with alternative types. Url fallback/?video=... should point to an empty page with embedded flas player in it which will read video path from the url (eg. using PHP or JS) and play it.
For this purpose you can use some free Flash video player... look here:  http://www.instantshift.com/2010/05/14/21-free-video-players-for-your-website-and-blogs/
Comment: Thank you for your response. The link you provided seems to go to a blank page. ANy idea why?
Comment: Are you sure? The link http://www.instantshift.com/2010/05/14/21-free-video-players-for-your-website-and-blogs/ work to me just fine (even now).

using og:video for facebook


Parse XML with SAX in java, case insensitive.

Question: I can parse xml just fine with SAXParserFactory in Java, BUT in some files,
there are some non-lowercase attributes present, like linear3D="0.5" etc.
I would like to somehow make
attributes.getValue(attr)

case-insensitive, so that attributes.getValue("linear3d") returns "0.5".
One solution would be to read the file as a string first, convert to lowercase, and then parse,
since there is no ambiguity in doing this in this type of xml.
However, can this be done more simply, by adding some flag to the factory or similar?
Comment: You should rather change your model. XML is case-sensitive. Don't go against conventions.
Comment: Well, unfortunantely, I am trying to parse .flame files, which almost fulfils .xml standards. I do not have control over its syntax, since they are created by a 3rd party software.
Comment: What does that mean? You don't have any guarantee that it will always linear3d or linear3D?
Comment: Well, in theory, it is probably always linear3D, however, attributes are 1-to-1 in correspondence with class files, and following Java standard, these should be capitalized. A solution would be to rename my Linear3d class to Linear3D...
Comment: You should really normalize class and fields names rather than transforming the XML files over and over again.
Answer: Instead of converting the entire file in to lower case the following approach is better. This iterates through all the attributes of the selected tag and comperes it ignoring the case.
Inside the implementaion of DefaultHandler write the following method
private String getValueIgnoreCase(Attributes attributes, String qName){
    for(int i = 0; i < attributes.getLength(); i++){
        String qn = attributes.getQName(i);
        if(qn.equalsIgnoreCase(qName)){
            return attributes.getValue(i);
        }
    }
    return null;
}


How to solve $\frac{y''}{y} = -\frac{2}{9x^2}$ without guessing?

Question: I want to solve the second-order differential equation
$$ \frac{y''}{y} = -\frac{2}{9x^2} $$
By trial and error, I found that $y=x^{1/3}$ and $y=x^{2/3}$ satisfy the equation. So, all solutions are of the form $y = ax^{1/3} + bx^{2/3}$ as long as $y\not= 0$.
How could I go about solving a differential equation like this analytically?
Comment: Have you tried separation of variables and integrating twice?
Comment: @Ziryerx Yes, I did, I got $(\ln(y)-1)y = \frac{2}{9}\ln(x)$ and didn't know how to proceed from there.
Comment: Perhaps one of $y$ is $y'$.
Comment: you can use frobenius method
Comment: @MyGlasses  In the original problem, no, it's definitely $y''$. I didn't come across this problem for a math class--I encountered it while reading physics
Comment: furthermore note that $(x^a)''$ yields $a (a-1)x^{(a-2)}$ which makes a solution of this type quiet plausible (since the rhs is also a simple power of x)
Answer: This is a Cauchy-Euler equation.
Putting it in that form:
$$9x^2 \frac{d^2y}{dx^2}+2y=0$$
You can use the ansatz $y=x^{\lambda}$:
$$\frac{dy}{dx}=\lambda x^{\lambda-1}$$
$$\frac{d^2y}{dx^2}=\lambda(\lambda-1)x^{\lambda-2}$$
To obtain the polynomial:
$$9\lambda^2-9\lambda+2=0$$
Comment: Thanks, I will accept this as soon as I can. Out of curiosity, are there any slightly more general methods for non Cauchy-Euler equations? I.e. what if the right hand side was $-\frac{9}{2x^3}$
Comment: elegant! ($+1$)...
Comment: @aras In that case, I do not know. I checked [Wolfram|Alpha](http://www.wolframalpha.com/input/?i=y%27%27%2Fy%3D-9%2F(2x%5E3)) and saw that it would be in terms of [Bessel Functions](https://en.wikipedia.org/wiki/Bessel_function) of the first and second kind.
Comment: Isn't an ansatz simply a guess?
Comment: @Dr.MV Well, strictly speaking it is. However, I think the OP means 'guessing' in the context of trial-and-error.
Comment: @projectilemotion (+1) for the post
Comment: @TheGreatDuck Your statement is false.  There are a host of methodologies that are not "sort of guesswork."  Aside from that, I up voted the answer.
Comment: @TheGreatDuck Do you need to guess anything about the solution to the ODE $$y'(t)+\mu(t)y(t)=f(t)$$with $y(0)=y_0$?  And the method of Frobenius isn't really guess work,, is it? And use of Green (of Green's if you prefer) function is not guess work.  And Fourier series expansions is not guess work.  What are you talking about?
Comment: @TheGreatDuck I listed (1) the method of Frobenius, (2) Green (Green's) Functions, and (3) Fourier series expansions. Why are you asking about Laplace Transforms?
Comment: @projectilemotion Hm, interesting. Thank you for your help!
Comment: @TheGreatDuck The other methodologies that I referenced apply to higher-order differential equations.


Implementing a module system with Android in-app purchases

Question: I have a question regarding in-app purchases in Android. But first off, a little bit of information about what I am trying to do...
My app has a collection of "modules" that are arranged in a SQLite database arranged like this. These modules are differentiated simply by a column that designates what module that particular entry belongs to. What I want to do, is create an in-app purchase system where the user can download additional "modules" of content.
What is the best way to arrange and handle this data? Is it a good idea to keep the database setup and somehow implement a system where the in-app purchase adds to the database? Is it possible to keep track of this in the case that the user deletes the app or app data? I want to make this system as dynamic as possible, so that the user is not shown a message saying there is additional content available if they have already purchased and installed it.
The development on my app has not begun yet, so any other arrangement of data can easily be explored. For reference purposes, each "module" will have about 50-60 entries, and the plan is to have anywhere between 5-20 "modules" so there will be a good chunk of data.
Sorry for the plethora of questions all at once. If you need any screenshots to get a better idea of the data, or if I didn't do a good enough job in explaining what I am trying to do, please let me know!
Answer: For me it sounds like you need user accounts serverside. There you keep track of the necessary things about the user, like what he/she has bought, etc. In other words, the database is in a remote place, not in the app, so you can delete and reinstall as you wish and the data is still available.
In order to identify the users, this will help: http://developer.android.com/training/id-auth/identify.html
Comment: Hi, thanks for your reply. Is it also possible to keep track of the user's purchases through their account they are using for the market? For example, when you buy an Android phone, and if you don't have a Gmail account, the OS let's you create one to sync and use Google Play. Perhaps it is possible to differentiate who purchased what with a quick check to a server with that account? I want to avoid implementing a login system just set, as from my experience it does put off a user quite a bit from the get go.
Comment: Sorry for the double comment...ran out of space...So what about the data itself? Let's say I figure out a way to check what data the user is supposed to have. Then, should it all be stored in a local database (makes the app usable offline) and should the data be added to the database with the purchase? I guess my question is, what form does the purchase take? Is it simply a SQLite additional table? And how to make the application recognize any new tables put in without having to give the app an update itself? Thanks!
Comment: You are right with the first comment, I searched and found this: http://developer.android.com/training/id-auth/identify.html it will probably be useful.
Comment: I don't understand fully the questions in the second comment. Just think about which data makes sense to be stored locally and which remotely. Main differences, locally you can access offline, remote not. Locally the access is faster. Locally will be removed / not available if the user removes the app, or reset the device, or use another device, remotely you control if and when the data is deleted.
Comment: Databases are just a way to persist data, the exact form of it depends of what exactly you need. It can be only an additional column in an existing table, or a new table... depends what exactly you want to track. How to know if there's new data, well, you don't have to update the app, of course, you just need to query the database (whereever it is). You could just need to save in a database the ids of the bought modules, and show notification of new content available only when the id of the content is not in the database... etc.


Stepwise binary logit regression - help for bootstrapping in Stata

Question: I am running a stepwise binary logit regression in Stata using 14 independent variables. Two of the independent variables are dummies (assuming a value of 0 or 1). I've tested the independent variables for multicollinearity and adapted them by standardizing or using the natural logarithm of their values in order to mitigate this issue (VIF<2.5). The normal model runs smoothly; however, when I want to bootstrap the sample (# of observations: 73) with 1000 replications I receive p-values of 1.0000. Furthermore, the results conclude with the note: "one or more parameters could not be estimated in 314 bootstrap replicates; standard-error estimates include only complete replications."
Two questions:
1. Is the VIF threshold that I used correct (VIF<2.5)? Which other ways are there to get rid of multicollinearity, without dropping one of the variables?
2. Since I don't assume that multicollinearity is an issue anymore, what else could I have done wrong concerning my bootstraping methodology?
Many thanks in advance for your answer(s)!
Best!
Tim
Comment: Your approach is not honest about the number of parameters estimated.  The transformation estimation process needs to be part of the bootstrap as does every other modeling step that utilized $Y$.  Collinearity on the other handle, can often ignore $Y$ and can be dealt with pre-outcome modeling.  There is no need to compute $P$-values using the bootstrap as you already have those from the original model fit.
Comment: Frank, thanks a lot for your quick reply. To put it into the words of a layperson: this means that I do not need to bootstrap my sample? Isn't the initial sample size of 73 too small to receive appropriate results?
Furthermore, what do you mean by "not honest"? That the transformations I chose are not consistent with each other? Unfortunately, the issue of multicollinearity appears when I use a consistent approach.
Comment: You are effectively estimating several more parameters when you try different transformations.  You need to let the bootstrap repeate *from scratch* all the modeling steps each time, including examining transformations. [This is why just fitting regression splines if often a great approach.  The bootstrap just refits the regression splines for each re-sample.]
Comment: Concerning your question about $n=73$, I wouldn't expect the bootstrap to improve on the accuracy.
Answer: Consider not doing stepwise resgression, which is a good way to almost insure biased results:
Malek, M. H. and Coburn, D. E. B. J. W. (2007). On the inappropriateness of stepwise regression analysis for model building and testing. European Journal of Applied Physiology, 101(2):263–264.
Steyerberg, E. W., Eijkemans, M. J., and Habbema, J. D. F. (1999). Stepwise selection in small data sets: a simulation study of bias in logistic regression analysis. Journal of clinical epidemiology, 52(10):935–942.
Whittingham, M., Stephens, P., Bradbury, R., and Freckleton, R. (2006). Why do we still use stepwise modelling in ecology and behaviour? Journal of Animal Ecology, 75(5):1182–1189.
Comment: Alexis, thanks for your answer. However, and since I am applying backward stepwise regression, I already include all of the independent variables in my first model which yields the described results for the bootstrapped sample.
Comment: Which does not get you around the fact that you are, among other things, selecting for the most heteroscedastic predictors.


Using typedef in class for its own struct data

Question: I am creating a new class. The class declares a struct variable, cs, which is used in all functions of the class. Some of the return variable of the functions in the class are of type cs *. In below, is the content of CSparse.h.
#ifndef _CSPARSE_H
#define _CSPARSE_H

#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stddef.h>
#ifdef MATLAB_MEX_FILE
#include "mex.h"
#endif
#define CS_VER 3                    /* CSparse Version */
#define CS_SUBVER 1
#define CS_SUBSUB 2
#define CS_DATE "April 16, 2013"    /* CSparse release date */
#define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2013"

#ifdef MATLAB_MEX_FILE
#undef csi
#define csi mwSignedIndex
#endif
#ifndef csi
#define csi ptrdiff_t
#endif

class CSparse
{
public:
    CSparse(void);
    virtual ~CSparse(void);

    /* --- primary CSparse routines and data structures ------------------------- */
    typedef struct csparse     /* matrix in compressed-column or triplet form */
    {
        csi nzmax ;     /* maximum number of entries */
        csi m ;         /* number of rows */
        csi n ;         /* number of columns */
        csi *p ;        /* column pointers (size n+1) or col indices (size nzmax) */
        csi *i ;        /* row indices, size nzmax */
        double *x ;     /* numerical values, size nzmax */
        csi nz ;        /* # of entries in triplet matrix, -1 for compressed-col */
    } cs;

    cs    *cs_add (const cs *A, const cs *B, double alpha, double beta) ;
    csi    cs_cholsol (csi order, const cs *A, double *b) ;
    cs    *cs_compress (const cs *T) ;
    csi    cs_dupl (cs *A) ;
    csi    cs_entry (cs *T, csi i, csi j, double x) ;
    csi    cs_gaxpy (const cs *A, const double *x, double *y) ;
    cs    *cs_load (FILE *f) ;
    csi    cs_lusol (csi order, const cs *A, double *b, double tol) ;
    cs    *cs_multiply (const cs *A, const cs *B) ;
    double cs_norm (const cs *A) ;
    csi    cs_print (const cs *A, csi brief) ;
    csi    cs_qrsol (csi order, const cs *A, double *b) ;
    cs    *cs_transpose (const cs *A, csi values) ;

    /* utilities */
    void  *cs_calloc (csi n, size_t size) ;
    void  *cs_free (void *p) ;
    void  *cs_realloc (void *p, csi n, size_t size, csi *ok) ;
    cs    *cs_spalloc (csi m, csi n, csi nzmax, csi values, csi triplet) ;
    cs    *cs_spfree (cs *A) ;
    csi    cs_sprealloc (cs *A, csi nzmax) ;
    void  *cs_malloc (csi n, size_t size) ;

private:
    /* --- secondary CSparse routines and data structures ----------------------- */
    typedef struct cs_symbolic  /* symbolic Cholesky, LU, or QR analysis */
    {
        csi *pinv ;     /* inverse row perm. for QR, fill red. perm for Chol */
        csi *q ;        /* fill-reducing column permutation for LU and QR */
        csi *parent ;   /* elimination tree for Cholesky and QR */
        csi *cp ;       /* column pointers for Cholesky, row counts for QR */
        csi *leftmost ; /* leftmost[i] = min(find(A(i,:))), for QR */
        csi m2 ;        /* # of rows for QR, after adding fictitious rows */
        double lnz ;    /* # entries in L for LU or Cholesky; in V for QR */
        double unz ;    /* # entries in U for LU; in R for QR */
    } css;

    typedef struct cs_numeric   /* numeric Cholesky, LU, or QR factorization */
    {
        cs *L ;         /* L for LU and Cholesky, V for QR */
        cs *U ;         /* U for LU, R for QR, not used for Cholesky */
        csi *pinv ;     /* partial pivoting for LU */
        double *B ;     /* beta [0..n-1] for QR */
    } csn;

    typedef struct cs_dmperm     /* cs_dmperm or cs_scc output */
    {
        csi *p ;        /* size m, row permutation */
        csi *q ;        /* size n, column permutation */
        csi *r ;        /* size nb+1, block k is rows r[k] to r[k+1]-1 in A(p,q) */
        csi *s ;        /* size nb+1, block k is cols s[k] to s[k+1]-1 in A(p,q) */
        csi nb ;        /* # of blocks in fine dmperm decomposition */
        csi rr [5] ;    /* coarse row decomposition */
        csi cc [5] ;    /* coarse column decomposition */
    } csd;

    csi *cs_amd (csi order, const cs *A) ;
    csn *cs_chol (const cs *A, const css *S) ;
    csd *cs_dmperm (const cs *A, csi seed) ;
    csi  cs_droptol (cs *A, double tol) ;
    csi  cs_dropzeros (cs *A) ;
    csi  cs_happly (const cs *V, csi i, double beta, double *x) ;
    csi  cs_ipvec (const csi *p, const double *b, double *x, csi n) ;
    csi  cs_lsolve (const cs *L, double *x) ;
    csi  cs_ltsolve (const cs *L, double *x) ;
    csn *cs_lu (const cs *A, const css *S, double tol) ;
    cs  *cs_permute (const cs *A, const csi *pinv, const csi *q, csi values) ;
    csi *cs_pinv (const csi *p, csi n) ;
    csi  cs_pvec (const csi *p, const double *b, double *x, csi n) ;
    csn *cs_qr (const cs *A, const css *S) ;
    css *cs_schol (csi order, const cs *A) ;
    css *cs_sqr (csi order, const cs *A, csi qr) ;
    cs  *cs_symperm (const cs *A, const csi *pinv, csi values) ;
    csi  cs_updown (cs *L, csi sigma, const cs *C, const csi *parent) ;
    csi  cs_usolve (const cs *U, double *x) ;
    csi  cs_utsolve (const cs *U, double *x) ;
    /* utilities */
    css *cs_sfree (css *S) ;
    csn *cs_nfree (csn *N) ;
    csd *cs_dfree (csd *D) ;

    /* --- tertiary CSparse routines -------------------------------------------- */
    csi   *cs_counts (const cs *A, const csi *parent, const csi *post, csi ata) ;
    double cs_cumsum (csi *p, csi *c, csi n) ;
    csi    cs_dfs (csi j, cs *G, csi top, csi *xi, csi *pstack, const csi *pinv) ;
    csi    cs_ereach (const cs *A, csi k, const csi *parent, csi *s, csi *w) ;
    csi   *cs_etree (const cs *A, csi ata) ;
    csi    cs_fkeep (cs *A, csi (*fkeep) (csi, csi, double, void *), void *other) ;
    double cs_house (double *x, double *beta, csi n) ;
    csi    cs_leaf (csi i, csi j, const csi *first, csi *maxfirst, csi *prevleaf,
                    csi *ancestor, csi *jleaf) ;
    csi   *cs_maxtrans (const cs *A, csi seed) ;
    csi   *cs_post (const csi *parent, csi n) ;
    csi   *cs_randperm (csi n, csi seed) ;
    csi    cs_reach (cs *G, const cs *B, csi k, csi *xi, const csi *pinv) ;
    csi    cs_scatter (const cs *A, csi j, double beta, csi *w, double *x, csi mark,
                       cs *C, csi nz) ;
    csd   *cs_scc (cs *A) ;
    csi    cs_spsolve (cs *G, const cs *B, csi k, csi *xi, double *x,
        const csi *pinv, csi lo) ;
    csi    cs_tdfs (csi j, csi k, csi *head, const csi *next, csi *post,
                    csi *stack) ;
    /* utilities */
    csd   *cs_dalloc (csi m, csi n) ;
    csd   *cs_ddone (csd *D, cs *C, void *w, csi ok) ;
    cs    *cs_done (cs *C, void *w, void *x, csi ok) ;
    csi   *cs_idone (csi *p, cs *C, void *w, csi ok) ;
    csn   *cs_ndone (csn *N, cs *C, void *w, void *x, csi ok) ;

    #define CS_MAX(a,b) (((a) > (b)) ? (a) : (b))
    #define CS_MIN(a,b) (((a) < (b)) ? (a) : (b))
    #define CS_FLIP(i) (-(i)-2)
    #define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i))
    #define CS_MARKED(w,j) (w [j] < 0)
    #define CS_MARK(w,j) { w [j] = CS_FLIP (w [j]) ; }
    #define CS_CSC(A) (A && (A->nz == -1))
    #define CS_TRIPLET(A) (A && (A->nz >= 0))
};
#endif

Here is the content of CSparse.cpp
#include "CSparse.h"

CSparse::CSparse(void)
{
}

CSparse::~CSparse(void)
{
}

/* remove duplicate entries from A */
csi CSparse::cs_dupl (cs *A)
{
    csi i, j, p, q, nz = 0, n, m, *Ap, *Ai, *w ;
    double *Ax ;
    if (!CS_CSC (A)) return (0) ;               /* check inputs */
    m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
    w = (csi* ) cs_malloc (m, sizeof (csi)) ;           /* get workspace */
    if (!w) return (0) ;                        /* out of memory */
    for (i = 0 ; i < m ; i++) w [i] = -1 ;      /* row i not yet seen */
    for (j = 0 ; j < n ; j++)
    {
        q = nz ;                                /* column j will start at q */
        for (p = Ap [j] ; p < Ap [j+1] ; p++)
        {
            i = Ai [p] ;                        /* A(i,j) is nonzero */
            if (w [i] >= q)
            {
                Ax [w [i]] += Ax [p] ;          /* A(i,j) is a duplicate */
            }
            else
            {
                w [i] = nz ;                    /* record where row i occurs */
                Ai [nz] = i ;                   /* keep A(i,j) */
                Ax [nz++] = Ax [p] ;
            }
        }
        Ap [j] = q ;                            /* record start of column j */
    }
    Ap [n] = nz ;                               /* finalize A */
    cs_free (w) ;                               /* free workspace */
    return (cs_sprealloc (A, 0)) ;              /* remove extra space from A */
}

/* C = A' */
cs* CSparse::cs_transpose (const cs *A, csi values) // THIS IS THE LINE WHERE THE FIRST ERROR APPREARS.
{
    csi p, q, j, *Cp, *Ci, n, m, *Ap, *Ai, *w ;
    double *Cx, *Ax ;
    cs *C ;
    if (!CS_CSC (A)) return (NULL) ;    /* check inputs */
    m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ;
    C = cs_spalloc (n, m, Ap [n], values && Ax, 0) ;       /* allocate result */
    w = (csi *) cs_calloc (m, sizeof (csi)) ;                      /* get workspace */
    if (!C || !w) return (cs_done (C, w, NULL, 0)) ;       /* out of memory */
    Cp = C->p ; Ci = C->i ; Cx = C->x ;
    for (p = 0 ; p < Ap [n] ; p++) w [Ai [p]]++ ;          /* row counts */
    cs_cumsum (Cp, w, m) ;                                 /* row pointers */
    for (j = 0 ; j < n ; j++)
    {
        for (p = Ap [j] ; p < Ap [j+1] ; p++)
        {
            Ci [q = w [Ai [p]]++] = j ; /* place A(i,j) as entry C(j,i) */
            if (Cx) Cx [q] = Ax [p] ;
        }
    }
    return (cs_done (C, w, NULL, 1)) ;  /* success; free w and return C */
}

/* C = compressed-column form of a triplet matrix T */
cs *CSparse::cs_compress (const cs *T)
{
    csi m, n, nz, p, k, *Cp, *Ci, *w, *Ti, *Tj ;
    double *Cx, *Tx ;
    cs *C ;
    if (!CS_TRIPLET (T)) return (NULL) ;                /* check inputs */
    m = T->m ; n = T->n ; Ti = T->i ; Tj = T->p ; Tx = T->x ; nz = T->nz ;
    C = cs_spalloc (m, n, nz, Tx != NULL, 0) ;          /* allocate result */
    w = (csi *) cs_calloc (n, sizeof (csi)) ;                   /* get workspace */
    if (!C || !w) return (cs_done (C, w, NULL, 0)) ;    /* out of memory */
    Cp = C->p ; Ci = C->i ; Cx = C->x ;
    for (k = 0 ; k < nz ; k++) w [Tj [k]]++ ;           /* column counts */
    cs_cumsum (Cp, w, n) ;                              /* column pointers */
    for (k = 0 ; k < nz ; k++)
    {
        Ci [p = w [Tj [k]]++] = Ti [k] ;    /* A(i,j) is the pth entry in C */
        if (Cx) Cx [p] = Tx [k] ;
    }
    return (cs_done (C, w, NULL, 1)) ;      /* success; free w and return C */
}

/* allocate a sparse matrix (triplet form or compressed-column form) */
cs *CSparse::cs_spalloc (csi m, csi n, csi nzmax, csi values, csi triplet)
{
    cs *A = (cs *) cs_calloc (1, sizeof (cs)) ;    /* allocate the cs struct */
    if (!A) return (NULL) ;                 /* out of memory */
    A->m = m ;                              /* define dimensions and nzmax */
    A->n = n ;
    A->nzmax = nzmax = CS_MAX (nzmax, 1) ;
    A->nz = triplet ? 0 : -1 ;              /* allocate triplet or comp.col */
    A->p = (csi *) cs_malloc (triplet ? nzmax : n+1, sizeof (csi)) ;
    A->i = (csi *) cs_malloc (nzmax, sizeof (csi)) ;
    A->x = values ? (double *) cs_malloc (nzmax, sizeof (double)) : NULL ;
    return ((!A->p || !A->i || (values && !A->x)) ? cs_spfree (A) : A) ;
}

/* change the max # of entries sparse matrix */
csi CSparse::cs_sprealloc (cs *A, csi nzmax)
{
    csi ok, oki, okj = 1, okx = 1 ;
    if (!A) return (0) ;
    if (nzmax <= 0) nzmax = (CS_CSC (A)) ? (A->p [A->n]) : A->nz ;
    A->i = (csi *) cs_realloc (A->i, nzmax, sizeof (csi), &oki) ;
    if (CS_TRIPLET (A)) A->p = (csi *) cs_realloc (A->p, nzmax, sizeof (csi), &okj) ;
    if (A->x) A->x = (double *) cs_realloc (A->x, nzmax, sizeof (double), &okx) ;
    ok = (oki && okj && okx) ;
    if (ok) A->nzmax = nzmax ;
    return (ok) ;
}

/* free a sparse matrix */
cs *CSparse::cs_spfree (cs *A)
{
    if (!A) return (NULL) ;     /* do nothing if A already NULL */
    cs_free (A->p) ;
    cs_free (A->i) ;
    cs_free (A->x) ;
    return ((cs *) cs_free (A)) ;   /* free the cs struct and return NULL */
}

/* free a numeric factorization */
csn *CSparse::cs_nfree (csn *N)
{
    if (!N) return (NULL) ;     /* do nothing if N already NULL */
    cs_spfree (N->L) ;
    cs_spfree (N->U) ;
    cs_free (N->pinv) ;
    cs_free (N->B) ;
    return ((csn *) cs_free (N)) ;  /* free the csn struct and return NULL */
}

/* free a symbolic factorization */
css *CSparse::cs_sfree (css *S)
{
    if (!S) return (NULL) ;     /* do nothing if S already NULL */
    cs_free (S->pinv) ;
    cs_free (S->q) ;
    cs_free (S->parent) ;
    cs_free (S->cp) ;
    cs_free (S->leftmost) ;
    return ((css *) cs_free (S)) ;  /* free the css struct and return NULL */
}

/* allocate a cs_dmperm or cs_scc result */
csd *CSparse::cs_dalloc (csi m, csi n)
{
    csd *D ;
    D = (csd *) cs_calloc (1, sizeof (csd)) ;
    if (!D) return (NULL) ;
    D->p = (csi *) cs_malloc (m, sizeof (csi)) ;
    D->r = (csi *) cs_malloc (m+6, sizeof (csi)) ;
    D->q = (csi *) cs_malloc (n, sizeof (csi)) ;
    D->s = (csi *) cs_malloc (n+6, sizeof (csi)) ;
    return ((!D->p || !D->r || !D->q || !D->s) ? cs_dfree (D) : D) ;
}

/* free a cs_dmperm or cs_scc result */
csd *CSparse::cs_dfree (csd *D)
{
    if (!D) return (NULL) ;     /* do nothing if D already NULL */
    cs_free (D->p) ;
    cs_free (D->q) ;
    cs_free (D->r) ;
    cs_free (D->s) ;
    return ((csd *) cs_free (D)) ;  /* free the csd struct and return NULL */
}

/* free workspace and return a sparse matrix result */
cs *CSparse::cs_done (cs *C, void *w, void *x, csi ok)
{
    cs_free (w) ;                       /* free workspace */
    cs_free (x) ;
    return (ok ? C : cs_spfree (C)) ;   /* return result if OK, else free it */
}

/* free workspace and return csi array result */
csi *CSparse::cs_idone (csi *p, cs *C, void *w, csi ok)
{
    cs_spfree (C) ;                     /* free temporary matrix */
    cs_free (w) ;                       /* free workspace */
    return (ok ? p : (csi *) cs_free (p)) ; /* return result, or free it */
}

/* free workspace and return a numeric factorization (Cholesky, LU, or QR) */
csn *CSparse::cs_ndone (csn *N, cs *C, void *w, void *x, csi ok)
{
    cs_spfree (C) ;                     /* free temporary matrix */
    cs_free (w) ;                       /* free workspace */
    cs_free (x) ;
    return (ok ? N : cs_nfree (N)) ;    /* return result if OK, else free it */
}

/* free workspace and return a csd result */
csd *CSparse::cs_ddone (csd *D, cs *C, void *w, csi ok)
{
    cs_spfree (C) ;                     /* free temporary matrix */
    cs_free (w) ;                       /* free workspace */
    return (ok ? D : cs_dfree (D)) ;    /* return result if OK, else free it */
}

/* wrapper for malloc */
void *CSparse::cs_malloc (csi n, size_t size)
{
    return (malloc (CS_MAX (n,1) * size)) ;
}

/* wrapper for calloc */
void *CSparse::cs_calloc (csi n, size_t size)
{
    return (calloc (CS_MAX (n,1), size)) ;
}

/* wrapper for free */
void *CSparse::cs_free (void *p)
{
    if (p) free (p) ;       /* free p if it is not already NULL */
    return (NULL) ;         /* return NULL to simplify the use of cs_free */
}

/* wrapper for realloc */
void *CSparse::cs_realloc (void *p, csi n, size_t size, csi *ok)
{
    void *pnew ;
    pnew = realloc (p, CS_MAX (n,1) * size) ; /* realloc the block */
    *ok = (pnew != NULL) ;                  /* realloc fails if pnew is NULL */
    return ((*ok) ? pnew : p) ;             /* return original p if failure */
}

/* p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c */
double CSparse::cs_cumsum (csi *p, csi *c, csi n)
{
    csi i, nz = 0 ;
    double nz2 = 0 ;
    if (!p || !c) return (-1) ;     /* check inputs */
    for (i = 0 ; i < n ; i++)
    {
        p [i] = nz ;
        nz += c [i] ;
        nz2 += c [i] ;              /* also in double to avoid csi overflow */
        c [i] = p [i] ;             /* also copy p[0..n-1] back into c[0..n-1]*/
    }
    p [n] = nz ;
    return (nz2) ;                  /* return sum (c [0..n-1]) */
}

/* C = alpha*A + beta*B */
cs *CSparse::cs_add (const cs *A, const cs *B, double alpha, double beta)
{
    csi p, j, nz = 0, anz, *Cp, *Ci, *Bp, m, n, bnz, *w, values ;
    double *x, *Bx, *Cx ;
    cs *C ;
    if (!CS_CSC (A) || !CS_CSC (B)) return (NULL) ;         /* check inputs */
    if (A->m != B->m || A->n != B->n) return (NULL) ;
    m = A->m ; anz = A->p [A->n] ;
    n = B->n ; Bp = B->p ; Bx = B->x ; bnz = Bp [n] ;
    w = (csi *) cs_calloc (m, sizeof (csi)) ;                       /* get workspace */
    values = (A->x != NULL) && (Bx != NULL) ;
    x = values ? (double *) cs_malloc (m, sizeof (double)) : NULL ;    /* get workspace */
    C = cs_spalloc (m, n, anz + bnz, values, 0) ;           /* allocate result*/
    if (!C || !w || (values && !x)) return (cs_done (C, w, x, 0)) ;
    Cp = C->p ; Ci = C->i ; Cx = C->x ;
    for (j = 0 ; j < n ; j++)
    {
        Cp [j] = nz ;                   /* column j of C starts here */
        nz = cs_scatter (A, j, alpha, w, x, j+1, C, nz) ;   /* alpha*A(:,j)*/
        nz = cs_scatter (B, j, beta, w, x, j+1, C, nz) ;    /* beta*B(:,j) */
        if (values) for (p = Cp [j] ; p < nz ; p++) Cx [p] = x [Ci [p]] ;
    }
    Cp [n] = nz ;                       /* finalize the last column of C */
    cs_sprealloc (C, 0) ;               /* remove extra space from C */
    return (cs_done (C, w, x, 1)) ;     /* success; free workspace, return C */
}

The first error I get is the following.
1>.\CSparse.cpp(46) : error C2143: syntax error : missing ';' before '*'

I have marked the error location in the source code above. It happens in the definition of cs* CSparse::cs_transpose (const cs *A, csi values).
After searching online, I found out that this is the problem with the scope of the typedef. Therefore, I had to adjust the returned type of the functions in CSparse.cpp. For example, I changed
cs* CSparse::cs_transpose (const cs *A, csi values)

to
CSparse::cs* CSparse::cs_transpose (const cs *A, csi values)

and it worked fine. Is there a better way of doing this? Why this problem is for the returned variable of the function and function arguments do not cause any problem. For example, in the function cs_transpose, A as well as function return variable is of type cs but only the function return causes the compiler to complain. Also, for some reasons, I could not use using namespace.
Could someone help me find the right solution for this problem?
Answer: It seems to me that you just forgot a ; at the end of your class myClass.
Beside, you don't need to typedef your struct, it could be:
struct ms {
    double d;
    double* pd;
};

ms *myfunction(void);

Comment: Antonio: I did so. However, at the line where I define `ms *myfunction(void)` in `myClass.cpp`, I get an error sayig `error C2143: syntax error : missing ';' before '*'`
Comment: @Ahmad This is a wild guess... Maybe `ms` is a reserved word in your compiler? Can you try to give to your struct a different name? Are you sure you put all semicolons `;` after the closing brace at end of all your structs and classes?
Comment: Antonio: I checked the semicolons. Is there any other thing that I can double check?
Comment: @Ahmad Try to post again your current code (edit your question, but leave your original text and append at the end your new code. You can also try your code at this link here http://coliru.stacked-crooked.com/ and post a link here/in your updated question. BTW, I am now going to bed...
Comment: @Ahmad The solution you found is correct. And, as long as I am aware, you cannot use namespaces for access a class namespace.