Couldn't we have defined the material conditional differently?

Question: I've been mulling this over lately, and I can't seem to understand why exactly the material conditional wasn't defined in a completely different way.
Obviously, the motivation behind our current definition of the material conditional is, amongst others, so that we don't end up with a definition that makes most restricted quantifiers impossible to work with. For example, take two triangles. A triangle is called equilateral if the lengths of its three sides are the same, whereas a triangle is defined to be isosceles if two of its three sides have the same length. We know then, by definition, that any equilateral triangle is also an isosceles triangle.
With this in mind, we can set up the following implication where $P(T)$ and $Q(T)$ are open sentences over the domain S of all triangles:
$$P(T): T \; \textit{is equilateral.} \; \text{and} \; Q(T): T \; \textit{is isosceles.}$$
$$P(T) \implies Q(T)$$
This implication should then be required to hold true for all triangles $T$ that are equilateral, so we could write:
$$\forall \, T, \, P(T) \implies Q(T)$$
but we run into the problem of "what if T isn't equilateral?" If we choose to define the truth values of the material conditional any other way than we currently have, say by making the implication false whenever $P(T)$ is false, we'd end up with a false implication. But surely, our implication (which we know to be true by definition) can't be proven wrong by looking at triangles that the implication doesn't even deal with in the first place. Therefore, we must require this implication to be vacuously true.
However, couldn't all of this have been avoided by simply stating:
$$\forall \, T: \textit{T is equilateral}, \, P(T) \implies Q(T)$$
and assigning a false truth value to the material conditional whenever its antecedent is false? That way, we'd avoid situations like:
$$\forall x \in \mathbb{R}, \; x>2 \implies x^2>4$$
$$x=-1$$
$$\therefore (-1)^2>4$$
...situations which we know to be untrue.
I'm probably not really getting the big picture here, but it seems to me that a simple specification of the properties of a quantified statement fix the issue of quantifier incompatibility. Could somebody enlighten me?
Cheers.
Comment: You may enjoy Angelika Kratzer's paper [Conditionals](https://udrive.oit.umass.edu/kratzer/kratzer-conditionals.pdf) which discusses the material conditional and why it is interesting. It comes to the conclusion that the mathematics uses the material conditional because in a certain sense it is the _weakest possible_ form of the conditional.
Comment: I don't really get the way you are formalizing: Wouldn't $\forall T:T is equilateral,P(T)\Rightarrow Q(T)$ be saying that "Given any triangle T such that T is equilateral, if T is equilateral then T is isosceles"? Why do you condition on something that is already true in the domain of discourse? Also, from $x>2\Rightarrow x^2>4$ and $x=-1$ because $x=-1$ is not greater than 2, the "whole" implication holds true for that value but not the consequent alone ($\neg(x^2>4)$).
Answer: Your inference is wrong.
If we start with the reasonable law :

$∀x \in \mathbb R,x > 2 \to x^2 > 4$

and we instantiate it with $x=-1$, we get :

$-1 > 2 \to (-1)^2 > 4$.

But we cannot infer the false : $(-1)^2 > 4$ because, in order to do it, we have to use modus ponens, and to do this we have to assert the false : $-1 > 2$, and we have no reason to assert it.
Comment: @Luke - exactly because we want *modus ponens* to work ... If the conditional $p \to q$ is *true* **and** the antecedent $p$ is *true*, then we want to conclude with the consequent. This fact account for the case when $p$ is *true*. If we set $p \to q$ false when both are false, we have to "break" the equivalence between $p \to q$ and $¬q \to ¬p$. In conclusion, the only "debatable" case is FALSE $\to$ TRUE... but if we change only this one to false what we get is the bi-conditional : ↔.
Comment: I see, you're right. But then why is the material conditional defined the way it is? I don't get it!
Comment: Yes, but isn't the bi-conditional defined based on the material conditional? So aren't you essentially referring back to our current definition of the conditional to demonstrate the necessity to define the conditional that way? Besides, why is the equivalence between $p \implies q$ and $\lnot q \implies \lnot p$ so important?
Comment: @Luke - no, forget about *bi-conditional* and call it *equivalence*. It is quite "natural" to say that two sentences are *equivalent* when they have the same truth-value; thus, no material conditional is involved here.
Comment: @Luke : if $p \to q$ is *false* when both are *false*, we have that its *contrapositive* ; $\lnot q \to \lnot p$ will be *true* (because now both antecedent and consequent are *true*). But again, our "intuition" says that if we assert that : "if I'm more than twenty years old, then I was born earlier than 1995", for sure I can assert : "if I was born **not** earlier than 1995, then I'm **not** more than twenty years old".
Answer: The one rule that we all agree must work is modus ponens: if we have $p \Rightarrow q$ and $p$ then we must have $q$. This means that $p \Rightarrow q$ must imply $\neg (p \wedge \neg q)$. The question for us is whether this is strong enough.
To help us decide whether that is strong enough, we look at trying to extend our definition of the conditional to first order logic. That is, we turn to statements of the form
$$(\forall x \in U) \: P(x) \Rightarrow Q(x) \quad (1)$$
for predicates $P,Q$ and a domain of discourse $U$. (I ask that you do not bring up set theory issues here.) I think it is reasonable to assert that this should be equivalent to
$$(\forall x \in \{ y \in U : P(y) \}) \: P(x) \Rightarrow Q(x). \quad (2)$$
That is, the members of $U$ which don't satisfy $P$ should not have anything to do with the truth of our statement. This is one point that could possibly be disputed.
The other main philosophical assumption is that in classical logic, every well-formed statement is either true or false. This is the other main point which can be disputed. (This point really is treated differently in some nonclassical logics, such as intuitionistic logic.)
Given these two assumptions, $P(x) \Rightarrow Q(x)$ must be true whenever $P(x)$ is false, because otherwise there would exist situations where (1) is false and (2) is true. Restricting attention back to propositional logic, we get the classical definition of the material conditional.
Comment: @Luke You are asking about the first of my two assumptions, i.e. that (1) and (2) are equivalent. In my answer I assert that this is natural. Maybe an example will help with that. Let's say $U$ is the real numbers, $P(x)$ is defined as "$x$ is an integer", and $Q(x)$ is defined as "$x^2$ is an integer". Do you agree that we should have $(\forall x \in U) \: P(x) \Rightarrow Q(x)$? In natural language this should mean "if $x$ is an integer then $x^2$ is an integer".
Comment: @Luke (Cont.) If you accept this, then given the second assumption (that $P(x) \Rightarrow Q(x)$ has to have *some* truth value), $P(1/2) \Rightarrow Q(1/2)$ must be true. Similarly $P(\sqrt{2}) \Rightarrow Q(\sqrt{2})$ must be true. Yet in the first case $P$ and $Q$ both fail, while in the second case $P$ fails and $Q$ holds.
Comment: @Luke What do you think about my example in the previous two comments?
Comment: @Luke Because of the second assumption: the statements "$x$ is an integer" and "$x^2$ is an integer" are well-formed for any real number $x$, so all of them must have some truth value. So under the second assumption you cannot simply dodge the issue, you have to decide whether $P(1/2) \Rightarrow Q(1/2)$ is true or false. If we chose false, then the formalization of "for any real number $x$, if $x$ is an integer then $x^2$ is an integer" would be false. That seems awfully problematic to me.
Comment: @Luke One somewhat abstract place where this is important is when we prove a theorem in the form of an implication, where we do not know whether the hypothesis is true or false. For instance, there are a lot of theorems in modern number theory that say "if the Riemann Hypothesis is true, then ..."
Comment: @Luke Perhaps a natural language analogy will help. Suppose Bob's been having car trouble, and tells Alice "if I make it to the grocery store, I'll buy some apples". She leaves, he tries to drive to the store, but his car breaks down along the way. So he didn't make it to the grocery store and didn't buy any apples. Did Bob lie? (I repeat that in the classical framework, the answer to my question can only be yes or no.)
Comment: Alright, so that didn't help. Another case to look at: do you accept the equivalence of $p \Rightarrow q$ and $\neg q \Rightarrow \neg p$, i.e. the validity of proof by contraposition? For instance do you think that the proof at this link: http://en.wikipedia.org/wiki/Proof_by_contrapositive#Example is valid? If so, then (yet again stressing this principle that you have to "pick a side") $p \Rightarrow q$ must be true in the case where $p$ and $q$ are both false.
Comment: @Luke It's more convenient to be able to hold the domain of discourse fixed in order to prove that all members of the domain have some property, or that there exists a member of the domain with some property. This is contrary to how we operate in natural language speech, where we frequently let the domain of discourse change fluidly. Keeping complete track of all this change in the domain of discourse in logic would prove quite cumbersome.
Comment: _"P(x)⇒Q(x) must be true whenever P(x) is false, because otherwise there would exist situations where (1) is false and (2) is true."_ - how so? They're not the same statements, so you'd expect them to differ in truth values, right? (2) is essentially a statement that's only ever incorrect when the implication doesn't hold true (P not implying Q), while (1) might have a false P(x) to begin with since the domain of discourse doesn't confine our variables to only the relevant ones. I really think you're on to something here, and it's starting to make sense, so please help me through this.
Comment: Yes, but why? You assert that they _must_ be true, but I see no reason for asserting that. Why couldn't they be false instead? Moreover, I still don't see why and how (1) and (2) are equivalent. (1) has a domain of discourse containing both relevant and irrelevant variables, while (2) consists of only relevant variables.
Comment: I think it's odd that we'd say "for all real x" when dealing with a statement that's specifically about integers - why not just say "for all integers" and not have to deal with cases like $P(1/2)$ or $P(\sqrt{2})$?
Comment: If it were only possible for the implication to be either true or false, I'd consider the choice completely arbitrary. He didn't lie, but he didn't tell the truth either. We just don't know. That's why I don't understand our current definition; it just seems so arbitrary and people usually stick to just saying "well, it works". I'm not really used to maths being this random and "pointless"...
Comment: Look, to get back to the original example: "for any real number x" doesn't make sense to me. Real numbers x don't have anything to do with our statement unless they're integers. It's like involving a completely different thing; "For any elephants x, if x is an integer then x^2 is an integer". Why wouldn't we just say "for any integer x"? Why _must_ we involve things that don't have anything to do with our statements, and why are we then _forced_ to say whether they're true or not?
Comment: the contrapositive is defined in terms of our current definition of the implication, so to me it doesn't make a lot of sense to rely on that to explain why the implication is the way it is. The contrapositive of an implication is a "result" of the implication.
Comment: I see. I guess I'll just have to work with this definition then. Either way, thank you so much for all the input - I really, really appreciate the effort.
Answer:
... assigning a false truth value to the material conditional whenever its antecedent is false?

Let's approach $P \Rightarrow Q$ as a truth functional connective. I assume we agree that if $P$ and $Q$ are true, then $P \Rightarrow Q$ is true.
Also, we probably agree that if $P$ is true and $Q$ is false, then $P \Rightarrow Q$ is false.
Using that agreement, and the quoted statement, we would find that the truth table for $P \Rightarrow Q$ is the same as the truth table for "$P$ and $Q$". But nobody thinks that "if $P$ then $Q$" should have the same meaning as "$P$ and $Q$"!  So the quoted statement above can't work if we want to capture "if $P$ then $Q$".
It turns out that, based on basic reasoning about implication, we should have the following three lines of the truth table:
P  Q  P => Q
T  T   T
T  F   F
F  F   T

That only leaves one missing line: when $P$ is false and $Q$ is true. If we let $P \Rightarrow Q$ be false in that case, we obtain the following table:
P  Q  P => Q
T  T   T
T  F   F
F  F   T
F  T   F

But that table would say that $P \Rightarrow Q$ is the same as $P \Leftrightarrow Q$. Again, nobody thinks that "if $P$ then $Q$" means the same as "$P$ if and only if $Q$".
The only other option is the actual table for material implication.  So, rather than being arbitrary, the table for material implication is the only choice that matches the three unambiguous lines of the truth table and does not make $P \Rightarrow Q$ the same as $P \Leftrightarrow Q$.
Comment: But isn't that some kind of circular reasoning? The biconditional is defined based on our current definition of the implication, so arguing that the implication can't be any different from how it is now or else it would clash with the biconditional strikes me as circular reasoning. On a different note; how exactly did you arrive at the first truth table?
Comment: The first truth table contains the three lines that are relatively uncontroversial about a truth-functional connective for "if P then Q". If P and Q are both true, or both false, then the implication should hold; if P is true and Q is false the implication should not hold. The fourth row is the one that causes the most consternation.  As for circularity, even before we study formal logic we know that "if N is a multiple of 4 then N is even" is not the same as "N is a multiple of 4 if and only if N is even".
Comment: Yes, we know they're not the same, but before we study formal logic we won't know what their truth values are either. On top of that, I still don't understand why that truth table is the way it is. If P and Q are both false and the implication still holds, I don't really consider that uncontroversial. As for the 4th row; you still haven't explained why it was defined that way?
Answer: I think it is illuminating to approach it from the opposite direction.
Suppose we already know we want universal quantifiers (those are easy to motivate, I think), and that we also want to express the idea "everything that satisfies $P$ also satisfies $Q$"). It turns out that exactly this meaning can be expressed as
$$ \forall x\, [ P(x) \triangleright Q(x) ] $$
if $\triangleright$ is a truth-functional connective with the truth table
$$ \begin{array}{cc|c} P & Q & P \triangleright Q \\ \hline
T & T & T \\
T & F & F \\
F & T & T \\
F & F & T \end{array} $$
Since we want to have quantifiers anyway and truth-functional connectives are easy to understand and manipulate, this is a wonderful plan! We just need to decide on a name for our connective.
For better or worse, mathematics has decided to use the symbol $\rightarrow$ (or $\Rightarrow$ or $\supset$) to write this connective and to pronounce it with the words "if ... then ...".
But it's really not a matter of "what should the right meaning of the words 'if' and 'then' be?", but instead "what should we call the thing with such-and-such truth table?".
If somehow, we all are convinced that giving "if ... then" this meaning is so confusing and illogical that it needs to be changed, we would still keep using a connective with the above truth table. We would just call it something different.

It would be technically possible to fuse the two constructions together and say that $\forall x$ must always appear with two formulas: a condition and a conclusion, so $\mathop{\forall x}\limits_{P(x)} [Q_x]$ means what we're currently writing $\forall x[P(x)\to Q(x)]$. Then if we ever needed a quantifier without a condition we could write it as $\mathop{\forall x}\limits_{x=x} Q(x)$.
But this would make things strange whenever we want to quantify over two variables -- for example $\forall x \forall y (x<y\Rightarrow P(x,y))$ would now need to be written $\mathop{\forall x}\limits_{x=x} \mathop{\forall y}\limits_{x<y} P(x,y)$, where the dummy condition on $\forall x$ doesn't exactly make things easier to read.
And generally we want to split complex constructions into simpler ones whenever we can -- that makes all of the theory simpler. So simply because we can split the quantifier-with-condition into a universal quantifier and a truth functional is enough reason to do it.
Comment: Also I think your rejection of OP's requirement of bounded quantifiers is too pessimistic. There are logics and mathematical contexts that require all quantifiers to be bounded, so that "$\forall x"$" is forbidden and only "$\forall x\in S$" is allowed.
Comment: Indeed I think some people would argue that unbounded quantifiers are logically incoherent, and when we omit the bounds it's only by way of a convenient abbreviation when the bound is implied by the context.
Comment: @Luke: There are only 16 possible truth tables for a truth function of 2 operands; it is not difficult to check that each of the 15 others don't give the desired functionality when put under a quantifier (in the sense that you either can have a situation where all $P$s are  indeed $Q$s but $\forall x[P(x)\rhd Q(x)]$ is nonetheless false, or you can have a situation where some $P$s are not $Q$s, yet $\forall x[P(x)\rhd Q(x)]$ evaluates to true).
Comment: @MJD: Sure, there are contexts that care about bounded quantification -- but in those contexts you generally want tighter control on the shape of the bounds than just "insert some property here", so having a three-place quantifier as the _general_ construct is not going to make it appreciably easier to define bounded quantification. At least not if the general construct is flexible enough to subsume our current use of logical implication.
Comment: I think that is a result of OP's unfamiliarity with how things are actually done. Had they more experience, they might have suggested, instead of $$\underset{\text{$T$ is triangular}}{\forall T.} P(T)\implies Q(T)$$ something like $$\forall T\in{\mathscr T}. P(T)\implies Q(T),$$ where $\mathscr T$ is the set of triangles. We don't do the first, but we do the second, and I imagine OP is unaware of this, and might view it as being sufficiently similar to his or her idea that the question is resolved not as "we don't" but as "we do"—except for the part about redefining the material conditional.
Comment: @MJD I think this is where I lose it
Comment: @MJD This is what bugs me. Why didn't we specify $\mathcal{T}$ to be the set of all _equilateral_ triangles? I mean, we're already using bounded quantifiers, why not do it right the first time around? Thank you for linking to that article by Angelika Kratzer, I'll be taking a look at that now. Still, I think, my chief problem with all of this is simply _why_ the conditional is the way it is. Henning Makholm tried to explain it as having a truth-table that suits our needs and then associating a word to it, but then I wonder; why is the truth-table defined like that!
Comment: @HenningMakholm Alright, but why is that particular truth table the one that expresses the meaning of our truth functional connective? How did we choose that one out of all the others? What makes that one so special? I'm used to maths being proof-based or motivated by arguments, and so far most explanations have tip-toed around the very core of this whole thing: the reason behind our current definition of the implication. And please don't just say "well, that's what worked out" - somebody must have figured out that this particular truth table was superior over all others. Why?
Comment: @luke Were you aware that $\forall x\in S. Q(x)$ is often defined to mean exactly $\forall x. x\in S \implies Q(x)$?
Comment: @MJD Not really, no. But what difference does that make?
Comment: I'm not sure, but it seemed pertinent.
Comment: @HenningMakholm I'll try to figure that out, but I don't think it's going to be particularly fruitful. Quantifiers in general bug me, I think. To me, it's just strange to expect a quantifier that involves a _lot_ of completely irrelevant elements to behave in a certain way. Just seems ill-conceived. It makes no sense to say "for all natural numbers n" when we're really only interested in all _even_ natural numbers n. So I don't even understand why we use quantifiers that way instead of bounding them to our relevant values; much less why I'd have to keep that in mind when defining conditionals.
Answer: Consider the statement: If it is raining, then it is cloudy.

Symbolically: $Raining\implies Cloudy$

What does this mean? First, what it does not mean: It does not mean that rain somehow causes cloudiness, or that cloudiness somehow causes rain. Neither is the case. It means only that it is not both raining and not cloudy.

Symbolically: $\neg[Raining \land \neg Cloudy]$

There is no suggestion of causality -- of one thing causing another -- or of time-based data about a historical relationships between raining and cloudiness.
Everything about material implication -- the truth table for $\implies$, and the detachment and contra-positives rules -- all make sense when you understand this. Simply stated, the rule is:

$A\implies B\equiv \neg[A\land \neg B]$

EDIT:
The Truth Table
$\begin{array}{c|c|c|c}
A&B&A\implies B\\
\hline
T&T&T\\
T&F&F\\
F&T&T\\
F&F&T
\end{array}$
The Intuition
In the first row, we have $A\implies B$ and $A$ being true. Of course, $B$ must also then be true, as indicated.
In the second row, we $A$ being true and $B$ being false. Then $A\implies B$ must be false, as indicated.
Note that when $A\implies B$ is true and $A$ is false, as you would expect, $B$ is indeterminate, i.e. $B$ could be either true or false, as indicated in the the last two rows.
We also need $A\implies B$ to be true when $A$ is false to prove vacuous truth, an essential method of proof in mathematics.
Comment: I think this misses the point, and I think the point here is from [Mauro ALLEGRANZA's comment above](http://math.stackexchange.com/questions/1317408/couldnt-we-have-defined-the-material-conditional-differently#comment2679053_1317540): We define it this way because that's what makes modus ponens work.
Comment: Okay.  I still feel that your answer misses most of the crucial issues, and it doesn't address OP's suggestion either.
Comment: So the only reason that the conditional is the way it is, is because it's logically equivalent to not(A and not B)? That's it? No profound reason as to why it was defined that way?
Comment: That is correct. I think you will find that this definition works really quite well in writing mathematical proofs. It may seem counter-intuitive at first because the if-then construct in everyday usage usually suggests a causal or temporal relationship. In mathematics, there is no cause and effect and no passage of time. It may help to think of mathematics as a static body of knowledge, aspects of which humans have discovered over the millennia. Cause and effect is the realm of science. But even in science, we don't say, if you smoke then you have cancer. We say smoking *may cause* cancer.
Comment: @MJD  In mathematical proofs, we also need $A\implies B$ to be true if $A$ is false. It's not just some undesirable *side-effect* as some would have it; it is essential.
Comment: @MJD  Note, too, that the truth table for $A\implies B$ is not completely determine by the requirement that MP must work. MP determines only 1 out of 4 rows.
Comment: @MJD  We need $A\implies B$ to be true when $A$ is false to establish that certain statements are vacuously true. Another way to look at: If we know only that  $A\implies  B$ is true and $A$ is false, then $B$ is indeterminate -- it could be either true or false.
Comment: See edit above.


Prime number theorem

Question: I have the following problem.

Find the proportion of prime numbers among positive integers up to and including with 500 decimal digits.

I do not have problem with math; the problem is that I do not understand what the problem is asking due to my english. Is my interpretation correct that question is asking?

Find the proportion of prime numbers among positive integers between $1$ digits and $500$ digits (including both bounds)
Comment: Find the proportion of prime numbers in the interval $[1,x]$, where $x$ has $500$ decimal digits. Answer: $\pi(x)=Li(x)+O(\sqrt{x}\log(x))$.
Comment: @DietrichBurde So $x$ is the last number with $500$ decimal digits? ($x+1$ has $501$ digits)
Answer: Your interpretation looks fine. The exact answer is
$$\pi(10^{500})\over10^{500}-1$$
(You could also write $\pi(10^{500}-1)$ in the numerator, but you don't need to, since $10^{500}$ is clearly not prime.) To check that this is correct, consider the easier example where you want the proportion up to and including $2$ digits, which means the one- and two-digit numbers $1$ to $99$, where the exact answer is
$${\pi(10^2)\over10^2-1}={\pi(100)\over99}={25\over99}$$
If an approximate answer is desired, the Prime Number Theorem tells you
$${\pi(10^{500})\over10^{500}-1}\approx{1\over\ln(10^{500})}={1\over500\ln10}\approx.000868589$$

Prime number theorem


Circular breathing technique on "mouthpieced" woodwind instruments (clarinet, recorder, saxophone and so on)

Question: I'm trying to learn circular breathing to extend my range of "advanced" techniques. I had asked my teacher for advice, but he said he was a "natural" at circular breathing (meaning he has never learnt it and could circular-breathe from the get-go) and couldn't help me.
After following the famous straw-and-a-glass-of-water method for a few weeks and reading through a number of resources (for example, one at tamingthesaxophone.com and another one at woodwind.org), I have come across what I think is a major flaw in all of these explanations, and I'll try to describe it in a bit more detail.
Breathing in through the nose while pushing air out of the cheeks is all nice and dandy, and you eventually do get used to it, but a major problem arises once you start blowing air out normally and only using your cheeks for when you need to breathe in. After a while (0.75-1.5 minutes) I personally feel the need to breathe out through my nose, which I can only assume to be a reflex of some kind. It feels similar to suffocating (when you feel an urgent need to breathe in), except it's an urge to breathe out. It happens regardless of how much air is stored within the body. It only occurs when regular breathing out is added on top of pushing air out of the cheeks. If I only use my cheeks, I can go on for hours without ever feeling that need to breathe out (I'm assuming that's due to me breathing out in small increments every other time while pushing air out of the cheeks). What's up with that, and how does one actually "combat" that problem? Because each and every one of my straw-and-a-glass sessions basically ends with me spending a few seconds breathing out like a maniac.
Another problem that none of the sources seem to mention is the actual trouble of having a mouthpiece in your mouth. I personally can't puff my cheeks out with a mouthpiece plugging the oral cavity, because all the air escapes into the mouthpiece straightaway. Is there a trick to it? Does one use their tongue to "close" the tip opening, or does one use a smaller tip opening for circular breathing? A smaller chamber?
I'm asking those questions in the hope of expanding on existing resources. I feel like they don't go into enough detail and brush over some of the more important aspects of this technique.
Comment: I'm only a beginner on the clarinet but the air in your longs can become stale before you finish exhaling even on notes where you're pushing a lot of air. I don't know an answer to how to breathe circular for clarinet, but I might guess that not taking a whole lungful might help and also learning to empty your lungs through your nose while using your cheeks to play might be things to try. I'd say a *wider* mouthpiece would be easier to play with puffed cheeks than a narrow one.
Comment: One more thing, I'd expect clarinet and sax technique in this area to be different from recorder. In fact I'd probably try to learn this on recorder first and then try sax/clarinet.
Comment: Related [question](https://music.stackexchange.com/q/104370/2600) concerning breathing in general.
Comment: @ToddWilcox, personally, I've never experienced that problem on either clarinet or saxophone with regular breathing. Perhaps, I should thank my past as a smoker for that. I'll give it a try it with a wider mouthpiece. Recorder might indeed be easier, given it doesn't have a reed (and thus should be less resistant). But my main problem is that I just can't puff my cheeks if there's something plugging my mouth, and I haven't been able to find any statements online from people with a similar problem.
Comment: @ToddWilcox, I've managed to achieve the desired effect (on the straw+glass) by using every 2nd or so cheek air expulsion to breathe out. Thank you. But I still do not understand the need for it and why none of the sources mention it. From studying them, I had personally assumed that air was supposed to escape via mouth only, and that there was something wrong with me. Having it escape via 2 different cavities seems inefficient and wasteful.
Answer: Circular breathing imposes a new 'breathing timetable' on your body. You are trading off your natural breathing cadence for the requirements of the music. In the same way that holding your breath for a long time, or breathing rapidly, will have consequences, the rapid 'sniffs' required in circular breathing can upset the system. Your impulse to breathe out through the nose is one such result.
The answer, as with almost everything musical, is practice. If you are feeling this effect with a drinking straw, or a recorder, be prepared for some head spins if you move on to the larger aerophones. The didgeridoo is the most arduous: sometimes you can feel you need another breath immediately and you can fall into a rapid rhythmic breathing pattern which, if left unchecked, can lead you quickly into blackout territory.
There is no need to breathe out through your nose. Except for that brief time when you use your cheeks to maintain instrument airflow while you sniff in, you are always breathing out. It is worth mentioning that the cheeks should not be pumping like bellows: they are only maintaining the airflow and should slowly collapse a little, that's all.
As for reeds, this is where you are going to have to grow new muscles. Instead of the 'doot' we learn when playing clarinet/sax, you're going to have to go with more of a 'boot', and it will be hell for a while.
Success is a matter of slowly building endurance. There is absolutely nothing mystical about circular breathing (it's just the oxygen deprivation/surfeit talking), but it certainly requires rigorous discipline and devoted practice if you are going to maintain the technique for more than a minute or so.
Comment: Pressure inside a closed 'container' remains the same throughout that container. Basically what you are doing with circular breathing is using the back of the tongue and soft palate to momentarily create a second 'container' for air inspired through the nose. It seems you have mastered this. You then have to use your mouth and front of the tongue to get  a suitable embouchure. Experiment with the following 'sounds': t, d, bw, who and two (the blowing on coffee one). They have more relevance than the drinking straw embouchure, which is mainly for blowing bubbles or inflating balloons.
Comment: Place your hands on your belly on either side of your navel and exhale strongly. Feel a  slight movement outwards? This is your diaphragm 'pumping' your lungs to expel air. Every time you breathe out, or blow an instrument, the mechanism is the same: it's the diaphragm doing the work. When you are circular breathing you continue breathing out. Don't stop. Keep it happening. You then , in one synchronised move, close your jaw slightly, press the back of your tongue up against your palate to make a chamber  behind it and quickly snort in while bringing your cheeks in a bit. Don't give up.
Comment: Thank you. Are you saying that with practice I will no longer feel the need to breathe out through the nose? I'm practising daily, what I'm trying to avoid is _improper technique_. Interesting note regarding cheeks. The video my original post links to (around 7:00) led me to believe that cheeks should be puffed out to the max and completely emptied out. "Boot" won't be much of a problem, assuming you mean attacking notes with bottom lip versus tongue. I practise that daily as well.
Comment: I think so. If you're not ready to make the leap to an instrument (although a recorder uses a ridiculously small amount of air) try just blowing into the air or at your palm held in front of your face. Blowing into the air means you can practise while walking around or sitting in public; people won't notice, or if they do they'll just think you have a funny expression on your face. Blowing to cool down your coffee or tea? Do it with circular breathing.
Comment: As for advice to bulge cheeks then fully collapse them, this may give you an air stream for a longer period of time, but the whole idea of circular breathing is to maintain that flow of air to the instrument while you sniff in a fresh supply, and this takes less than a second.  Heavy-duty driving with the cheeks may boost the volume momentarily, and this may be an expressive technique, but I aim for a seamless effect. As for 'proper technique', any technique where the sound doesn't stop and you don't lose consciousness is a good technique.
Comment: Funnily enough, I'm already doing the exercises in public :) Masks are useful for something, after all. I aim for a seamless effect as well. And increasing airflow speed has helped me get rid of the need to breathe out, but at the cost of how long I can maintain it and at the cost of seamlessness as well... In other words, pushing the air out of the cheeks to breathe out helped me do it seamlessly (but was annoying as hell). It's hard to lose consciousness when you also play flute...
Comment: Okay, I can circular-breathe for 5 or more minutes with the glass+straw. But I cannot replicate it with a mouthpiece. At all. It's completely different, and, to be honest, I still have no idea how to overcome that difference. With the glass+straw I produce a stable flow of bubbles, with no "drops" or "spikes", and my cheeks do not seem to change in volume at all during the process. Still have to use some "puffs" to breathe out though. Any ideas?
Comment: Nothing seems to work. I can't sustain the airflow for more than a few seconds. Might as well give up, I simply don't get it.
Comment: Still no dice. Took me 2 weeks to learn how to puff my cheeks with a mouthpiece, can't draw the minutest of breaths when they're puffed. I have never been that frustrated with anything music-related, and I'm a very patient person. It even beats my experience with flute. I honestly can't take it anymore. My apologies for venting my frustration here.
Answer: I'd like to point out two issues:
First,  you write

regardless of how much air is stored within the body

Here the most important distinction is missing: any sufficiently dense gas will do for making an instrument sound, including exhausted air. Unfortunately the latter will not help your body getting its oxygen, and this could be the reason for the mentioned need to breath out. Your body wants to get rid of this useless stuff. As I mentioned in my answer to the linked question, this is an effect the players of bassoon and even more of oboe are used to, since their respective reeds permit only a small airflow and the danger of not getting rid of exhausted air is well-known and requires conscious exhale. I can imagine, that you start with inhaling part of circular breathing too early (too much air still in lung), so too little fresh air fits in.
Second issue is, how to fill cheeks in spite of an opening as a present mouthpiece. With your standard air stream and pressure (which you are used to apply for normal playing) you won't succeed because there is no excess on air. You may try to exert more pressure by the diaphragm or imagine to exhale faster or whatever helps so more air is provided than flows through the mouthpiece but only the excess will be available for cheek storage. You have to work against the muscles of your cheeks, which have to sustain the pressure to make the instrument sound.
Comment: Thank you for reminding me of your answer to the related question. Somehow, I have completely forgotten the last point you made there. What do you mean by "starting to circular-breathe too early"? Thank you very much for providing more insight into the process. How does your answer coincide with Areel Xocha's? From reading his response, I've come to the conclusion that the need to breathe out eventually dissipates. Is that assumption correct?


In major can ii V I support ^6 ^7 ^8?

Question: Is there any reason why this progression should be a problem in major keys? The other harmonizations I have for this soprano according to "Harmony and Voice Leading" by Edward Aldwell and Carl Schachter are:

vi V I,
IV vii6 I,
IV vii6 I6

They don't include ii V I however and I think this is an obvious choice unless I'm missing something?
Comment: Other than IV V I, it's hard to think of a more idiomatic ending than the one you're describing.  You're quite right.
Comment: @Bennyboy melodies of the 18th century typically cadence from above, though, or, if not, as ^8 ^7 ^8 or ^9 ^7 ^8, so ^6 ^7 ^8 is more likely to be found in the middle of a phrase.  For an ^8 ^7 ^8 cadence you're likely to find ii7 V I or, more likely, ii(6/5) V I.  The latter also works for ^9 ^7 ^8, as does ii6 V I.
Comment: Have I missed a criterion?
Comment: @Bennyboy1973 I'm just saying that having ^6 ^7 ^8 in the soprano isn't a particularly idiomatic ending in the 18th century.
Answer: That's interesting; there's nothing that would prevent ii–V–I from harmonizing this 6–7–1 soprano line.
A similar progression, though, would present a problem: IV–V–I would almost certainly lead to parallel octaves (see A, below), parallel fifths (see B), or a doubled leading tone (see C), and so it makes sense that IV–V–I is not included. But ii–V–I doesn't have these problems (see D).

My guess is that this is a byproduct of the authors' Schenkerian-theory mindset. In Schenkerian theory, the best tonal closure occurs with a descending soprano line of something like 3–2–1. As such, a firm cadence like ii–V–I is best harmonized with a soprano of 2–2–1. Notice that the sample progressions you gave for 6–7–1 are not true cadences, with the exception of vi–V–I. But this one is so comparatively rare in this style that I'm guessing they felt comfortable including it anyway.
Comment: I couldn't make the ii-V-I work in 4-part harmony. However by varying the number of voices, ii-V43-I6 works pretty well (or ii-V43-I with doubled root.)
Comment: Thanks Richard. Yes the IV V I progression is mentioned in the same section of the book as being the the wrong choice for ^6 ^7 ^8.
Comment: @armani ii6 V I is quite common in the early 18th century.
Comment: @phoog More common than IV–V–I, in my experience!
Comment: Well yes, that's what I meant to say.
Comment: @phoog... when you say common did you mean as a general cadential progression or to harmonize the soprano ^6 ^7 ^8?
Comment: @armani I meant in general.  As I've noted in another comment, final melodic cadences of ^6 ^7 ^8 are not very common.  You will often see it in an inner voice, however, with ^4 ^5 ^1 in the bass and ^2 ^2 ^1 in the soprano.
Comment: @phoog yes but its nice to use it in the middle of a phrase or section and I do like the sound of it so I was interested to know why it wouldnt have been included as a legitimate way to harmonize that line.. maybe, perhaps possibly it is because the minor version doesnt work since ii in minor is generally avoided...but even then ii6 is an option so not sure
Comment: @armani it's typical to avoid cadential harmonizations in the middle of phrases even if they could fit, because, well, it's not the end of the phrase. I looked at a couple of Bach chorales that contain ^6 ^7 ^8, one of which is _Wachet auf_ from BWV 140, where the ^8 is harmonized with a vi chord. The only example I found where it's in a I chord is _Ein feste Burg_ ("A mighty fortress") from BWV 80, where the chords are IV vii°6 I (the bass is ^4 ^2 ^1).  There's probably a Bach chorale somewhere that harmonizes those three pitches either as ii6 V I or ii V I; I just couldn't find it.
Comment: @phoog I disagree with that because a phrase could end once on the less strong cadence and then the second time on the strong cadence. This could create contrast in a nice way. Thanks for digging into the Bachlopedia :)
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/133984/discussion-between-phoog-and-armani).
Comment: @armani there are a lot of erudite answers here, but nobody has really accepted that the answer is "Yes, you can do that."  Those chords do, in fact, work fine to support ^6^7^8, and you can write that out pretty simply to prove it to yourself.  Unless you're trying to emulate a Bach chorale, or to conform to the edicts of the theorists of the 19th and 20th century, you're fine.  We see the same thing in English grammar, where a schoolmaster might beat a student for ending a sentence with a preposition, but without actually furnishing a sensible reason why one ought not do so.
Answer: According to Walter Piston there is a difference in basic voice leading for ii V compared to other descending fifth progressions...

Just to have text to accompany the image...

In the progression II-V, it is customary not to repeat the common tone but to move the three upper voices down to the next available position.

Piston does not say why it is customary. But think the point must be about cadential harmony. Using wide open voicing to make the voices easier to read, Piston's customary treatment is...

...notice how RE descends to DO (via TI) and FA descends to MI (via RE) which provides a very strong resolution, a perfect authentic cadence.
If the basic voice leading of hold common tones, move other tones the smallest distance is followed the result is...

...an imperfect cadence and FA ascending rather that descending.
Obviously neither offends a sense of good voice leading, but one is clearly a stronger cadence. That leads me to believe Piston's point about custom must be particularly about cadential harmony. If such a progression of ii V I were occurring in something like a non-cadential, sequential passage, I suppose either voice leading option might be used.
Maybe the author of your book takes a view similar to Piston's.
Piston illustrated his book with a lot of examples from the great composers, but not in the voice leading principles section. Also, even though he provides lots of real music examples he didn't do anything like a corpus analysis as seems popular now in the computer era. I don't really know if Piston's "custom" would hold up under a large survey of real music. Regardless, the cadential aspect of the voice leading options seem clear enough and should probably be treated accordingly.
If it isn't clear, the tenor line in my examples would be the soprano line you're concerned about. You would just invert voices to put those tenor lines into the soprano position. I voiced my examples with D in soprano to make the cadential point clear.

In major can ii V I support ^6 ^7 ^8?


mysql database normalisation

Question: I'm new to mysql! have absolutely basic knowledge like creating tables only.
I'm in the process of creating a website with online examinations and results. My fields include
t_id, t_name(subject),ru_id, ru_name, ru_skl, hs_user, hsu_skl

Legend: t is test. ru is registered users. skl is school. hs is high scored. hsu is high scored user.
I don't know how to arrange the fields in tables and to establish a relationship such that the following conditions are met:
(1) each test can have multiple users registering, for the same test_id.
(2) highest scored user should be obtained and entered into table, for the respective test_id.
(3) highest scored user's school should also be entered into table, for the respective test_id.
(4) conditions 2 n 3 should be retrievable so as to process using php for monthly toppers list, etc.
Kindly require ur help! :)
Answer: Table: UserToTest
Columns:
test_id | user_id | score

That is actually all you need. Just insert user_id and test_id to establish the relationship. Add the score as additional information.
All the other data you want to have, max score by user and max score by school are values you can easily compute when querying. So there is no real need to write it in a table, it would only make the datahandling more complicated as you would have to add triggers, constraints or more logic in your application to keep those values up to date.
Comment: Tq for ur ans!! i get wt u mean, bt wt if i have to add points for the user who scored max, and then to the school, such as to create sumtn like a leaderboards, etc., which have to be updated at specific time intervals. Then, wouldn't i need to store the values of scores, etc, as i would be displaying it in a webpage...?
Comment: No, you don't have to store them. Also when you are computing them as you are querying there will be no problem like "updated at specific intervals" as the computed values will always be up to date. But if you really really want to save those values, you should put them into the test-table, as it has nothing to do with the actual relations but is a specific statistic for a test.
Comment: will definitely try ur valuable suggestion...Tnx a lot!!
Comment: Nice :) Feel free to ask when you need help with those queries for the leaderboard, sometimes they aren't as easy as one first might think. Also please accept the answer if it helped you
Comment: y tnq, again!! If ur fairly proficient with php pdo, kindly send me ur email ID...Dat'd b easier i suppose!

mysql database normalisation


Find the real values of $P$ for which $f(x)=P$ has exactly one solution.

Question:
$$f(x)=(x-1)^2(x-2)+1$$
  Find the real values of $P$ for which $f(x)=P$ has exactly one solution.

Hi, I'm a little bit confused with this question.I don't know how I should start. I think I need to use the quadratic formula but I don't know if it gives me the right answer. Can you help me with this question?
Answer: Just another way considering that, once expanded, you have to solve the cubic equation $$x^3-4 x^2+5 x-(1+P)=0$$
If you look here, you will see that the key factor for the number of roots of the general cubic equation $ax^3+bx^2+cx+d=0$  is the discriminant $\Delta$ given by $$\Delta=18 a b c d - 4 b^3 d + b^2 c^2 - 4 a c^3 - 27 a^2 d^2$$ So, for the case $a=1$, $b=-4$, $c=5$, $d=-(1+P)$, $$\Delta=-27 P^2+50 P-23=-27(P-1)(P-\frac {23}{27})$$ As given in the Wikipedia page, if $\Delta<0$, the equation has one real root and two nonreal complex conjugate roots.
I am sure that you can take it from here.
Answer: We need $(x-1)^2(x-2) = P-1$ to have exactly one real root.  The LHS has a double root at $1$ and a single root at $2$, and is increasing otherwise.  Hence as long as $P-1$ does not cross the LHS in this interval, it will always have only a real root.
Therefore the only values $P-1$ cannot take is the range of $(x-1)^2(x-2)$ when $x \in [1, 2]$.  This is easily found to be $[-\frac4{27}, 0]$, either using calculus or the AM-GM:
$$\frac14(x-1)^2(2-x) \le \left( \frac{\frac{x-1}2+\frac{x-1}2+2-x}3\right)^3=\frac1{27}$$
Answer: I think it is very useful to think about this exercise graphically. Let us have a look at the following graph.
The graph shows the function
$$
f(x)=(x-1)^2(x-2)+1
$$
and a horizontal line $f(x)=1.5$ which depicts the situation when $P=1.5$. We need to find such values $P$ that the horizontal line interesects the graph of the function only once.
Answer: 1) Find the local minimum and maximum of $f(x)=(x-1)^2(x-2)+1$.
$~~~~~$For this purpose, find $x_1$ and $x_2$ such that $\frac{d}{dx} f(x_1)= \frac{d}{dx} f(x_1) =0$. ($ x_1 = 1$ is a local maximum and $x_2 = \frac{5}{3}$ is a local minimum)
2) For each $P>f(1)=1$ or $P<f(\frac{5}{3})=\frac{23}{27}$, $f(x)=P$ has exactly one solution.
3) For $P=1$ or $P=\frac{23}{27}$, $f(x)=P$ has two solutions.
4) For $P\in(\frac{23}{27}~~,~~1)$ , $f(x)=P$ has three solutions.


Splitting field and intersection of subfields

Question: Let $K/F$ be a field extension and $f \in F[x]$ with $\deg{(f)} \geq 1$. Furthermore, for a subset $L$ with $F\subseteq L \subseteq K$, let $p(L)$ denote the property that $f$ can be factored completely into linear factors in $L[x]$. Now consider the set
$$\mathcal{L}:=\bigcap\{F\subseteq L \subseteq K \mid p(L) \ \text{holds}\} $$
Question: If property $p(K)$ holds, does it follow that $p(\mathcal{L})$ holds?
In words: If $f$ can be factored completely into linear factors in $K[x]$, does it follow that $f$ can be factored completely into linear factors in $\mathcal{L}[x]$?
Comment: Is $\mathcal{L}$ supposed to be the *intersection* of those intermediate fields $L$ such that $p(L)$ holds?
Comment: @leoli1 Oh yes you're right, it should be the interesection of all those $L$. I've edited it now.
Answer: Yes, that is true. Let $\alpha$ be any root of $f$ in $K$. As $\alpha$ is contained in every $L$ such that $p(L)$ holds we have $\alpha\in\mathcal{L}$. Therefore $\mathcal{L}$ contains all roots of $f$ in $K$ and $f$ splits over $K$, so $f$ will also split over $\mathcal L$ since all the linear factors over $K$ are actually defined over $\mathcal L$.
Comment: Could you elaborate a bit more on why $\alpha$ is contained in every $L$ with $p(L)$? I know that $\alpha$ is a root of $f$ in $K$ iff $(x-\alpha)$ is a factor of $f$. Is this factor then also one of the factors in the factorisation of $f$ in $L[x]$ for some $L$ with $p(L)$, and thus a root of $f$ in $L$?
Comment: Yes, that is the reason. Since $f$ splits over $L$ into linear factors we can write $f=\prod_{i}(x-\beta_i)$ for some $\beta_i\in L$. As $f(\alpha)=0$ and we are in fields $\alpha$ has to be one of the $\beta_i$ and hence in $L$
Comment: Okay thanks, it makes sense now.


Expanding height on button click on slider

Question: I have a testimonials slider, and I want to add a button "Show more" if my text in div is taller than  200px and hide it if not.
Here is my attempt, class dsb mean display block in css

$(function() {
  var curHeight = $('.about-bottom-text').height();
  if (curHeight > 250) $(this).parent().find('.readmore').removeClass('dsb');
  else $(this).parent().find('.readmore').addClass('dsb');
});

function changeheight() {
  var readmore = $('.readmore');
  if (readmore.text() == 'Read more') {
    readmore.text("Read less");
  } else {
    readmore.text("Read more");
  }
  $('.height').toggleClass("heightAuto");
}

some text>

  Read more

Comment: Please update the snippet I wrote for you with relevant CSS, fix the HTML and explan what the actual problem is. You for example do not have a function and you do not have a class .about-bottom-text
Comment: Your're right,i didn't provide all code,i tested your example and it's not working..... here my all corect code....
Comment: $(function()
 {
     var curHeight = $('.about-bottom-text').height();
     if(curHeight > 250)
         $(this).parent().find('.readmore').removeClass('dsb');
     else
         $(this).parent().find('.readmore').addClass('dsb');
 });
function changeheight() {
        var readmore = $('.readmore');
        if (readmore.text() == 'Read more') {
            readmore.text("Read less");
        } else {
            readmore.text("Read more");
        }

        $('.height').toggleClass("heightAuto");
    };
Comment: class aout-bottom-text is instead od class text
Comment: I have updated my answer to handle the link text
Answer: I suggest you toggle the button
I also removed the inline onclick

$(function() {
  $(".readmore").on("click", function(e) {
    e.preventDefault();
    var show = $(this).text()=="Read more";
    var $prevDiv = $(this).parent().prev();
    $prevDiv.css({ "overflow":show?"initial":"hidden" }); // or toggleClass
    $(this).text(show?"Read less":"Read more");
    if ($(this).prev().is("br") ) { // the next can likely be handled by your CSS
       $(this).prev().remove();
    }
    else {
      $(this).before('
');
    }
  });
  $('.text').each(function() {
    var tall = $(this).height() > 200;
    $(this).css({ "height":"200px","overflow":"hidden" });
    $(this).next().find('.readmore').toggle(tall);
  });
});

some text

  Read more

some text
some text
some text
some text
some text
some text
some text
some text
some text
some text
some text
some text

  Read more

Answer:

jQuery(document).ready(function ($) {

    var divs=$('.text>div').hide();

    var h2s=$('.text>h2').click(function () {
        h2s.not(this).removeClass('active')
        $(this).toggleClass('active')
        divs.not($(this).next()).slideUp()
        $(this).next().slideToggle()
        return false;

    });

});

Read more

 Nice content!

This is a quick example.


How to use 'toPromise()' on http.post request that doesn't return data in Angular?

Question: I recently started learning Angular (4) and followed the tutorials of Angular.io.
But now that I'm trying to build my own application I'm running into a bit of a problem. I've spent the whole day trying to figuring this out but I failed.
I'm working on an auth service that has only a login and a logout for now.
The login works fine, but I don't get the logout to work. It seems to break on the toPromise() call.
const url = `${environment.serviceURL}/api/account/logout`;
const headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded',
    'withCredentials':true,
    'Authorization': `Bearer ${this.token}`});
let options = new RequestOptions({headers: headers});
let result = this.http.post(
     url, options).toPromise().then(/*do something*/);

This gives me the following error in the console:
ERROR Error: Uncaught (in promise): TypeError: v.split is not a function
TypeError: v.split is not a function at http://localhost:4200/vendor.bundle.js:26382:76
at Array.forEach (native)
at http://localhost:4200/vendor.bundle.js:26382:20
at Map.forEach (native)
at Headers.toJSON (http://localhost:4200/vendor.bundle.js:26380:23)
at Object.stringify (<anonymous>)
at Request.Body.text (http://localhost:4200/vendor.bundle.js:26957:25)
at Request.getBody (http://localhost:4200/vendor.bundle.js:27865:29)
at Observable._subscribe (http://localhost:4200/vendor.bundle.js:27393:37)
at Observable._trySubscribe (http://localhost:4200/vendor.bundle.js:567:25)
at http://localhost:4200/vendor.bundle.js:26382:76
at Array.forEach (native)
at http://localhost:4200/vendor.bundle.js:26382:20
at Map.forEach (native)
at Headers.toJSON (http://localhost:4200/vendor.bundle.js:26380:23)
at Object.stringify (<anonymous>)
at Request.Body.text (http://localhost:4200/vendor.bundle.js:26957:25)
at Request.getBody (http://localhost:4200/vendor.bundle.js:27865:29)
at Observable._subscribe (http://localhost:4200/vendor.bundle.js:27393:37)
at Observable._trySubscribe (http://localhost:4200/vendor.bundle.js:567:25)
at resolvePromise (http://localhost:4200/polyfills.bundle.js:3224:31)
at http://localhost:4200/polyfills.bundle.js:3150:17
at SafeSubscriber._error (http://localhost:4200/vendor.bundle.js:66387:85)
at SafeSubscriber.__tryOrSetError (http://localhost:4200/vendor.bundle.js:16367:16)
at SafeSubscriber.error (http://localhost:4200/vendor.bundle.js:16321:26)
at Subscriber._error (http://localhost:4200/vendor.bundle.js:16248:26)
at Subscriber.error (http://localhost:4200/vendor.bundle.js:16222:18)
at Observable._trySubscribe (http://localhost:4200/vendor.bundle.js:572:18)
at Observable.subscribe (http://localhost:4200/vendor.bundle.js:555:27)
at http://localhost:4200/vendor.bundle.js:66387:15

The mayor difference is (at least I think) that the login returns data containing the user info and the logout doesn't return any data. It just removes the session in the service.
I just want to know if the request has succeeded so I can act upon it.
What am I doing wrong or what should I do differently to get this working?
Comment: To answer your question to me ... see this post on Promises vs Observables: https://stackoverflow.com/questions/37364973/angular-promise-vs-observable
Comment: @SEG.Veenstra good catch on null input. About your other question, http returns an Observable which is by default lazy. If you don't subscribe to an Observable, it won't execute. In this case, it won't make the http call. You should either subscribe to it or you can use async pipe in your html which also does the same thing.
Comment: I'd recommend that you don't use promises and use observables instead. I have a complete CRUD example app here: https://github.com/DeborahK/Angular2-ReactiveForms
Comment: Do you use split function on your data when you call login url? If so, I assume you use the same function for logout which calls the same promise function. You should use different http calls for each.
Comment: @DeborahK I will check it out. Can you elaborate on why observables are 'better'?
Comment: @BunyaminCoskuner both are two separate functions and API endpoints. I'm also not splitting anything myself. I think the toPromise is trying to do that somehow.
Comment: @SEG.Veenstra do you run your app in prod mode? If so, can you remove --prod tag which may give more detailed error.
Comment: @BunyaminCoskuner I'm running it in Dev mode. What I've posted is all the error I'm getting.
Comment: Can you confirm that it's the `let result =` line that is throwing the error and not one of the lines above it? In browser dev tools, if you open the network monitor tool, is an HTTP call actually made?
Comment: @SEG.Veenstra I don't think toPromise is causing that. There is no .split call in toPromise if I'm not mistaken. Check here --> https://github.com/ReactiveX/rxjs/blob/88ec8dc54b6ede043f779232e33e3939b870e3dc/src/operator/toPromise.ts
Can you try to find who is calling .split function?
Comment: @BeetleJuice If I remove the `toPromise()` I'm not getting an error. But both times no HTTP call is made. Any idea why?
Comment: Guys, I found an error on my behalve. I had to put in `null` for the body param to at least let the HTTP request work. It probable tried to parse the options as the body or something... oops.
I'm now facing some CORS errors, but that's an other matter. THX guys!
Answer: This had nothing to do with the toPromise() as @Bunyamin Coskuner and @BeetleJuice pointed out in the comments.
I found out that I made a mistake in calling the http.post methode without the body parameter which caused the function to take the options as the body.
changing:
let result = this.http.post(
 url, options).toPromise().then(/*do something*/);

to:
let result = this.http.post(
 url, null, options).toPromise().then(/*do something*/);

Solved my error!


Elasticsearch: _count give strange result

Question: $ curl -XGET 'http://test.server.es:9200/index/test/_count?pretty'
<code>{
  "count" : 229594,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  }
}
</code>
try again:
$ curl -XGET 'http://test.server.es:9200/index/test/_count?pretty'
<code>{
  "count" : 226967,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  }
}
</code>
The "count" value is smaller than the previous _count, yet no delete operation between the two _count.
Comment: Are you running it on a multiple nodes cluster?
Comment: Yes. A Cluster of 21 nodes.
Answer: One of your nodes went crazy and has uncomplete shards on it.
Ask for stats and find the faulty node:
<code>curl -XGET 'http://localhost:9200/_cluster/nodes/stats'
</code>
If you had replica set to at least 1, then just stop this node, remove the data dir and restart the node.
My 2 cents
Comment: Thanks. I set number_of_replicas=4, now it's ok.


If the product of two matrices is a null matrix, when can we say one of them is a null matrix?

Question: $A$ and $B$ are two rectangular matrices of size $m \times n$ and $n \times p$, respectively (where $n > m,p$). Also $A$ is full rank. If $AB = 0$ can we say $B = 0$?
Comment: No AB=0 not always implies A or B =0.
Comment: I know But when one of them is full rank what can we say.I think if A has full column rank then B should be null matrice
Answer: The simplest example is to pick $ A $ to have one row and $ B $ one column ($ m = p = 1 $).  $ A B $ then becomes a dot product, and we know that for any two orthogonal vectors their dot product is $ 0 $.
This is the kind of example that is important to think about, since it shows that a lot of what you know about algebra with scalars does not carry over to algebra with matrices.
Comment: Do you know the answer  for the case $n  <  $m , $p
Comment: What you are asking is:  If $ A $ has linearly independent columns, does $ A B = 0 $ mean $ B $ is the zero matrix.  The answer is yes.  How do you see that?  $ A B = A ( b_0 ~~ b_1 ~~ \cdots ) = ( A b_0 ~~ A b_1 ~~ \cdots )  $.  So, $ A b_j = 0 $.  But since $ A $ has linearly independent columns, $ b_j $ (each column of $ B $) is zero.
Comment: yes my question was exactly that: when we can say $ B = 0 $
I understand .thanks alot


Prove that $\oint _{|z|=R} (f-g)' dz = 0$ (Residue Theorem)

Question: I know that $f$ and $g$ have a pole or order $k$ in $z=0$.
$f-g$ is holomorph in $\infty$.
I need to prove that:
$$\oint_{|z|=R} (f-g)' dz = 0$$
Any help?
Note: $f$ and $g$ only have a singularity in $z=0$
Comment: Integral of $(f-g)'$  over a closed loop is zero... because $(f-g)'$ has an antiderivative...
Comment: I don't understand
Comment: [What user147263 said](http://math.stackexchange.com/questions/757744/analytic-fz-has-fz-as-derivative-implies-int-gamma-fz-dz-0-f/757754#757754).
Answer: As Git Gud alluded to in their comment, simply parameterise the curve and calculate the integral directly. The usual parameterisation is $\gamma:[0,2\pi]\rightarrow\mathbb C:\ t\mapsto Re^{it}$. Letting $h=f-g$, we have
$$\oint_Ch'(z)\ \mathrm dz=\int_0^{2\pi}h'(\gamma(t))\gamma'(t)\ \mathrm dt=\int_0^{2\pi}(h\circ\gamma)'(t) \mathrm dt\\=(h\circ\gamma)(2\pi)-(h\circ\gamma)(0)=h(R)-h(R)=0.$$
Answer: If $h$ is holomorphic, then $h'$ exists and is holomorphic. If $h$ is holomorphic, then $\oint_C h dz = 0$ for all circles $C$. Take $h= f-g$, $(f-g)'$ respectively.
Comment: What does "holomorphic in $z=\infty$" mean? I know of holomorphic on an open set.
Comment: This isn't quite true. If $h$ is holomorphic on a region $D$ and $C$ is a closed simple curve entirely within $D$, then $\oint_Ch(z)\ \mathrm dz=0$. But $h=(f-g)'$ is not holomorhpic at $z=0$.
Comment: No, the exercise is not so stupid haha. $f-g$ is holomorphic in $z=\infty$
Comment: @Jason why is that? the OP did not say that $f-g$ is not holomorphic at $z=0$. He said that it is holomorphic at $\infty$ which I presume, maybe mistakenly, that it's entire. For example, take $f=g=\frac{1}{z}$
Comment: Well fine, it is not *necessarily* holomorphic at $z=0$. Your example doesn't change the fact that we do not know for sure that $(f-g)'$ is holomorphic at $z=0$, so we cannot use Cauchy's theorem.


Galois extension from $GF(5)$ to $GF(25)$.

Question: I'm a bit confused by part (a) and (d) specifically, in the following question,but I'll throw up the rest too just to make sure it's okay;
Let $β$ be a root $of g(x) = x^2 − x + 1$ over $GF(5)$.
(a) Explain briefly why $GF(5)(β) \cong GF(25)$.
(b) Verify that $β^3 \neq 1$ and $β^8 \neq 1$ in $GF(25)$.
(c) Using (b), or otherwise, find the minimum m ≥ 1 such that $β
^m = 1 $ in $GF(25)$.
(d) Determine the isomorphism type of the group (GF(25)×, ·) of non-zero elements of
GF(25) under multiplication.
My answer:
a)$GF(5)$ is isomorphic to a subfield of $GF(25)=GF(5^2)$ as 1|2. $GF(5)(\beta):=\{a+b\beta|a,b \in GF(5)\}$ contains 25 elements so $GF(5)(\beta)\cong GF(25) $ as now it has the same number of elements as well as the same underlying structure. [I feel my explanation is shaky here].
b)$\beta^2-\beta+1=0 \Rightarrow\beta^2=\beta-1$.
so $\beta^3=\beta(\beta-1)=\beta^2-\beta=\beta -1-\beta=-1 \neq1$.
and $\beta^8=(\beta^2)^4=(\beta-1)^4=...=\beta^2$.
c)$\beta^{24}=(\beta^8)^3=(\beta-1)(\beta-1)(\beta-1)=(\beta^2-2\beta+1)(\beta-1)=(-\beta)(\beta-1)=-(\beta-1)+\beta=1$.
d) an automorphism ? [I really don't know about this one ]
Comment: For part c you should notice that $(x+1)(x^2-x+1)=x^3+1$ is a factor of $x^6-1$, so $m=6$ is the minimum. This follows equally easily from your calculation of $\beta^3$. I don't see how this helps in part d. We do know that the multiplicative group is cyclic of order $24$, but the presence of an element of order six does not imply that. To that end you would need to find an element $\gamma$ such that neither $\gamma^{12}$ nor $\gamma^8$ is equal to $1$. I suspect that whoever designed the problem made a mistake. I gave a similar problem in my course just two weeks ago :-)
Answer: For a), it depends on how you define $GF(5)$. My preferred argument is that $GF(5)$ is a splitting field: it's the splitting field for $t^{25}-t=0$ over $GF(5)$ and unique by uniqueness of splitting fields. But in any field of order 25, every element satisfies this polynomial, so it is also the splitting field.
For d), there's a standard result that any finite subgroup of the multiplicative group of a field is cyclic. The argument goes like this: Let $X$ be such a subgroup. It's certainly Abelian. Finite Abelian groups have elements of maximal order, and in fact every element has order dividing the maximal order: if $g$ has maximal order and $h$ has order not dividing $o(g)$, then $o(gh)=\frac{o(g)o(h)}{\text{gcd}(o(g),o(h))}>o(g)$, a contradiction.
So every element has order dividing $o(g)$, so every element is a root of the polynomial $x^{o(g)}-1=0$. There are certainly at least $o(g)$ elements in $\langle g \rangle$, so there are definitely that many in $X$. But there are at most $o(g)$ roots of this polynomial, so at most $o(g)$ elements of $X$. So $|X|=o(g)$, so $X=\langle g\rangle$.
In particular, this tells us that $GF(25)^{\times}$ is a cyclic group of order 24.


Proper subsetting of survey data

Question: I have a question about proper subsetting of survey data. This is the scenario:
A health survey targeting the general U.S. population has a first stage of sampling that begins by defining primary sampling units (PSUs) as counties, or groups of counties for sparsely-populated areas.  These PSUs are stratified by state (Washington, DC is lumped in with Maryland), and two are selected within each stratum, for a total of 100 sampled PSUs.  Thereafter, subsequent stages of sampling are done in a hierarchical manner down to the household level and, ultimately, one individual within the household is selected to participate in the survey.  For variance estimation purposes, however, the survey administration team only releases stratum and PSU codes.
If you were estimating the rates of a particular health condition (e.g., Type 2 diabetes) captured by the survey for a region of the country, which you defined as a grouping of 8 states, could you subset the survey data set for all cases in the region?
I'm confused about whether this would be a proper subset of the data if subsetting as described above. I believe that it is not because the number of people with a health condition could vary from one county to the next in the sample, so the domain sample size is a random variable itself. However, I'm not totally positive since it seems like a logical way to subset your data.
Answer: Here's a well-written blog post that directly answers your question:
https://notstatschat.rbind.io/2021/07/22/subsets-and-subpopulations-in-survey-inference/
Short answer:
The short answer is that, no, you don't want to simply subset your data and calculate the estimate from the subset. The variance of the estimate from your subset depends on the entire design, not just the sample members from the domain you're interested in. The only practical exception is that if your data has replicate weights created using the complete data, you can proceed to estimate variances for domain estimates by just subsetting the data and using only the rows of replicate weights in your subset of data. But again, the replicate weights have to first be created using the full dataset.
Comment on survey statistics software
To provide a user-friendly experience, survey statistics software will "pretend" to subset the data, but what it actually does is retain all the data but set the weights to zero for cases outside the subset of interest. For example, consider the following R code adapted from Dr. Lumley's blog post, which estimates the total enrollment for high schools (i.e. ignoring middle and elementary schools):
library(survey)

data(api)

# Create a survey design object
dclus1 <- svydesign(id=~dnum,weights=~pw, data=apiclus1, fpc=~fpc)

svytotal(~enroll, subset(dclus1, stype=="H"))

What this code is actually doing is equivalent to the following:

svytotal(~I(enroll * ifelse(stype=="H", 1, 0)), dclus1)

In the above code, R is keeping track of the entire survey design, even when you're computing estimates for just a subpopulation. You'd run into problems if you didn't tell R about the entire survey design, for example if you did the following:
# Don't do this!
library(survey)

data(api)

subset_of_data <- subset(apiclus1, stype == "H")

# Create a survey design object using only the subset
dclus1 <- svydesign(id=~dnum,weights=~pw, data=subset_of_data, fpc=~fpc)

svytotal(~enroll, subset(dclus1, stype=="H"))
```

Proper subsetting of survey data


How to load a large amount of elements in JavaFX?

Question: I want to create a connect four game in fxml. I have already created the fxml for the board and now I want to load all the "coin fields" which are Buttons with an Image view into my Controller.
From previous experiences with fxml I learned to load an fxml element like this:
@FXML
Button idOfButton;

This is good if I have specific elements that I want to change. But since I have 42 Buttons (6*7) I don't want to do that for every Button Field... Is there any way I can do it in a different way and auto-generate it? I prepared this for-loop but since I don't know what to write into the curly braces it's still pointless :D
Button[] coinButtons = new Button[42];

@FXML
public Button[] loadCoinButtons() {
    for(int x=0; x<7; x++) {
        for(int y=0; y<6; y++) {
        // Stuff that loads the buttons into my buttons array
        }
    }
    return coinButtons;
}

Help is highly appreciated!
Comment: Just create the buttons in Java, instead of in FXML.
Comment: @James_D And then load it into my fxml?
Comment: BTW, why do you need 42 buttons? In Connect4, there are at most 7 possible moves.
Comment: No, don't use FXML for the buttons. Just create them directly in the controller.
Comment: @James_D ah you are right, I actually only need 7 buttons because the coins are gonna drop anyways
Answer: You can create these buttons in the Java code. Not declaring them in FXML doesn't mean they won't belong to your scene. What you have to do is give the fx:id tag to a container in which you would like to put more buttons, declare it in a Controller class with the @FXML annotation and then put some new Nodes there. Look at the simple app below (assuming all the files are in the sample package) - I created some buttons in FXML file and some via the Java code.
Main.java:

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

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

sample.fxml:
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Button?>

<VBox fx:id="vBox" fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml">
        <Button text="FXML_Button_1"/>
        <Button text="FXML_Button_2"/>
        <Button text="FXML_Button_3"/>
</VBox>

Controller.java:
package sample;

import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;

public class Controller {
  @FXML
  VBox vBox;

  private final int BUTTONS_NUMBER_OF_ROWS = 5;
  private final int BUTTONS_NUMBER_OF_COLUMNS = 5;
  private Button [][] buttons = new Button[BUTTONS_NUMBER_OF_ROWS][BUTTONS_NUMBER_OF_COLUMNS];

  @FXML
  private void initialize() {
    initializeButtonsArray();
    putButtonsOnGrid();
  }

  private void initializeButtonsArray() {
    for (int i = 0 ; i < BUTTONS_NUMBER_OF_COLUMNS ; i++) {
      for (int j = 0 ; j < BUTTONS_NUMBER_OF_ROWS ; j++) {
        buttons[i][j] = new Button("Button_" + i + j);
      }
    }
  }

  private void putButtonsOnGrid() {
    GridPane buttonsGridPane = new GridPane();
    for (int i = 0 ; i < BUTTONS_NUMBER_OF_COLUMNS ; i++) {
      for (int j = 0 ; j < BUTTONS_NUMBER_OF_ROWS ; j++) {
        buttonsGridPane.add(buttons[i][j], i, j);
      }
    }
    vBox.getChildren().add(buttonsGridPane);
  }
}


Why is crontab file periodically overwritten?

Question: I have a Ubuntu 12.10 server with an nginx user that I use to edit a crontab file. Periodically (maybe once every few hours? it's hard to tell), I notice that edits I have made as the nginx user have been deleted, and when I type crontab -e my last changes have disappeared. Once I make the changes again and save, the new file installs correctly, and the jobs run successfully until it reverts again at some stage in the future.
I am not a server admin expert, so I guess I'm asking what the best way to debug something like this is? Or if this is a common problem what the usual mistakes are that I might be making.
Thanks!
Comment: Is there any server management software, e.g. puppet, used on the server?
Comment: Nope nothing like that as far as I'm aware...
Comment: You mention editing a crontab file, what file are you editing?  A file in /etc/cron.d/?  A crontab spool file?  Are you sure there isn't a bug in your edit script?   I kinda suggest you look at switching over to files in /etc/cron.d/  They are less likely to be trashed.  Do you know the specific times?  Do you see anything in the log when the crontab gets trashed?
Answer: Argh! OK, this was a communication error. We're deploying a Rails app on the server which uses a gem called Whenever:
https://github.com/javan/whenever
This gem was overwriting the changes I made in the crontab file each time I deployed. Solutions are to either remove the gem, or to use it to set up the jobs.
Comment: I presume you filed a bug report there? :)


What does S in linux file properties mean?

Question: I'm creating directories and changing the permissions of them in perl with the following code:
umask 0000;
mkdir $path, 0770;
chown $userid, $groupid, $path;

Now when I do ls -l on a directory I've just created, they are as follows:
drwxrws---  2 user group 4096 Nov  3 15:34 test1

I notice for the group permissions, there's an s instead of x.
Even if I chmod manually to remove all permissions for the user and group ("chmod g=" and "chmod u=", it's still there:
d-----S---  2 user group 4096 Nov  3 15:36 test2

The internet suggests S means everything in the folder is run as su or something? I don't quite understand what it means but I figure I should understand seeing as these are webroots so if there's a security implication, I ought to be aware of it.
Many thanks for your help!
Comment: This is not a programming question, thus it is off-topic.
Comment: I did wonder. Which site do you suggest it should go instead? I was thinking serverfault but then I figure it's not really a sysadmin question either
Comment: [unix](http://unix.stackexchange.com/)?
Comment: Look at the footer - all non-beta sites are listed.
Answer: s means the setgid/setuid bit and the executable bit both are set
S means only the setgid/setuid bit is set
check out man chmod for more information.
Answer: This is happening because of the umask value you're setting.

The internet suggests S means everything in the folder is run as su or something?

That is incorrect.
If the setuid bit is set on an executable program, then it will execute with the privileges of its owner.
If the setgid bit is set on the executable program, then it will execute with the permissions of its group.
So, don't go around creating things as root:root with umask 0000.
Better yet, don't ever set that to your umask.
See here: http://linuxzoo.net/page/sec_umask.html

The number given as a parameter to the umask command works in a opposite manner to the number given to the chmod command. The 'mask' serves to remove permissions as opposed to granting them.
Answer: In a way, it indicates an "error":
There is no point in setting the setuid bit, if the executable bit is not set.


Translation of sql query to Mongo languague

Question: I am trying to do the following query in Mongo:
SELECT *
FROM events
WHERE v1 - v2 > 20;

where v1 and v2 are names of columns in the SQL DB.
how can I translate it to Mongo Languague?
Answer: Assume you have these documents in your events:
{
    "_id" : ObjectId("54cdfde528bb923955eff8b4"),
    "v1" : 35,
    "v2" : 10
}

/* 1 */
{
    "_id" : ObjectId("54cdfde928bb923955eff8b5"),
    "v1" : 10,
    "v2" : 20
}

You cant use a simple find() query. You should use aggregation:
db.events.aggregate(
[
    { $project : { 'diff' : { $subtract : ['$v1', '$v2'] }, v1 : 1, v2 : 1 } },
    { $match : { diff : { $gt : 20} } },
    { $project : { v1 : 1, v2 : 1 } },
]).result

the result is:
{
    "0" : {
        "_id" : ObjectId("54cdfde528bb923955eff8b4"),
        "v1" : 35,
        "v2" : 10
    }
}


Firebase: pegar utilizador pelo seu email em Javascript FIrebase v9 (modular)

Question: Olá,
na minha plataforma implementei o sistema de login com a autenticação do firebase.
Como posso pegar um utilizador do firebase, segundo o seu email?
Este código retorna as informações do utilizar loggado no momento. Eu quero o retorno de um utilizador segundo um email que eu recebo de um input.
import { getAuth } from "firebase/auth";

const auth = getAuth();
const user = auth.currentUser;
if (user !== null) {
  // The user object has basic properties such as display name, email, etc.
  const displayName = user.displayName;
  const email = user.email;
  const photoURL = user.photoURL;
  const emailVerified = user.emailVerified;

  // The user's ID, unique to the Firebase project. Do NOT use
  // this value to authenticate with your backend server, if
  // you have one. Use User.getToken() instead.
  const uid = user.uid;
}

Estou a utilizar Firebase/JS - Versão 9 para a Web (modular).
Não sei se faz diferença, mas a estrutura da base de dados em tempo real, segue abaixo.
Comment: Se você quer logar por e-mail/senha pode usar o método signInWithEmailAndPassword. Para retornar os dados somente com e-mail pode pesquisar por getUserByEmail https://firebase.google.com/docs/auth/admin/manage-users?hl=pt-br
Answer: Você pode usar a função equalTo para isso:
import { getDatabase, ref, query, get, orderByChild, equalTo } from "firebase/database";

const emailInput = "email@example.com"; // exemplo de email

const dbRef = ref(getDatabase());
get(query(dbRef, `users`), orderByChild(`email`), equalTo(emailInput)).then((snapshot) => {
  if (snapshot.exists()) {
    console.log(snapshot.val());
  } else {
    console.log("No data available");
  }
}).catch((error) => {
  console.error(error);
});


Supremum of sequence

Question: I have this sequence
$$
\begin{cases}
x_1=3 \newline  x_{n+1}=(-1)^{n}\sqrt{3+2|x_n|}\\
\end{cases}$$
I have to find the $\inf {x_{2n}}$ and $\sup{x_{2n}}$
but when I try to check the second condition of $\inf$ and $\sup$ it doesn't make sense.
Comment: I see that this is a constant function always tends to -3
Comment: What about it doesn't make sense?
Comment: Have you tried computing a few values $x_i?$ You might notice something.
Comment: It's not constant but $x_n=\begin{cases}3&n\ odd\\ -3&n\ even\end{cases}$.
Comment: "ut when I try to check the second condition of inf and sup it doesn't make sense." The first condition if if $s =\inf x_{2n}$ then $s$ is a lower bound of $x_{2n}$.  As $x_{2k} =-3$ for all $x_{2k}$ we have $-3 \le x_{2k}=-3$ for all $x_{2k}$.  So $-3$ is a lower bound of $x_{2n}$.  That's done.  The second condition is that if $a > s$ then $a$ is not a lower bound.  If $a>-3$ then $a_2 =-3 < a$ so $a_2 < a$.  Furthermore *all* $x_{2k}=-3< a$.  So $a$ can not be a lower bound for any $a>-3$. That's the second condition.  So $-3$ satifsies the two conditions.  So $-3=\inf x_{2n}$....
Comment: Same can show $\sup x_{2n} = -3$.  For all $x_{2k}$ we have $x_{2x}=-3 \le -3$ and if $b < -3$ then $b < -3 = x_{2k}$ for all $x_{2k}$.  So $\sup x_{2n} = -3$. .... In general, if $x_{k_i}$ is a constant subsequence so that $x_{k_i} = c$ a constant.  Then $\inf x_{k_i} = \sup x_{k_i} = c$.
Answer: I am not sure if you are looking for the supremum/infimum of the whole sequence or just a subsequence but writing a few terms here gives you
$$x_1 = 3 \\
x_2 = (-1)^1 \sqrt{3+2|x_1|} = -\sqrt{3+2\cdot 3} = -\sqrt{9} = -3 \\
x_3 = (-1)^2 \sqrt{3+2|x_2|} = \sqrt{3+2\cdot 3} = \sqrt{9} = 3 \\
\vdots$$
You can convince yourself that $x_{2k-1} = 3$ and $x_{2k} = -3$ for $k \geq 1$.

Supremum of sequence


Question about unique representation of reals

Question: The wiki on construction of real numbers from Cauchy sequences says

A practical and concrete representative for an equivalence class representing a real number is provided by the representation [of Cauchy sequences] to base b. For example, the number π = $3.14159$... corresponds to the Cauchy sequence $(3,3.1,3.14,3.141,3.1415,...)$.

But you can just as easily write it as, for example, $(150,34,5, 4.1, 3.17, 3.15, 3.14,  3.1415, ...)$. That sequence is Cauchy, and it is equivalent to $(3,3.1,3.14,3.141,3.1415,...)$ because their difference tends to zero.
So how is $(3,3.1,3.14,3.141,3.1415,...)$ a unique representation (in base 10)?
Answer: In this construction reals are equivalence classes, as you understood. What your quote says is that one method to take a representative of a class is to take a base b development of the number you want to get. What you have is indeed a member of $\pi$ (seen as an equivalence class), Wikipedia just gave you some canonical representative.


How is R calculating prediction intervals for the mean response at x0? Manual calculation yields different results

Question: EDIT: It appears that for this particular problem I made a simple arithmetic error. I am now getting the same results. What prompted me to write this question was that this is the third time that I've had this problem. However, in the past, I was mistakenly using interval="predict" when I should have been using interval="confidence".
I am trying to compute a 95% confidence interval for a mean response on a small dataset, yet when I calculate this manually I get a very different interval. How is R calculating the interval when using predict.lm? Am I using the wrong function call? I verified that my manual calculation is correct with the solutions manual.
Computing a 95% confidence interval for a mean response at $x_0 = 170$ for the following dataset:
      x        y
1   170   162.50
2   140   144.00
3   180   147.50
4   160   163.50
5   170   192.00
6   150   171.75
7   170   162.00
8   110   104.83
9   120   105.67
10  130   117.58
11  120   140.25
12  140   150.17
13  160   165.17

I calculated the confidence interval using the following equation from my book:
$$
\hat\mu_{y|x_0}\pm t_{\alpha/2, n-2}\sqrt{MS_{\rm res}\left(\frac 1 n + \frac{(x_0-\bar x)^2}{S_{xx}} \right)}
$$
And I got an interval of $168.36\pm23.465$ (or alternatively, $(144.895, 191.825)$). When I did this manual calculation, the MSRes I calculated is the same as the output from calling anova(model). Additionally, I calculated Sxx in R as follows:
# Results are equivalent:
sum((data$x - mean(data$x))^2) # = 6230
(length(data$x)-1)*var(data$x) # = 6230

However, when I calculate this in R, I get the same fitted value but a different interval:
> predict.lm(data.lm, newdata=data.frame(x=170), interval="confidence", level=0.95)
       fit      lwr      upr
1 168.3611 153.9071 182.8152

Why is R giving me an incorrect interval? Or is my textbook simply wrong? This also applies to a 95% prediction interval on the same $x_0$, using the following equation:
$$
\hat y_0 \pm t_{\alpha/2, n-2}\sqrt{MS_{\rm res}\left(1 + \frac 1 n + \frac{(x_0-\bar x)^2}{S_{xx}} \right)}
$$
Comment: (For whomever: this seems like as much a statistical question as an R code question; I think it should be on topic here.)
Comment: It seems that I made a silly error. Please see my edit at the top of my question. Should this question be closed at this point?
Comment: I see no need for this question to be closed. IMO, clarifying these calculations has intrinsic value irrespective of the original motivation.
Answer: It's hard to guess what you might have done wrong since Sxx and MSres are correct. Perhaps the t-value? Here is the calculation done by hand in R to confirm that the R answer agrees with the formula:
data <- structure(list(x = c(170, 140, 180, 160, 170, 150, 170, 110,
120, 130, 120, 140, 160), y = c(162.5, 144, 147.5, 163.5, 192,
171.75, 162, 104.83, 105.67, 117.58, 140.25, 150.17, 165.17)), .Names = c("x",
"y"), row.names = c(NA, -13L), class = "data.frame")

data.lm <- lm(y~x, data=data)

# get prediction
pred <- predict.lm(data.lm, newdata=data.frame(x=170), interval="confidence", level=0.95)

# correct t-value
tval <- qt((1-0.95)/2, df=13-2)

# correct Sxx
Sxx <- sum((data$x - mean(data$x))^2)

# correct MSres - note division is by the number of df (but you have this right anyway)
MSres <- sum(data.lm$residuals^2)/11

# confidence interval calculated by hand
sqrt(MSres * (1/13 + (170 - mean(x))^2/Sxx)) * tval * c(1, -1) + pred[1]

# compare with R interval calculation
pred

Comment: Thanks for the input. I made a silly mistake in my calculation, and I ended with the same result as you. Also, it appears that my misconception is with what interval type to use for a given problem--the mistakes I have made in the past is because I was using `interval="predict"` when in fact I should have been using `interval="confidence"`. I would make the mistake of assuming `predict` whenever the problem gave me a new value for x.

Thank you for helping me see this! Our instructor couldn't help me since he is not familiar with R.


SQL Query Update using a join

Question: Here is my SELECT statement that lists what I am trying to change;
SELECT

t1.`qid`,
t1.`gid` as 'incorrect gid',
t1.`question` as 'subquestion',
t1.`parent_qid`,

t2.`qid`,
t2.`gid` as 'correct gid',
t2.`question`

FROM `questions` as t1

LEFT JOIN `questions` as t2 ON t1.`parent_qid` = t2.`qid`

WHERE t1.`sid` = '33844' AND t1.`gid` NOT IN ('1306','1317','1319','1320','1321','1322','1323','1324','1325','1326','1327','1328','1329','1330','1331','1332','1333','1334','1335''1334','1335','1336', '1337','1338','1339','1340')

I want to replace all the 'incorrect gid's with the 'correct gid's using an UPDATE statement.
This is the UPDATE statement I have tried but cannot get to work;
UPDATE `questions` as t1

SET `gid` = t2.`gid`

FROM

`questions` as t1
LEFT JOIN
`questions` as t2 ON t1.`parent_qid` = t2.`qid`

WHERE t1.`sid` = '33844' AND t1.`gid` NOT IN ('1306','1317','1319','1320','1321','1322','1323','1324','1325','1326','1327','1328','1329','1330','1331','1332','1333','1334','1335''1334','1335','1336', '1337','1338','1339','1340')

Basically, all the rows that are children have an incorrect gid (group id) and need to be fixed. But all rows that refer to the parent (as parent and children are in the same table) will have a correct group id.
So I have to join up the parents groupid, to each child row..
Answer: The correct syntax in MySQL:
UPDATE `questions` as t1 LEFT JOIN
       `questions` as t2 ON t1.`parent_qid` = t2.`qid`
    SET t1.`gid` = t2.`gid`
WHERE t1.`sid` = '33844' AND
      t1.`gid` NOT IN ('1306','1317','1319','1320','1321','1322','1323','1324','1325','1326','1327','1328','1329','1330','1331','1332','1333','1334','1335''1334','1335','1336', '1337','1338','1339','1340')

Comment: Apparently you're not supposed to use this box to say "thanks" but I'm doing it anyway! THANKS! It worked.

SQL Query Update using a join


Which sports broadcast gets the highest TRP rate?

Question: Which sports broadcast is watched by the most people in the world, on television or online?
Indirectly, which sports match gets the highest TRP rate?
Comment: Can you clarify what you mean by "TRP rate?" That's not a phrase I'm familiar with. (Also, how are you using the word "indirectly"?)
Comment: @pjmorse Thanks for comment, TRP = > Television Rating Point....
Answer: According to article from Whatculture FIFA World Cup with average viewer 3.5 billion is the most watched sport broadcast in the world. But FIFA says 3.2 billion and estimated 280 million people around the world watched matches online or on a mobile device.
And the 2014 World Cup final between Germany and Argentina in Brazil was watched by more than 1 billion viewers which suggest it might be the highest TRP match.


Is the Coefficient of Variation valid for data which does not follow a normal distribution?

Question: I am trying to compare the dispersion of several data vectors. As an example I have that via two methods produces one vector of data that fits a normal distribution and other one that follows an exponential distr. Is it valid to compare the CV of both and according to that affirm that one is more disperse than other? Should I somehow consider that both set of points do not fit the same pdf?
Comment: It's a relationship of the standard deviation to the mean. It is meaningless for distributions with 0 mean. That includes some normal distributions. I think it is actually more meaningful for distributions concentrated on the positive portion of the real line like the exponential distribution. I don't think it has an interpretation when  the mean is negative and certainly not for distributions that don't have a finite mean such as a Cauchy distribution.
Comment: @Wladimir I would usually not be inclined to use CV on data that *did* follow a single normal distribution. It is primarily useful when variance is proportional to the square of the mean, which practically speaking is typically restricted to strictly positive random variables.
Comment: @Glen_b my two data vectors follow a normal and exponential distribution each. And for both there are only positive values. What would you recommend in case of an exponential distribution to measure dispersion?
Comment: How can you know your data are drawn from these distributions?
Comment: @Glen_b following the kolmogorov smirnov test, after computing the p-value of several distributions (normal, expon, pareto, etc.), I can confirm that the data follows the distribution with the highest p-value. I confirmed this also by drawing the histogram and the corresponding fitted pdf.
Answer: Partially answered in comments, but first, very short: CV is mostly useful on distributions concentrated on the positive numbers, excluding normal distributions!

It's a relationship of the standard deviation to the mean. It is
  meaningless for distributions with 0 mean. That includes some normal
  distributions. I think it is actually more meaningful for
  distributions concentrated on the positive portion of the real line
  like the exponential distribution. I don't think it has an
  interpretation when the mean is negative and certainly not for
  distributions that don't have a finite mean such as a Cauchy
  distribution.

– Michael R. Chernick

@Wladimir I would usually not be inclined to use CV on data that did
  follow a single normal distribution. It is primarily useful when
  variance is proportional to the square of the mean, which practically
  speaking is typically restricted to strictly positive random
  variables.

– Glen_b -Reinstate Monica


Show that $\sqrt{-6}$ is irreducible in $\mathbb{Z}+\mathbb{Z}\sqrt{-6}$

Question: Suppose not. Then there exists $\alpha,\beta\in\mathbb{Z}+\mathbb{Z}\sqrt{-6}$ such that $\sqrt{-6}=\alpha\beta\implies\alpha,\beta$ are not units. I'm not really sure where to go from here. Any advice?
Answer: The concept of norm is extremely important, including the fact that it is multiplicative (meaning that $N(m) N(n) = N(mn)$). Learn it, love it, live it.
What really makes things easy in $\mathbb{Z}[\sqrt{-6}]$ (which is the same thing as $\mathbb{Z} + \mathbb{Z}\sqrt{-6}$, right?) is the fact that there are only two units: 1 and $-1$. How do we know those are the only units? A unit has norm 1 or $-1$. The norm of a number of the form $a + b \sqrt{-6}$ is $a^2 + 6b^2$, so the norm can't be negative. The possible norms in $\mathbb{Z}[\sqrt{-6}]$ are 0, 1, 4, 6, 7, 9, 10, etc. (see Sloane's A002481). Both 1 and $-1$ have a norm of 1, no number in this domain can have a norm of $-1$. If $a > 1$ or $b > 1$, then $N(a + b \sqrt{-6}) > 1$.
2 and 3 are potentially prime because no number in this domain has a norm of 2 or 3. But, as you already know from the other question you asked, $2 \times 3 = -(\sqrt{-6})^2 = 6$, which means 2 and 3 are irreducible but not prime in this domain.
But what about $\sqrt{-6}$? Its norm is 6. If it's reducible, we can find two numbers, neither of them 1, such that $N(\alpha) N(\beta) = 6$. So we're looking for a number with a norm of 2 and another with a norm of 3. But we just saw that there are no numbers in that domain with that norm. Therefore, $\sqrt{-6}$ is irreducible.
If you really want to be sure, you can try each product $(a - b \sqrt{-6})(a + b \sqrt{-6})$ for $0 \leq a \leq 3$ and $b$ likewise.
Answer: A start: Use the fact that in general $N(\alpha\beta)=N(\alpha)N(\beta)$. Here $N(\gamma)$ is the norm of $\gamma$. The norm of $x+y\sqrt{-6}$, where $x$ and $y$ are integers, is $x^2+6y^2$.
Comment: $\sqrt{-6}$ is very much not a unit, it has norm $6$. The only units are $\pm 1$.
Comment: $\sqrt{-6}$ is a unit, since $\frac{-\sqrt{-6}}{6}*\sqrt{-6}=1,$ so $\alpha\beta$ is a unit $\implies 1=N(\alpha\beta)=N(\alpha)N(\beta)$?
Comment: Oh, I misunderstood the definition. I was thinking of multiplicative inverse in the group of units. Thank you, I think I see what to do now.


Unable to deploy my react app to google cloud platform vm

Question: I started learning Google Cloud Platform recently. So, created a trial account. Can I deploy my learning web application to the VM I created and browse it from my local? I tried running gcloud app deploy from my vm but getting error...
== ERROR: (gcloud.app.deploy) PERMISSION_DENIED: The caller does not have permission==

Comment: The `gcloud app deploy` command deploys your app to App Engine and not to your VM. Start reading the documentation and then figure out which service your want to use. Google has good getting started examples.
Answer: VM (Compute Engine) and App engine are two different things, you can read more in this answer. gcloud app deploy is app engine utility and used to deploy your application to app engine.
If you have your code in compute engine and want to deploy to app engine, make sure service account associated with your vm has necessary scopes and permissions. Please check this answer.
On addition to that you can start with cloud shell for deploying your web application.