What are some common patterns used when playing the piano/keyboard in a pop/rock band setting?

Question: I've been trying to learn to play the keyboard for a few years now and think it would be cool to eventually get to the point where am able to play as part of a group.  The problem is that I really have no idea how to go about reaching this goal.  I'm in my early 30s, so if I want to play with people around my own age, they will almost certainly be people who are already quite experienced with their instrument, and who expect that their keyboardist knows what he/she is doing.  So I'd think that a good way to practice would be by taking songs and simply playing them the way I would be expected to play them in a band.  The problem is that I really don't know what that would be.
What I've been doing so far is practicing songs' chord progressions with my left hand playing the root note and my right hand playing the chord, like what you might see in a piano playing guide for beginners.  But I get the impression that experienced keyboardists often won't play like this in a real pop/rock band situation, especially if there is already a bassist.
So, what are some common patterns for playing the keyboard in a real band?  I'm not looking specifically for easy patterns targeted at beginners (or difficult ones found in complex jazz), but rather conventional ones found in your average pop/rock band (whether easy or hard).
So, the two main things I'm looking for are

What does my left hand do?  And what does my right hand do?
What are some common rhythmic patterns?  What I'm practicing now is very basic and quite boring (usually just quarter notes for both hands).  How can I make it more interesting?

I'd appreciate any advice you could give.
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/134515/discussion-on-question-by-sean-what-are-some-common-patterns-used-when-playing-t).
Answer:
I've been trying to learn to play the keyboard for a few years now and
think it would be cool to eventually get to the point where am able to
play as part of a group. The problem is that I really have no idea how
to go about reaching this goal.

This makes it seem that you'd like to practice alone at home, until you know everything and can come out as a fully trained keyboard player, without having to face other people as a not-yet-fully-competent beginner. Sort of like, wanting to learn a language completely before trying to speak with anyone. But the thing is, you learn to play keyboard parts in a band by playing keyboard parts in a band. Go there and try something, and your learning will be boosted to a completely new level. One hour of actual real playing is worth ten hours of practicing alone.

I'd think that a good way to practice would be by taking songs and
simply playing them the way I would be expected to play them in a
band. The problem is that I really don't know what that would be.

I think there's a mistake here. You're looking at entire songs, when you should be looking at keyboard parts of song arrangements. Look at what keyboard players do in bands.
There are many different categories of things keyboard players do. On an abstract level, the parts can be looked at from several perspectives: rhythm, harmony, pitch, texture, or the overall big story of a song. Or melody which has aspects of all of those. On a less abstract level you could think about things like (1) rhythmic comping, (2) background pads, (3) melodic playing. And then do it so that it supports the song and what everyone else is doing.
General considerations
These aspects actually apply to all instruments, not just keyboards. But since keyboards can sound like anything, it's particularly important to think about fitting together with everyone else.
Fitting together rhythmically: if you play rhythmic comping, make sure that it fits in with how the bass, guitar and drums are comping rhythmically. If you use a sound that has a clear loud attack, you have to think that it's a drum.
Fitting together harmonically: your parts have to be in  a pitch range that goes together with the other instruments. And it has to play the right notes so the overall chord makes sense.
Fitting together melodically: if your parts have a melodic element, it has to fit in with the lead vocals and any other melodic lead instrument. Fill in the gaps, don't step over the existing melody. Think about it as "counterpoint".
Fitting together as a texture: if there's a very bright guitar sound, you might want to play something more mellow or dark. If everything else is very thick, play something less thick.
Things to play on keyboards in general
Types of things to do on a keyboard are:

(1) rhythmic comping. Like guitar strumming, but on a keyboard. This can be (a) two-handed left/right alternation ("stride"), (b) one-hand backbeat like in reggae, (c) chord arpeggios in a steady rhythm, (d) any other rhythm. 3-2 clave? Bossa nova? You need to think about what the rhythm pattern of the whole group is. If your group was a salsa band's rhythm section, which part do you play - conga, timbale, shaker, clave, cowbell? Do you double an existing rhythm part, or play complementary counter-rhythms?
(2) background pad. You play slow pad sounds which create a harmonic background filling. Either full chords or even just single-note lines. A high legato strings sound that stays as close to some single pitch as possible in a voice-leading sort of way can glue together the whole sound of the group. In a chord progression C, F, Gsus4, G, C, your single-note legato line would play the notes C, C, C, B, C.
(3) melodic fills. You play countermelodies and "fills". For example with a brass sound or a "heaven/fantasy bell".
(4) melodic doubling. You double an existing melody and give it more power. Either in unison, or e.g. a third/sixth above or below.
(5) special effects. Come up with a strange sound and add it sparingly somewhere in a song. It may catch the listener's ear and make the song memorable.
(6) full piano accompaniment. All of the above at the same time. You play as if there were no other players in the band, and others adjust to your piano playing. This is typically done in slow ballads. It's also a potentially dangerous thing to do, if others don't agree with you taking the whole stage.
(7) synth solos. Well, not everybody does this at all. You play like a guitar solo, but on a synth. Impress everyone and show off what you can do.

Particular standard keyboard instruments
A lot of the time, a keyboard player can just play "synths" and quite freely select the type of sounds to use and what to do with them. But there are a few specific real physical keyboard instruments with specific commonly known uses and genres that a keyboard player should know about. I would call these standard instruments, and they were widely used by keyboard players before around the 1970s or 1980s, when synthesizers started to be utilized for all kinds of sounds and a keyboard could sound literally like anything. Standard keyboard instruments include:

The acoustic piano, of course. You should know what sort of things are generally played with acoustic pianos in pop/rock. For pop/rock check out Jerry Lee Lewis, the Beatles, Carole King.
"Rhodes" i.e. electric pianos such as Fender Rhodes and Wurlizer. Used a lot in soul, r&b and jazz. Check out Feel Like Makin' Love by Bob James (great version by Roberta Flack), or Riders on the Storm by the Doors.
Clavinet. Check out Superstition by Stevie Wonder.
The Hammond organ. Electric drawbar organs, usually with "Leslie" rotating speakers and slightly distorted sounds are used in a lot of soul and rock music. This is an art form in itself, and in some bands, there is an organ player that plays a Hammond organ only. But for specific songs, a keyboard player might be tasked to play a Hammond part, because there has to be a Hammond sound in that song. Any other sound would be wrong. Check out Smoke on the Water by Deep Purple, or A Whiter Shade of Pale by Procol Harum.

Mimicking other, non-keyboard instruments
In addition to the standard keyboard instruments listed above - which happen to fit well for a generic synthesizer-workstation-do-it-all instrument - you may be asked to create the sound of other, non-keyboard instruments. For example, a brass section or a violin section. Or an accordion. Maybe a harp or a marimba. In my opinion, this is risky, because it can sound cheap and awkward, if you hear a horn section or an accordion, but none are to be seen on the stage. But that's nevertheless done quite routinely by keyboard players. In order to come up with a credible marimba part, you have to know what and how is played on a marimba.
What's the simplest thing to get started?
The above is already a lot of things to learn. But the good news is, you don't need to do all of that, or even most of that at all. Do one simple thing that supports the band, and you're already adding a significant contribution. The most important thing that's required from any band member is to be a nice person and support others. I recommend starting with the following simple thing: play pads with 1-3 notes and follow the song parts. For example, in a verse, play a single chord tone for every chord, and in a chorus, play three-note chords. For the sound, pick a synth pad or electric piano sound. This is very easy to do, and if you don't play the wrong notes, you'll make a positive contribution. If you can sing backing vocals in the chorus as well, even doubling the lead melody, you'll be a super useful band member.

What does my left hand do? And what does my right hand do?

It depends on which musical element (of the listed 7 things) you're doing. If you're playing synth pads, you only need one hand or one finger. You don't have to use both hands. As a matter of fact, you don't have to play at all! One of the common mistakes that pianists do is when they try to play keyboards, they play too much all the time, "full piano accompaniment" all the way and they never shut up. Don't do that! Do one thing only. Play a tambourine if you absolutely must do something with your hands all the time.
If you're tasked with mimicking a non-keyboard instrument like a harp, you do whatever it takes to do that on your keyboard. Left or right hand? What rhythm patterns? Whatever a harp usually does.

But I get the impression that experienced keyboardists often won't
play like this in a real pop/rock band situation, especially if there
is already a bassist.

You're on the right track here! But you need to look at all instruments, not just the bass. And consider that the drummer actually plays several instruments: the kick drum, the snare drum, the hi-hat, etc. The guitar is capable of stepping on all the toes and fingers of a keyboard player and vice versa. A lead singer is the most important single instrument. How does your playing relate to the lead vocals?

What are some common rhythmic patterns? What I'm practicing now is
very basic and quite boring (usually just quarter notes for both
hands). How can I make it more interesting?

There are no rhythmic patterns specifically for keyboards that you could always add to any song without thinking, and a rhythmic pattern's being "interesting" does not necessarily make it a good fit for a song. The whole band together creates one big rhythmic pattern, and your job is to understand the big picture and what your own playing does to it. Even if everyone plays something that is extremely "interesting" by itself, if they don't serve the same idea, putting them together will create chaos and rhythmic noise. You have to contend with being a small part in a big puzzle.
Quarter notes are actually quite a lot of rhythmic hits already. Start by playing just on beat one of each bar, and with your right hand only. Record your playing over a song that doesn't have keyboards, and listen to it later on. Is your keyboard part making the song better or worse?
Comment: "You don't have to use both hands." – Indeed. If your band has a bassist, as most pop/rock bands would, when in doubt, don't use your left hand.
Comment: There are too many pianists who want to play in bands out there that anyone who is less than "fully trained keyboard player" would get a chance
Comment: @ojs I don't necessarily disagree, but then again, there are lots of bands where a guitarist or singer adds in simple keyboard parts in some songs where they think it's needed. Something like a synth pad in a bridge or a melodic "obligato" that people expect. It doesn't have to be difficult at all, as long as you're a team player and support the music.
Comment: Yup. The problem is that the singer, guitarist, percussionist if they have one or even drummer with pads can do that. No need for keyboardist.


Getting whitespace while reading XML using XMLTextReader

Question: I am reading an XML using XMLTextReader in C#.net. The structure of XML is like below:
<root attr1="" attr2="">
    <element1>some value</element1>
    <element2>some value</element2>
</root>

After reding attributes, I shift control to element1. Code is as below:
reader.MoveToElement()
if(reader.ReadToDecedent("element1"))
{
    string val= reader.ReadInnerXML();
}

Now after reading this, reader shows whites space. Again I want to move to element1 and from there, using ReadToDecendent I want to move to element2. I cannot use MoveToContent() as I have to follow the same flow.
So how can I move to element1 after reader inner text?
Answer: Have you considered using XPathDocument and the related classes? It would look like such:
var _xml = "<xml><elements><element1>some text</element1><element2>some more text</element2></elements></xml>";
var xPathDoc = new XPathDocument(XmlReader.Create(new StringReader(_xml)));
var nav = xPathDoc.CreateNavigator();
var node = nav.SelectSingleNode("//element1");  // with xpath exp you can pick out specific tags
var innerText = node.Value;

Now if you just had element as the name of the tags instead of element1, element2,... you can iterate through all element tags:
var nodes = nav.Select("//element");  // selects all element tags
while(nodes.MoveNext()){
    //do something
}

This is probably a simpler way to query a xml doc. Plus, if you wanted tags that had a specific attribute, the xpath expression would be //element[attr1=\"atrribute_value\"]
Hope this helps


Chi-square test or Fisher's Exact test

Question: Fisher's exact test is applied when sample size is small.  In this link it is said that

If any expected counts are less than 5, then some other test should be used (e.g., Fisher exact test for 2x2 contingency tables)

This link http://www.theanalysisfactor.com/observed-values-less-than-5-in-a-chi-square-test-no-biggie/ also gave similar statement.
But here http://www.biostathandbook.com/fishers.html author recommended to  use Fisher's exact test when the total sample size is less than 1000.
Can I use a Fisher's exact test whatever the sample size is?
Edit:
I know Fisher's exact test is conservative and many authors recommend not to use this conditional test rather an unconditional test should be used (Reference: Recommended tests for association in 2×2 tables) .
Then my question is more precisely that when should I do an exact test instead of chi-square test?
Comment: The comments only concern the chi square approximation that is used. Sample size is not much of an issu as it is with the chi square.e with Fisher's test.  The only restriction involves assuming that the marginal total are assumed to be fixed.
Comment: You don't *have* to have fixed margins to use the Fisher exact test, you only need to be willing to condition on the (almost ancillary) margins.
Comment: @MichaelChernick Exact test can be done in 3 case: (1) Both margins fixed (Hypergeometric Dist'n)→Fisher's exact test
(2)One margin fixed (Double Binomial Dist'n)→Barnard's exact test
(3)No margins fixed (Multinomial Dist'n)→Barnard's exact test. https://stats.stackexchange.com/questions/169864/boschloo-or-barnard-which-test-for-cross-table-analysis. If sample size is not an issue of exact test, then why is there chi-square test? Can't I always perform an exact test in a $R\times C$ contingency table whatever the sample size is?
Comment: You were referring to Fisher vs Chi square and what I said about fixed margins is correct.  Other types of exact tests were not mentioned in the question.
Answer: When the chi-squared test is inappropriate due to small sample sizes or highly unequal cell distribution, one can instead use Fisher's exact test.The chi-squared test is basically an approximation of the results from the exact test, so erroneous results could potentially be obtained from the few observations.
Comment: The assumption of fixed margins is required for Fisher's exact test but not necessarily for the chi square test.
Comment: It is not true that fixed margins is an *assumption* of the Fisher exact test. You might decide to condition on the marginals. See comment of Glen_b on Q itself.

Chi-square test or Fisher's Exact test


Theory confusion

Question: In every book and website I look at it says for guitar that sharps and flats are on the same fret for example C sharp and D flat are both on the forth fret of the a string and I've seen that it is similar for piano. However I saw on a violin web page that it can play a flat and G sharp as separate notes and the a flat is on the G string so why are violins able to separate the notes but not guitars and pianos? that's assuming the information is OK. Also why are the sharps and flats sometimes identified even though they are using the same fret or piano key? for example on sheet music and chord Books.
Comment: "Also why are the sharps and flats sometimes identified even though they are using the same fret or piano key?" - a good answer to that (suitable for a beginner) would be too long for this forum, but when you start to study scales, chords, and harmony the answer should become clear. There are many books and websites that explain those topics.
Comment: See [this question and answer](http://music.stackexchange.com/a/23977/7222) for your last question.
Comment: The top answer is pretty detailed.  But the short of it is a difference in Just and Even Tempered tuning.  Guitars and Pianos are tuned for even (or equal) temperament.  The half steps are defined by the irrational number 12th root of 2.  Violins and other fret less instruments are played (or can be played) in just tuning.  See below answer for details on the ratios for the Just scale.
Answer: I suggest reading this answer first (where I derive the stuff I talk about here with some extra graphics).

Western music is derived from diatonic scales, like the one created by all the white keys on piano. Not sharps and flats at all! Such diatonic scales are based on just intonation, i.e. intervals that sound good because of objective physical reasons, namely a low integer frequency ratio, which causes some overtones to match up. To be precise: Western diatonic scales are originally Pythagorean, but by the time of Renaissance the thirds were made mostly Ptolemaic. This is still the scale that's naturally used by singers and string instruments when playing in harmony (especially at long major chords, where there's time to really eliminate all impurities (beat) from the sound).
The ratios of a Ptolemaic scale in C are as follows (frequency in Hertz and ratio to tonic):
264     297    330  352     396    440      495 528     594    660  704     792
1/1     9/8    5/4  4/3     3/2    5/3     15/8 2/1     9/4    5/2  8/3     3/1
 C       D      E    F       G      A        B   C       D      E    F       G
Again note there are no real semitones (as in, halves of whole tones) here – most of the intervals are different from each other, for instance the interval from D to E is a bit smaller than the one from C to D!
Nevertheless, there is some symmetry: if we start another diatonic scale from the F, we notice that most of the notes reoccur:
264     297    330  352     396    440      495 528     594    660  704     792
 C       D      E    F       G      A        B   C       D      E    F       G

                    352     396    440  469⅓    528    586⅔    660  704     792
                    1/1     9/8    5/4  4/3     3/2    5/3     15/8 2/1     9/4
                     F       G      A    B♭      C      D       E    F       G
There are only two discrepancies:

The fourth note with 469⅓ Hz is very notably lower than the one that would come there in the C-based scale. These really can't be replaced for one another, hence this note is always given a different name: B♭ instead of B.
The sixth note is also a bit lower than the ninth in the C scale. Is this important? Well, our ears can't measure pitch with infinite precision. Players and singers always stray somewhat away from the "ideal" pitch anyway. To most listeners, it would not be quite obvious what's wrong if you replace 594 Hz with 587 Hz, though in some chords it will definitely cause a bit of an impure sound.

This kind of difference between two notes in different just-intonation scales is essentially also what's different between e.g. C♯ and D♭, just there it's even stronger yet harder to notice because you need to modulate across a whole bunch of different keys in the circle of fifths.
The idea behind tempered tunings, in particular the 12-edo scale that you find on modern pianos, is to simply disregard these small differences and use a compromise somewhere in between, which will work for all scales equally well (though not quite perfectly for any of them). For comparison, the two Ptolemaic scales and the equally-spaced 12-edo scale (rounded to integer Hertz frequency) between them:
264     297    330  352     396    440      495 528     594    660  704     792
263 278 295 313 331 351 372 394 417 442 468 496 526 557 590 625 662 702 743 788
                    352     396    440  469⅓    528    586⅔    660  704     792
 C       D      E    F       G      A        B   C       D      E    F       G
As you see, this matches the just-intonation scales pretty well on most tones, only on the thirds of each scale (E and A) are a bit higher. Indeed that's the biggest problem with the 12-edo scale: major thirds are sharp, sounding a bit restless. This is especially notable when playing chords on distorted guitar, which in turn is a reason why rock guitar tends to prefer playing only powerchords (pure fifths): fifths don't have that deficiency in 12-edo!
So, to answer the question: why are violins able to separate the notes but not guitars and pianos – well pianos would ideally be able to separate them too, but for practical reasons they are designed so these enharmonically equivalent notes are actually played on the same key.
Comment: Just a couple of things I'd add: not all tempered tunings aim to be equally good/bad in all keys. Some are great or near-perfect in one key, not so great in the adjacent keys, then increasingly worse the further away from it you get. This does give keys interestingly different characteristics, although isn't suitable for music which travels far from the home key. And also, that the ultimate difference between a perfect G# and a perfect Ab is that G# is very slightly flatter than Ab. Most of the time, anyway. Really perfect tuning is about what roles each note plays, not what they're called.
Answer: Violins are fretless instruments, whereas guitars have frets. This means that the placement of the guitar fret determines the placement of this A♭/G♯. A violinist, however, can move their finger ever so slightly in either direction to adjust the tuning of the A♭/G♯ as they see fit in a given musical environment.
Although A♭/G♯ are the same in an abstract sense (and from a standpoint of what we call twelve-tone equal temperament), the pitches can be different based on what's happening in the music. The most obvious example is from a standpoint of just intonation, where a G♯ in an E major chord will need to be lowered significantly, whereas an A♭ in an A♭ major chord will (can) actually be tuned higher than the G♯!
Answer: Another factor that applies to the violin is the "standard" way that the fingers of the left hand are used to stop the strings. Because of the (relatively small) size of the instrument, the most natural way is to use successive fingers for successive notes of a major or minor scale, without needing to move your hand position.
So if you are playing in A flat major, the notes on the D string would be fingered
1 - E flat
2 - F natural
3 - G natural
4 - A flat

(1 is your index finger, 4 your pinky). But in A major, you would use
1 - E natural
2 - F sharp
3 - G sharp
4 - A natural (if you don't want to use the open A string)

So in that sense G sharp and A flat are "different notes" for a violinist because they are played with different fingers, even if they are at exactly the same pitch.
The strings on a guitar are nearly twice as long as the violin, so keeping your hand in a fixed position on the neck of a guitar while playing different notes is less practical. So guitarists tend to think of a which fret corresponds to each note, and the left hand finger they use for that fret depends on the notes that precede or follow it.
Answer: As Richard says, because the violin is fretless, you can slightly alter the pitch of every note to create the temperament that you want. I might have two songs containing 'B', and in one case I might pitch the 'B' a bit higher- even when the notes are named exactly the same, the same chromatic note might have different pitches.
So when your source says...

I saw on a violin web page that it can play A flat and G sharp as separate notes

...I think that's potentially misleading, because the fact that the notes are named differently is not itself a definitive reason to play the same chromatic note at different pitches.
It would imply that you were playing in a different key though, so if you were not trying to play in equal temperament, a difference in pitch would be likely. So it's not an incorrect statement, but it is conflating two different concepts.
Answer: All disciplines have their own Vocabulary, 'Music Theory' also has words to explain their idiosyncrasies.
The 'Concept you describe' in 'basic music theory' is called: En-harmonic!
Two names for one musical tone.
The C Major Chromatic Scale is, C,C#,D,D#,E,F,F#,G,G#,A,A#,B... *
( 12 semi tones )*. Sharps are added in Ascending Order.
Flats are used in descending order, C,B,Bb,A,Ab,G,Gb,F,E,Eb,D,Db.
No ( flats or #'s ) between B&C / E&F ).
( C# is en-harmonic to Db. G# is en-harmonic to Ab,... same tone, different name ).

Theory confusion


How to calculate integral $\int_{0}^{\infty}x\ \operatorname{sech^3}(x)dx$

Question: For this integral, I used the identity
$$
\operatorname{sech}^3(x) = \frac{8e^{-3x}}{(1 + e^{-2x})^3} = 4\sum_{n=1}^{\infty}(-1)^{n-1}n(n+1)e^{-(2n+1)x}
$$
After replacing this expression in the given integral, using Laplace transforms, I obtained a divergent series. I know the answer is G (Catalan constant) - $\frac{1}{2}.$
Comment: @an4s: Divide your result through by $\mathrm e^{6x}$ to obtain the OP's.
Comment: Shouldn't it be $$\operatorname{sech}^3(x) = \dfrac{8e^{3x}}{\left(1 + e^{2x}\right)^3}\quad?$$
Comment: The given power series does not converge for all $x\in[0,\infty)$
Comment: @joriki - thanks, that makes sense!
Answer: Recall the following integral representation of the Catalan constant
\begin{eqnarray*}
\frac{1}{2} \int_{0}^{\infty} \frac{x}{\cosh(x)} dx =G.
\end{eqnarray*}
Using $\operatorname{sech}^2(x)+\tanh^2(x)=1$ gives
\begin{eqnarray*}
 \int_{0}^{\infty} x \operatorname{sech}^3(x) dx +  \int_{0}^{\infty} x \operatorname{sech}(x) \tanh^2(x) dx =  \int_{0}^{\infty} x \operatorname{sech}(x) dx.
\end{eqnarray*}
Integration by parts on the middle integral
\begin{eqnarray*}
 &\int_{0}^{\infty} \color{blue}{x \tanh(x)} \operatorname{sech} (x) \tanh(x) dx = \\ & -\color{blue}{x \tanh(x)} \operatorname{sech}(x) ]_{0}^{\infty}+   \int_{0}^{\infty} (\color{blue}{x \operatorname{sech}^2(x)+ \tanh(x)})\operatorname{sech}(x) dx.
\end{eqnarray*}
Now
\begin{eqnarray*}
 \int_{0}^{\infty}  \tanh(x)\operatorname{sech}(x) dx=1.
\end{eqnarray*}
Rearrange and the result follows.
Answer: Integrate by parts
\begin{align}
&\int_{0}^{\infty}x\operatorname{sech^3} xdx\\
=&\int_0^{\infty}\frac{x \>\text{sech}\>x}{2\tanh x}d(\tanh^2 x)
=- \frac12\int_0^{\infty} (\tanh x \>\text{sech}\>x -x \>\text{sech}\>x)dx\\
=&-\frac12 + \frac12\int_0^{\infty}  x \>\text{sech}\>x
\overset{t=e^{-x}}{dx}
= -\frac12 + \int_0^{1} \frac{\ln t}{1+t^2}dt
= -\frac12 + G
\end{align}


Calcular número mínimo de permutações para ordenar

Question: Recebi esta questão em um teste, e gostaria de saber que caminhos tomar.
Tenho um array de n inteiros distintos, A = [a0, a1, ..., an-1].
Posso permutar quaisquer dois elementos do array qualquer número de vezes.
Como calcular o menor número de permutações necessárias para ordenar os elementos de maneira crescente?
Comment: Em alguma linguagem em especifico?
Comment: Em qualquer linguagem
Comment: Usando ponteiros resolve o seu problema
Answer: Existem vários algoritmos de ordenação, mas o principal entre eles é o quick sort.
Ele consiste em definir um dos elementos da lista como elemento pivô. No exemplo abaixo, é considerado o elemento 3 como pivô, sendo representado pelo risco preto. A finalidade é organizar todos os elementos que são inferiores ao pivô à sua esquerda e todos os que são superiores à sua direita. Assim, ao final, o elemento pivô já estará em sua posição final. Após, executa-se recursivamente a mesma lógica para os elementos à esquerda e para os elementos à direita, definindo novos elementos pivôs.
A lógica executada é a seguinte:

Verifica-se à direita do pivô, do final para o início, o primeiro elemento que seja inferior ao mesmo, permutando suas posições. No caso, o primeiro elemento inferior à 3 é o 1.
Verifica-se à esquerda do pivô, do início para o final, o primeiro elemento que seja superior ao mesmo, permutando suas posições. No caso, o primeiro elemento superior à 3 é o 5.
Repete-se a verificação do passo 1, encontrando o valor 2, permutando as posições novamente.
Repete-se a verificação do passo 2, encontrando o valor 4, permutando as posições novamente.
O elemento pivô estará em sua posição final, então repete-se o algoritmo para os vetores [1, 2] e [4, 5] separadamente, até o vetor estar completamente ordenado.

Quick Sort em Python
def quick_sort(vector):
  # Se o vetor tiver comprimento 1, terminou a ordenação:
  if len(vector) <= 1:
    return vector
  else:
    return quick_sort([x for x in vector[1:] if x < vector[0]]) + \ # Ordena o vetor a esquerda
           [vector[0]] + \                                          # Elemento pivô na posição final
           quick_sort([x for x in vector[1:] if x>=vector[0]])      # Ordena o vetor a direita

Veja funcionando no Repl.it

Mínimo de permutações
Dado que a pergunta se originou de um teste/prova, acredito que o conhecimento prévio sobre os algoritmos de ordenação era esperado, assim, para responder, posso tomar como referência que o Quick Sort já é o algoritmo mais eficiente e o que exige menos permutações durante a ordenação, com isso, basta que eu calcule o número de permutações que tal algoritmo fará para determinar o mínimo possível.
Considerando um vetor genérico, o pior caso acontece quando o pivô é o maior ou menor elemento e o vetor está previamente ordenado de forma inversa. Ou seja, o pior caso ocorre quando os sub-vetores são desbalanceados: um com tamanho n-1 e outro 0, sendo n o tamanho do vetor. Portanto, o número de comparações e permutações feitas em cada sub-vetor será n-1 para o vetor da esquerda e 0 da direita. Na segunda iteração, os vetores terão tamanhos n-2 e 1, portanto haverá n-2 comparações ao total. Assim continua até o vetor estar ordenado, portanto, o total de comparações/permutações será igual a:

O melhor caso ocorre quando o elemento pivô divide o vetor em tamanhos iguais, havendo n/2 comparações em cada sub-vetor, portanto o total é igual à:

Fontes:

Quicksort - Wikipedia
Quicksort - UFMG
Answer: Conforme o Anderson referenciou anteriormente um algoritmo bem eficaz para organizar um array é o QuickSort. O algoritmo consiste em Fixar uma posição do array e comparar o valor referente à essa posição com as demais e quando chegamos na na última posição n-1, já não precisamos fazer nenhuma comparação.
Importante: o array começa da posição 0 e termina na posição n-1, ou seja, se declaramos um array de tamanho 5, não vamos percorrer a posição 5 do array pois ela não existe, vamos até a posição 4 (n-1)
Vou tentar escrever o algoritmo em português, mas abaixo se encontra o algoritmo em Java:
Inteiro  [5] vetor := {16, 7, -9, 4, 13};
Inteiro auxiliar :=0;
Inteiro i := 0;
Inteiro b :=0;

Para (i:=0 até vetor.tamanho-1) faça{
---- Para (b:= i+1 até vetor.tamanho -2) faça {
-------- Se ( vetor [ i ] > vetor [ i+1] ) {
-------- auxiliar := vetor [ i ];
-------- vetor [ i ] := vetor [ i+1 ];
-------- vetor [ i+1] := auxiliar;
-------- }
----}
}

Exemplo no Java:

Espero ter ajudado...


Is there any way to get command line parameters in Google Chrome extension?

Question: I need to launch Chrome from command line with custom parameter, which
contains path to some js-file. Further this path will be used in
extension.
I browsed carefully all related documentation and clicked all nodes in
Chrome debugger, but found nothing which can resemble on command line
parameters. Is it possible anyway to get these parameters or it's need
to write more complex npapi-extension? (theoretically in such npapi-
extension we able to get self process through win-api, command line of
self process and so on).
Comment: The data displayed on `chrome://version` is defined in `chrome://version/strings.js` but extensions aren't allowed to access it.
Comment: FYI, the NPAPI approach you described won't work, because the plugin would be running in a completely different process (launched by Chrome with command line parameters it decides on).
Comment: You're wrong and right simultaneously. I tried such scheme already, and it's possible get info about separate current process with extension. It means that also there is way to get info about parent process and about parent process command line as result.
Comment: Also I found special page chrome://version. This page contains exact info what I need - command line with all switches. I tried debug this page, but found nothing useful for me.
Answer: Hack alert: this post suggests passing a fake URL to open that has all the command-line parameters as query string parameters, e.g.,
chrome.exe http://fakeurl.com/?param1=val1&param2=val2

Comment: +1 Thanks! I refined this approach a bit, pls. check out my answer. I would be happy to hear your opinion.
Comment: Works...might also want to prefix with `./` like `./chrome.exe MY_URL`
Answer: Perhaps pass the path to your extension in a custom user agent string set via the command line. For example:
chrome.exe --user-agent='Chrome 43. My path is:/path/to/file'

Then, in your extension:
var path = navigator.userAgent.split(":");
console.log(path[1])

Answer: Basically I use the technique given in @dfrankow's answer, but I open 127.0.0.1:0 instead of a fake URL. This approach has two advantages:

The name resolution attempt is skipped. OK, if I've chosen the fake URL carefully to avoid opening an existing URL, the name resolution would fail for sure. But there is no need for it, so why not just skip this step?
No server listens on TCP port 0. Using simply 127.0.0.1 is not enough, since it is possible that a web server runs on the client machine, and I don't want the extension to connect to it accidentally. So I have to specify a port number, but which one? Port 0 is the perfect choice: according to RFC 1700, this port number is "reserved", that is, servers are not allowed to use it.

Example command line to pass arguments abc and xyz to your extension:
chrome "http://127.0.0.1:0/?abc=42&xyz=hello"

You can read these arguments in background.js this way:
chrome.windows.onCreated.addListener(function (window) {
    chrome.tabs.query({}, function (tabs) {
        var args = { abc: null, xyz: null }, argName, regExp, match;
        for (argName in args) {
            regExp = new RegExp(argName + "=([^\&]+)")
            match = regExp.exec(tabs[0].url);
            if (!match) return;
            args[argName] = match[1];
        }
        console.log(JSON.stringify(args));
    });
});

Console output (in the console of the background page of the extension):
{"abc":"42","xyz":"hello"}

Answer: You could try:
var versionPage = "chrome://version/strings.js";
$.post(versionPage, function(data){
    data = data.replace("var templateData = ", "");
    data = data.slice(0, -1);
    var jsonOb = $.parseJSON(data);
    alert(jsonOb.command_line);
});

This assumes you are using jQuery in your loading sequence, you could always substitute with any other AJAX method
Comment: This method only works if you have the version page open, to fix this I would wrap the $.post with:

    `chrome.tabs.create({url: versionPage, active: false}, function(){
    });`
Comment: Perhaps once the post is complete you can then close the tab :)
Comment: this technique used to work, but not anymore on chrome 47. I am now using the --user-agent technique with great success.
Answer: Further to the answers above about using the URL to pass parameters in, note that only Extensions, not Apps, can do this. I've published a Chrome Extension that just intercepts the URL and makes it available to another App.
https://chrome.google.com/webstore/detail/gafgnggdglmjplpklcfhcgfaeehecepg/
The source code is available at:
https://github.com/appazur/kiosk-launcher
for Wi-Fi Public Display Screens
Comment: Both links are dead
Comment: sorry, yes, I changed to using group policy to get parameters to my app, so unpublished that.


Calculating Confidence Intervals For Data Constrained Between 0 and 1 R

Question: I have what I feel is a relatively simple question, but it seems to have no easily-accessible answer. I'm trying to find how to calculate the 95% confidence interval for data that is continuous, but constrained between 0 and 1. Full disclosure - my data are proportions and many of the values are 0s or 1s. This means I can't simply use quantiles, because the 2.5% quantile is always 0 and the 97.5% quantile is always 1.
I realize many functions in R calculate 95% CIs for proportions, but these functions all seem to rely on data relating to the number of successes. My data do not include "successes".
In my study, I compared the relative abundance of one species to another species in a given plot of land. I did this at multiple locations. So each row of my data frame (shown below) corresponds to a location at which I did this assessment. Column 1 is the proportion of species 1, and column 2 is the proportion of species 2 - these values sum to 1 for each row.
<code>  prop.species.1        prop.species.2
1      1.0000000        0.0000000
2      1.0000000        0.0000000
3      1.0000000        0.0000000
4      0.0000000        1.0000000
5      0.6363636        0.3636364
6      1.0000000        0.0000000
7      1.0000000        0.0000000
8      1.0000000        0.0000000
9      0.5555556        0.4444444
10     1.0000000        0.0000000
..           ...              ...
</code>
The data frame is 1000 rows long. Does anyone know how I can calculate the 95% CIs for each column?
Comment: I'm voting to close.  This is a statistics question and isn't specific to programming.
Comment: Do you know the actual counts at each location?  Or is only the proportion available?
Comment: You are trying to calculate the confidence interval of what statistic?  The mean?
Answer: Determining confidence intervals by the bootstrap methods percentile and bca will respect the hard endpoints in the data.
Based on your sample data, calculating the mean proportion for each species is probably not very meaningful, since the data are very skewed.  The following code in R calculates the confidence interval for the median of each of the two species using the percentile method.
It's not clear to me that summarizing the data in this way makes a lot of sense, but it depends on your purposes.  If some species were 100% of observation in one location, and 0% in another two locations, is it helpful to take the median or the mean of these?  Would it be better to count up all the observations in all locations and divide by the grand total?
<code>Data = read.table(header=TRUE, text =
"Obs   prop.species.1    prop.species.2
1      1.0000000        0.0000000
2      1.0000000        0.0000000
3      1.0000000        0.0000000
4      0.0000000        1.0000000
5      0.6363636        0.3636364
6      1.0000000        0.0000000
7      1.0000000        0.0000000
8      1.0000000        0.0000000
9      0.5555556        0.4444444
10     1.0000000        0.0000000
")

hist(Data$prop.species.1)
hist(Data$prop.species.2)

summary(Data$prop.species.1)
summary(Data$prop.species.2)

library(boot)

Mboot1 = boot(Data$prop.species.1,
             function(x,i) median(x[i]),
             R=10000)

Mboot2 = boot(Data$prop.species.2,
             function(x,i) median(x[i]),
             R=10000)

boot.ci(Mboot1,
        conf = 0.95,
        type = c("perc"))

   ### median = 1

   ### Intervals :
   ### Level     Percentile
   ### 95%   ( 0.6364,  1.0000 )

boot.ci(Mboot2,
        conf = 0.95,
        type = c("perc"))

   ### median = 0

   ### Intervals :
   ### Level     Percentile
   ### 95%   ( 0.0000,  0.3636 )
</code>
Answer: I don't think you can calculate a confidence interval using the data shown in your data frame, however you probably can calculate a CI using data not shown.
IF I understand you correctly, each row in your data frame corresponds to a single site where you took several measurements.   Presumably you had to look at a number of subjects to calculate a proportion of one species over the other.
If my assumption is correct, you can calculate the confidence interval, but you will need the record of how many measurements you took at each site (N), and how many were species A vs. species B.  Using these data points you can calculate the CI.
Have a look at this tutorial on the problem, it goes through the problem step by step, with accompanying R commands:
http://www.r-tutor.com/elementary-statistics/interval-estimation/interval-estimate-population-proportion


How do I re-create a built-in view?

Question: I duplicated a view before making changes, but it didn't save and I'd changed most of the view settings before I realised I was working on the original.
How can I recreate the standard taxonomy view?
I am using Drupal 9, if that makes a difference.
Answer:
Export your current config using drush cex -y
Copy/paste the /web/core/modules/taxonomy/config/optional/views.view.taxonomy_term.yml into your config directory (usually /config)
Import the config using drush cim -y
Comment: Absolutely wonderful, thank you!

How do I re-create a built-in view?


Por que o "If" não consegue verificar igualdade entre CType(double, int32) com int32?

Question: Eu tenho uma função que me retorna um Double e preciso verificar se o resultado é igual a 5000. Eu estou usando If CType(resultadoFunção as double, Int32) = 5000 Then, mas embora ele mostre 5000, ele não retorna True. Por que?
 Private Async Sub Teste1()
    'Necessário Engucv
    'Imports Emgu.CV

    'vid = caminho de algum video
    Capiture = New VideoCapture(vid)

    While True
        Dim m As New Mat
        Capiture.Read(m)
        PictureBox1.Image = m.Bitmap
        Label1.Text = CType(Capiture.GetCaptureProperty(CvEnum.CapProp.PosMsec), Int32).ToString
        Await Task.Delay(42)

        If CType(Capiture.GetCaptureProperty(CvEnum.CapProp.PosMsec), Int32) = 5000 Then
            'Faz algo
        End If
    End While
End Sub

Answer: Isto ocorre porque o tipo Double não tem exatidão e para ser igual precisa ser exatamente igual, uma diferença mínima não é aceitável, já é diferente. Você pode ver mais detalhes em Qual a forma correta de usar os tipos float, double e decimal?. No momento que faz essa conversão provavelmente está gerando um número como 4999.99999999999998 e aí a parte inteira é 4999, portanto diferente de 5000. O uso de um Round() pode resolver o problema neste caso, mas cuidado com outros.


highlight invalid input, component.valid always valid but binding works

Question: I just learnt about the component.valid EL expression and I'm having some trouble with it. My component is always valid when I use component.valid instead of binding the component and using the bound name :
This works:
    <h:inputText required="true" binding="#{textIn}" value="#{testBean.number}" style="#{textIn.valid ? 'border:1px solid green;' : 'border:1px solid red;'}">
        <f:validateDoubleRange maximum="3"></f:validateDoubleRange>
    </h:inputText>

Without the binding and using component.valid the component is always valid :
    <h:inputText required="true" value="#{testBean.number}" style="#{component.valid ? 'border:1px solid green;' : 'border:1px solid red;'}">
        <f:validateDoubleRange maximum="3"></f:validateDoubleRange>
    </h:inputText>

What's wrong with this ? It's really a deal breaker for me because I have to type one more attribute and I can only type that much..
Comment: Try updating/rendering the entire form after submit.
Comment: That trick is taken over from [my blog](http://balusc.omnifaces.org/2011/09/communication-in-jsf-20.html). JSF utility library OmniFaces offers a [single tag](http://showcase.omnifaces.org/components/highlight) which transparently does all the necessary magic.
Comment: @KishorP it works well now, thanks. I've no idea why it worked at some point with the binding attribute without any update, but it doesn't seem to work today if I don't update so I'll assume there was probably a mistake in my code(maybe I did use update without seeing it but yeah I doubt it).
Comment: @BalusC I saw in your blog you wrote in your css #{resource..} to locate a resource. When reading this I was exited and tried #{aBean.color} in my css. Unfortunately it didn't work. Is it reserved to implicit component ? As for the omnifaces tag, I will be blunt but it doesn't really save much time. I'll use omnifaces in the future but for now I think it abstract things I need to know to understand the jsf framework well.
Comment: Presence of EL in CSS is checked only once per CSS file application wide. So if you were editing an existing CSS file without EL without restarting the application, you need to restart the application. Learning/hobbying/fiddling/practicing around with JSF is a very good reason to not use OmniFaces yet :)
Comment: @BalusC Thank you. I was wondering when I was driving the other day, don't answer if it's inappropriate but how do you think? with images ? you see words, in java ?
Comment: @BalusC That doesn't answer much :D. Anyway I'll leave it at that. I think in sound that's why I had an hard time understanding.
Comment: :) At least definitely not with sound. I also can't imagine how the hearing could think with that, I find sound far too disturbing. When I think, I mostly just ... think logically.
Comment: @Ced : Ok ill add that as an answer. You are asking BalusC how he thinks? He doesn't need to, ideas just flow out of his brains like water :) he has inspired lots of people including me.
Answer: Update or render the entire h:form after submission.
This will re evaluate the el expression bound to style attribute.


is there a way to free up space after Visual Studio 2010 SP1 is installed

Question: I have just installed VS2010 SP1 and it takes a huge amount of space. What I would like to know is if it's possible to remove the SP1 uninstall files, and thus free up some space.
For example after installing Windows 7 SP1, there is a command (dism /online /cleanup-image /spsuperseded) to clean up all the space, if you don't want to uninstall SP1 afterwards. Is there a similar command for VS2010 SP1?
Answer: One really nice tip to get free space is removing  Hiberfil.sys. This file is only used to allow you to hibernate your machine. But, i think as a developer you can remove thius file. Since that you dont use to much this feature.
http://helpdeskgeek.com/windows-7/windows-7-delete-hibernation-file-hiberfil-sys/
Comment: it's indeed a space hog but it has absolutely nothing to do with visual studio
Comment: Aggree, i just provide another fair way to get a lot of space in your windows 7 machine.


Jackson deserilisation for spring-response-body

Question: The Json-Response-Body for my example-ajax call will not deserilise as expected. For testing purposes I want to return an empty JSON-Array.
JavaScript: JSON-Ajax-Call

saveFiles: function (files) {
            $.ajax({
                url: "SaveFile.do",
                type: "post",
                data: JSON.stringify(files),
                contentType: "application/json",
                success: function (saved) {
                    showSaveResult(saved);
                }
            });
        },

Java-Controller:

@RequestMapping(value="/SaveFile.do", method = RequestMethod.POST)
    @ResponseBody public ArrayNode createSaveResult (@RequestBody Data[] entities, BindingResult result, Locale locale){
        ArrayNode jsonReturn = new ArrayNode(jsonNodeFactory);
        return jsonReturn;
}

Request:

[{key:value1},{key:value2}]

Response:

{"array":true,"elements":[],"containerNode":true,"valueAsText":null,"numberType":null,"fields":[],"fieldNames":[],
"null":false,"textValue":null,"booleanValue":false,"long":false,"valueNode":false,"missingNode":false,
"object":false,"pojo":false,"number":false,"integralNumber":false,"floatingPointNumber":false,"int":false,
"double":false,"bigDecimal":false,"bigInteger":false,"textual":false,"boolean":false,"binary":false,
"numberValue":null,"intValue":0,"longValue":0,"bigIntegerValue":0,"doubleValue":0.0,"decimalValue":0,
"binaryValue":null,"valueAsInt":0,"valueAsLong":0,"valueAsDouble":0.0,"valueAsBoolean":false}

Instead the response delivers the complete ArrayNode Object. How can I solve this problem?
Answer: An ArrayNode is a Jackson representation of a single element of an array. If you simply return it, you're going to get the serialized version of ArrayNode, not an empty array element which is what you want.
You can either return a class that represents your expected data set:
private static class SaveResult {
    String key;
    String value;
}

@ResponseBody public SaveResult[] createSaveResult (@RequestBody Data[] entities, BindingResult result, Locale locale){
    return new SaveResult[0];
}

You could also build up the Json by hand and return the string as shown here (How to create this json string using Jackson?).
I lean heavily towards the first approach as I feel it is much more obvious with a quick read of the code.


F-Statistic: Levene's Test vs. Two-Sample

Question: I'm trying to get my head around the calculation of the critical F-Statistic for testing the equality of variances using two different tests.
I have 2 groups (n=12) and (m=11). Trying to do a two tailed test with alpha=5%.

Two-Sample F-Test (larger variance over smaller variance): F( 2.5% , 11 , 10 ) = 3.66
Levene's Test: F( 2.5% , 1, 21 ) = 5.83

The actual F-Statistic I come up with between the two tests is pretty similar. Why is the critical F-Stat for Levene's test so much larger?
Am I calculating the critical values for the tests correctly?
Also there is Hartley's F-Max test, but I think I need a different F-Stat table for that.
Answer:
The actual F-Statistic I come up with between the two tests is pretty similar.

I don't know that this is generally the case. If the population variances are quite different, they should both tend to be large together, but they don't respond to things in quite the same way,

Why is the critical F-Stat for Levene's test so much larger?

Simply because one of the two degrees of freedom is very small. If either df is small, the tail quantiles are larger.

Am I calculating the critical values for the tests correctly?

Well, the degrees of freedom are right -- if you want an approximate 5% test in both cases, then no.
The Levene test only uses the upper tail (that is, it doesn't matter which group has the large variance, it's always an upper tail test). The appropriate upper tail critical value for the Levene test is actually 4.3248 (but it's only approximately a 5% test)
[The variance ratio test is also only approximate, because the "taking the maximum ratio" part in effect treats the degrees of freedom as interchangeable. It's possible to avoid that effect, though.]
Of the two, the Levene test is much more robust to departures from normality.
However, if you're doing this in order to check the assumptions of some other procedure, such as an ANOVA or t-test, the advice of quite a few papers is to avoid such formal testing (particularly if you'll choose a different test when you reject than if you don't).


Superscope DHCP leases and configuration set up

Question: Hello I wanted to see if someone could help with a network problem I am having. Right now we have a super-scope and scopes of 192.168.50.1 and 192.168.51.1, as of now both are activated but only 192.168.50.1 is handing our leases, 192.168.51 wont. here is a summary of our network
Gateway: watchguard firebox x750e for our router/gateway at 192.168.50.1 I set up as a secondary IP address 192.168.51.1
Server: Server 2008 r2 standard, running our DNS @ 192.168.50.242 and 220.127.116.11 as a secondary, AD, and DHCP. On that NIC card i have 192.168.50.242 as the IP address and 192.168.51.242 as a secondary. 192.168.50.1 as the default gateway and 192.168.51.1 as a secondary.
Im am not very knowledgeable at this but as far as i have researched after adding a super scope and activating scopes, they should automatically start handing out addresses and I cant figure out why only one does. any help at all would be appreciated.
Comment: Have you created any VLANs?  What was the reasoning behind using superscopes and not scopes when the DHCP role was configured?
Comment: Why are you using a superscope?
Comment: No VLANs, we have the scopes inside of the superscope and I did not originally set this up. the previous IT guy did but he told me it would work fine when activating the second scope and that didn't happen. Not sure if he blows smoke sometimes.
Answer: There is probably no reason to keep it like this, it's unnecessarily complicated.  192.168.50.0/24 and 192.168.51.0/24 can be combined into one subnet, 192.168.50.0/23, so you could reconfigure that on the DHCP server and get rid of the Superscope.  Then configure it as 192.168.50.0/23 on the router/vlan as well.  The only issue is going to be subnet mask and gateway on statically configured devices, so you might have numerous touch points.  DHCP clients will pick up the new subnet mask next time they renew.
It's probably the case that you ran out of IPs on 192.168.50.0/24 at some point and another was added as a "secondary" as a quick and dirty way to get more address space on that wire/vlan.  Superscope is a way to join those two /24's on the DHCP side telling the DHCP server that both of these scopes are on the same wire and thus recognize that any clients or relay agents coming from either subnet should be treated as being on the same wire/vlan.  This is more commonly used when the subnets are non-continguous, e.g., if it was 192.168.50.0/24 originally then you added 192.168.66.0/24 as a secondary network to get more space.
The behavior you see is thus normal.  You won't see the DHCP server start handing out addresses from the newly-enabled scope (under the Superscope) until all addresses in the first scope (192.168.50.1) are all used up.  And existing DHCP clients will continue to directly renew the IP they already have.
Comment: Sounds great thanks for the help. One more question, on my DHCP server's NIC card should I have 50 and 51 IP addresses, gateway and DNS or will it just keep it all on x.x.50.x?
Comment: If you convert over to 192.168.50.0/23, then your only gateway is 192.168.50.1 and you only need one address on the NIC and it can be the 50.x or 51.x but you don't need both anymore.
Answer: Are you sure you are really having a problem?
Superscopes are useful when you join two physical subnets, each with its own scope and DHCP server. They solve the following problem: client disconnects from scope A, then reconnects and asks for renewal of lease, but server B is quicker and, ignoring the existence of a superscope, declines the request of lease renewal; the client will then have to re-issue a DHCP discovery signal, and may be offered a lease by server B within scope B. Thus the client is now cut-off from its original network, and inserted into a subnet for which it may not be configured. This may happen every time every client disconnects.
By configuring a superscope, you are basically allowing server B, now assumed to be aware of its participation in a wider scope than its own subnet, to renew the lease of the client in subnet A, basically keeping all configurations intact.
In your network, you have a single DHCP server, and, if I understand right, a single physical network. Thus there is no difference between a superscope and a single scope with netmask 255.255.254.0 instead of the usual 255.255.255.0. Since there is only one DHCP, it will start dishing out addresses in the 192.168.51.0/24 scope only after it has exhausted addresses in the 192.168.50.0/24 scope. Depending on the size of your network, you may ascertain whether you are there yet or not. Judging from the OP, I would guess not.
Comment: @syneticon-dj  You are wrong, syneticon-dj. Read after Table 4.3, you will see that Microsoft Tech makes **exactly** my point above. Can I have my two points back, now?
Comment: I am not wrong, you have a misconception about superscopes which you've expressed in your answer above. But you surely can have the 2 points back if you clarify that superscopes are only useful for implementing multiple logical IP subnets in a single [broadcast domain](http://en.wikipedia.org/wiki/Broadcast_domain). Note that a vote, once casted, cannot be changed unless the answer has been edited since.
Comment: This is not what (MS-DHCP) superscopes are about. [***This***](http://technet.microsoft.com/en-us/library/cc958938.aspx) is.
Comment: BTW: there *is* a difference between a superscope including two IP /24 networks and a single /23 - for the first case your default router would need to have two IP addresses (one for each subnet) and need to route traffic between the logical subnets, despite the hosts being technically able to communicate with each other directly. It is a pain in the bum to set up, manage and debug too, so I would not recommend using logical netting (and thus, using superscopes, too) to anyone now that VLANs are implemented all over.
Comment: @syneticon-dj Not suggesting that a superscope with two subnets and a /23 subnet are the same: I am saying that in the OP's network there is no client initially with an IP address in the second scope, so that, so long as the first subnet has enough addresses, no address will be given in the second scope. In a **real** superscope, instead, one of the DHCP servers is actively dishing out IP addresses in the second scope even though the address space of either scope is far from exhausted. Which is the reason why the OP did not see any address in the second scope, which is what puzzled him.
Comment: So what you are saying is that my server wont hand out addresses from the second scope until all of the addresses in the first scope are depleted? @MariusMatutiae I gave you back your +1 :) seems as though both statements are correct. Also should I have a 192.168.51.x ipaddress set up for DNS as well? or just leave is 192.168.50.242?
Comment: @Vdub Thanks, ;-). The part I do not understand is why you need a superscope in the first place. You only have one DHCP, and you seem to have only one physical net. Are you close to depleting the subnet address space? If not, I embrace syneticon-dj's comment that they are a pain, and would advise you to dispense with it altogether.  That would solve all of your doubts, and make your like a heck of a lot easier.
Comment: I'm not sure the previous IT guy set it up, when I got here there were the 2 scopes under the super scope but only one was activated. A couple times we had used 96% OF OUR 254 addresses so I activated the other one. I am really not sure what the difference is between having 2 scopes in a superscope or just having 2 scopes lol doesn't seem to be to much of a difference. I would use VLANs but i am very unfamiliar with them so obviously a n00b. If the second scope will hand out addresses after the first is depleted that's all I need anyway so that's good. thanks for the help!
Comment: Okay, so this answer is badly worded in regards to what Superscopes do, but suffice it to say the jist of it is correct.  Superscopes tell the DHCP server to recognize BOTH gateways as relay agents for BOTH scopes (and any direct clients).  They are treated as matching the Superscope, i.e., a relayed DHCP request from 192.168.50.1 is equivalent (for matching) as 192.168.51.1 and thus a request from either of these will match the Superscope.  Once that decision is made, the behavior now will be to use IPs from the first scope until all used up, then start issuing from the second scope.
Answer: I think the difference here is not having to re-ip all of the network devices. The router can route all packets over a VDOM interface (I believe) between the two networks if any communication across the scopes is required.
The physical router port becomes a point of failure but if all you need is more addresses and the network wasn't previously designed to be extendable maybe a super scope isn't a horrible option while you plan for a total re-IP.
Additionally couldn't you use the super scope to slowly migrate into a new IP scheme? I think so.


User permission to edit only nodes with taxonomy term

Question: I want to let my customers only edit nodes that have a specific taxonomy term.
For example i have user TimCook from company Apple. He got the role "customer" and i want to give him the right to edit nodes only with the taxonomy term "apple" of the vocabulary "company".
I didn't find any module for this. Maybe there is one, or someone has a hint where i should start to make an own module.
Answer: Taxonomy Access Control Lite module should help you.

This node_access module governs access to nodes based on the taxonomy
  terms applied to the nodes. A simple scheme based on taxonomy, roles
  and users controls which content is visible.
Answer: Taxonomy Access Control
You may set permission to allow users in role "apple" have the right to view, update or delete nodes with an "apple" term.
Comment: No i have 1000 taxonomy terms / customers so i would have 1000 roles.


Showing a representation is irreducible by showing that a degenerate subspace has codimension one.

Question: Throughout $\phi$ be a continuous character from a locally compact abelian group $G$ to the circle.
I'm trying to understand this implication. Basically we want to show that a certain representation is irreducible. We know that the representation is of the form $C_c(G)/W$, where $W$ is the subspace of functions $f$ which are degenerate with respect to the norm $\langle\cdot\rangle_\phi$. We have that $\langle f,f\rangle_\phi=\left|\int\overline{\phi(s)}f(s)\ ds\right|^2$, and the authors assert that hence the subspace degenerate with respect to $\langle\cdot\rangle_\phi$ has codimension one, and therefore $C_c(G)/W$ (more precisely its closure) is one-dimensional.
How do we know that the degenerate subspace has codimension one? How does it follow from the calculation of the norm of an arbitrary $f\in C_c(G)$?
Answer: The degenerate subspace is the orthogonal complement of $\mathbb{C}\phi$ w.r.t. the inner product $\int\bar f g ds$. Whence codimension $1$.


FDT's Haxe Viewer Won't Launch My Project

Question: I tired to and set the Launch URI using the browse button, but it doesn't seem to be wired up. Also if I try and set a configured path relative to the project (bin/js/index-debug.html) it reports that "Please select a valid URI file".

Here is a sample of my .HXML file for more detail:
<code>-main ClassCollector
-cp lib/collector
-neko bin/collector/ClassCollector.n
-cmd neko bin/collector/ClassCollector.n src/main/haxe examples/main/haxe/All.hx -class
</code>
Answer:
-cmd neko bin/collector/ClassCollector.n src/main/haxe examples/main/haxe/All.hx -class

When using FDT for Haxe, you currently cannot run commands in the .HXML file. This will also cause other problems such as slow autocompletion and other errors.
This may change in a later version of FDT.


Who can remix a song?

Question: I'm thinking of trying to learn how to remix songs with GarageBand and similar applications. So far I'm a total noob, and I'm just wondering who is allowed remix what songs? Is anyone allowed to remix a popular song and call it their own? Or is it necessary to contact the song's creator to gain permission?
On a similar note, what if the artist is dead? I would assume you would not need to contact anyone, but maybe there are some family members who wouldn't want the songs to be remixed?
Thanks for any help / advice you can give!
Answer: Like user2808054 says, if you're just messing around at home, you can do what you want.
But if you're going to start publicly displaying your music (for money or not) a number of different rules start cropping up, such as copyright, and various other Creative Commons licences.
Arrangements
If you write an arrangement of a piece, you need to give credit to the original "authors", which may include composer and lyricist. As long as you provide proper reference, and your arrangement is "different enough" from the original, that's fine.
Musical Phrases
Some publishers may not allow for remixing of certain current songs (by current I mean the singer/songwriter is still alive and making money from sales). If you are just using a tune/phrase "snippit" from a piece in your composition, usually that's ok as long as it does not make up a significant portion of your overall work. Be careful that if you're using a collection of phrases from different works from the same artist that they get "concerned" about it. This YouTube video ("John Williams is the Man") had initially received some criticism (and almost a lawsuit) from the publishers because the whole song used musical phrases from a collection of songs all from John Williams. The artist eventually came to an agreement with the publishers and added the song and movie titles as super/sub titles in the video.
When in doubt, include a reference to the original work you're using.
Copyright
Depending on what kind of work it is, Copyright may persist long after the author is dead. Even then, the artists family may apply for an extension which would transfer the rights to the artists family. From the Wikipedia entry on "Copyright":

In most of the world, the default length of copyright is the life of
  the author plus either 50 or 70 years. In the United States, the term
  for most existing works is a fixed number of years after the date of
  creation or publication. Under most countries' laws (for example, the
  United States[39] and the United Kingdom[40]), copyrights expire at
  the end of the calendar year in question.

I hope this helps, and have fun!
Answer: It depends on what you're going to do with it.
If it's just for home use and your own enjoyment, then you can do what you want.
If you're going to try to sell it and call it your own (ie, a commercial venture), then there will certainly be an issue about copyright. Working out who owes who what is a hugely complicated area.
If you're remixing a song, using original tracks from the original artist, then you absolutely can't call it your own. It;s theirs - you're just messing with it.
If the artist is dead, this doesn't mean you can just use their stuff. They might not even own the copyright themselves. There are laws about when material comes "out of copyright" but these vary depending on the country you're working in.
Vanilla Ice used Queen & Bowie's "Under Pressure" riff but (he says in interview) it wasn't a sample; they played it afresh, and added one extra note at the start of the riff which meant it was different enough to be able to call it their own.
Early Cliff Richard music has recently come out of copyright. It's alleged that he's still alive.
Others will know much more about it than me, but that's the nub of it.
Comment: [According to Wikipedia](https://en.wikipedia.org/wiki/Ice_ice_baby), despite not being so at first, credits (and money) are now properly given to Bowie and Queen for the "Ice Ice Baby" bass line.

Who can remix a song?


Why iterations of Gibbs sampling for a bivariate Gaussian distribution can be seen as random walk?

Question: In Section 4.4 of the excellent technical report Probabilistic Inference using Markov Chain Monte Carlo Methods, the author tries to analyze the performance of Gibbs and Metropolis algorithm with simulating samples from a bivariate Gaussian distribution. In this example, he claimed:

Notice that in this example both Gibbs sampling and the Metropolis algorithm explore less confined direction by a random walk.

This statement confuses me for a while (It also came to my attention that other books, e.g., Pattern Recognition and Machine Learning, Section 11.3, also adopted the similar perspective to estimate the number of iterations needed to obtain two nearly independent samples). What is the rationale of such statement? To me, suppose we want to sample from
\begin{align*}
\begin{bmatrix}
X_1 \\
X_2
\end{bmatrix} \sim N\left(\begin{bmatrix} 0 \\ 0 \end{bmatrix},
\begin{bmatrix} \sigma_1^2 & \rho\sigma_1\sigma_2 \\ \rho\sigma_1\sigma_2 & \sigma_2^2\end{bmatrix}\right)
\end{align*}
using Gibbs sampling, the conditional distribution for $X_1$ given the current value of $X_2 = x_2$ is $N((\rho\sigma_1/\sigma_2)x_2, (1 - \rho^2)\sigma_1^2)$. Therefore in a single Gibbs pass, a Gaussian random number is generated according to this distribution, which is (in my opinion) very different from a random walk. In particular, the state will not stay at the current value with positive probability.
Does the author actually merely mean this example and the random walk share the "square root" phenomenon?
Answer: At the intuition level, the Gibbs algorithm induces a random walk on both components, eg:
$$X_1'=\rho\sigma_1/\sigma_2X_2+(1 - \rho^2)^{1/2}\sigma_1\epsilon_1=
\rho\sigma_1/\sigma_2\left(\rho\sigma_2/\sigma_1X_1
+(1 - \rho^2)^{1/2}\sigma_2\epsilon_2\right)+(1 - \rho^2)^{1/2}\sigma_1\epsilon_1=\rho^2 X_1 + (1 - \rho^2)^{1/2}\sigma_1[\rho\epsilon_2+\epsilon_1]$$
which is an AR(1). And makes the statement

in a single Gibbs pass, a Gaussian random number is generated
according to this distribution

incorrect.
Comment: Thanks. But is "AR(1)" equivalent to "Random Walk"? It may be intuitively OK to say so if $\rho$ is close to unity, but theoretically not true, correct?
Comment: Radford considers the "random walk" behaviour of all reversible MCMC as detrimental. He thus does not mean the $x_{t+1}=x_t+\epsilon_t$ representation of a random walk, but the feature of meandering back and forth in the excursion, hence wasting time and possibly missing converging fast enough to the target.
Comment: Thanks for the clarification, I can see his point but just wanted to make sure I didn't miss something simple and interesting.


What was this NHL match, possibly in 1999, where the National Anthem was sung by Christina Aguilera?

Question: I'm trying to identify a game on which Christina Aguilera sang the National Anthem, as appears on this video.
I've got 3 leads:

The video title says it was on 1999.
In another version of this video (whose title also says it's a 1999 game), the commentator says the game takes place in Anaheim.
We can see the blurry players' uniforms:

Can you identify this game, or at least identify some more clues that would help?
Answer: Your fact finding of it taking place in Anaheim is correct based on announcers. I think it is safe to assume based on uniform colors that the team on the far side is the Ducks. They featured a light color top home jersey at that time.
Placing an identification on the opposing team is more difficult given video quality. Based on this schedule, it would appear that there were 20 home games that took place in the year 1999 in the 99-00 season. This also could have been in latter half of the 1998-99  season, found here. That season featured 24 home games for the Ducks, with an additional 2 postseason games versus the Detroit Redwings. So a total of 46 NHL games were played there.
Based on the jersey colors, I believe the opposing team is the Philadelphia Flyers. The light strip across the neckline appears in only 2 jerseys that have a dark body and light number, Philadelphia and Tampa Bay. Tampa Bay, however, features a large white block on the bottom portion of the jersey which would be seen clearly even with poor video quality.
They only played @ Anaheim once in the year 1999 across the two seasons, which was this game on November 3, 1999.
Aside from the jersey aspect, the "goalie matchup" comment at the end of your second video link would support this. The Anaheim goalie Dominic Roussel had posted the highest save percentage of his season in October, winning both games in which he appeared. Philadelphia's netminder John Vanbiesbrouck closed out 12th overall for the season and posted a .908 save percentage in the month of October. This would mean that the goaltender matchup would have been considered a meeting between two strong players at that point in the season, supporting this theory.
Therefore I believe this took place a the game between PHI and MDA on November 3, 1999.
Comment: In addition to the 24 home games duck played in the 1998-99 season in 1999, the Ducks also played 2 postseason games in April of 1999 at home
Comment: Edits shall reflect, thank you @alamoot
Comment: Thank you! There's another fact I didn't mention because it's obscure: Aguilera has an ad board behind her, with the letters "...ower ā de". I've tried to locate this ad board on videos circa that time, to no avail. However, Food4Less alongside Ralphs ads and Arrowhead's ad (0:01 and 1:21 on my first link, respectively) are visible in every video from that time (e.g [1](https://www.youtube.com/watch?time_continue=90&v=d_5VAoYFFcI&feature=emb_title), [2](https://www.youtube.com/watch?v=lDZTaCI1wUc&t=557s), [3](https://www.youtube.com/watch?v=YnFcBN2WWkE)).
Comment: @heyjude I did my best to find information about that company but had no luck in my search. Might have been a local company who is no longer is in business? Without increased video quality it really will be hard to determine a lot of other pieces.
Comment: @PaulWitry, the ad board is Powerade's old logo, with the "a" over a hockey puck, like [this one](https://nhl.bamcontent.com/images/photos/289652306/1284x722/cut.jpg).
Comment: @HeyJude would never have found that out, great work!


Python Plotly - Annotated Heatmap - Adding layout

Question: I found two different ways of making a heatmap in Plotly, one in which it annotates the heatmap, the other just uses a colorbar.
Annotation:
dfreverse = df_hml.values.tolist()
dfreverse.reverse()

colorscale = [[0,'#FFFFFF'],[1, '#F1C40F']]

x = [threeYr,twoYr,oneYr,Yr]
y = ['March', 'February', 'January', 'December', 'November', 'October', 'September', 'August', 'July', 'June', 'May', 'April']
z = dfreverse

z_text = np.around(z, decimals=2) # Only show rounded value (full value on hover)

fig = ff.create_annotated_heatmap(z, x=x, y=y,annotation_text=z_text, colorscale=colorscale, hoverinfo='z')

# Make text size smaller
for i in range(len(fig.layout.annotations)):
        fig.layout.annotations[i].font.size = 9

plotly.offline.iplot(fig, filename='annotated_heatmap_numpy')

Colorbar:
dfreverse = df_hml.values.tolist()
dfreverse.reverse()

colorscale = [[0, '#454D59'],[0.5, '#FFFFFF'], [1, '#F1C40F']]

x = [threeYr,twoYr,oneYr,Yr]
y = ['March', 'February', 'January', 'December', 'November', 'October', 'September', 'August', 'July', 'June', 'May', 'April']
z = dfreverse

hovertext = list()
for yi, yy in enumerate(y):
    hovertext.append(list())
    for xi, xx in enumerate(x):
        hovertext[-1].append('Count: {}
{}
{}'.format(z[yi][xi],yy, xx))

data = [plotly.graph_objs.Heatmap(z=z,
                                  colorscale=colorscale,
                                  x=x,
                                  y=y,
                                  hoverinfo='text',
                                  text=hovertext)]

layout = go.Layout(
    autosize=False,
    font=Font(
        family="Gill Sans MT",
        size = 11
    ),
    width=700,
    height=450,
    margin=go.Margin(
        l=150,
        r=160,
        b=50,
        t=100,
        pad=3
    ),
        xaxis=dict(
        title='',
        showgrid=False,
        titlefont=dict(
           # family='Gill sans, monospace',
            size=12,
            #color='#7f7f7f'
        ),
        showticklabels=True,
        tickangle=25,
        tickfont=dict(
            family="Gill Sans MT",
            size=12,
            color='black'
        ),
    ),
    yaxis=dict(
        title='',
        showgrid=False,
        titlefont=dict(
            #family='Gill sans',
            #size=12,
            #color='#7f7f7f'
        ),
        showticklabels=True,
        tickangle=25,
        tickfont=dict(
            family="Gill Sans MT",
            size=12,
            color='black'
        ),
)
)

fig = plotly.graph_objs.Figure(data=data, layout=layout)
plotly.offline.iplot(fig,config={"displayModeBar": False},show_link=False,filename='pandas-heatmap')

The actual question
I want to produce the heatmap with the annotation (1st chart) but be able to change the font and font size of the x and y axis through I presume a layout. However the Annotation Heatmap code doesnt seem to like me putting a layout in it. Is this possible?
Answer: The ff.create_annotated_heatmap doesn't directly accept a layout as a keyword argument, but you can update the layout of the fig it produces:
fig = ff.create_annotated_heatmap(z, x=x, y=y,annotation_text=z_text, colorscale=colorscale, hoverinfo='z')

fig.layout.update(
  go.Layout(
    autosize=False,
    font=Font(
      family="Gill Sans MT",
      size = 11
    )
  )
)

plotly.offline.iplot(fig, filename='annotated_heatmap_numpy')

This way you don't have to pass each of the values separately, especially in the case you have an existing layout that you want to re-use.
Comment: @Sakari_Cajanus, nice answer. But I guess instead of `Font(family=)`, it will be `dict(family=)`.
Comment: Does anyone know how to annotate the heatmap using the go.Heatmap() directly rather than the ff?
Answer: I found this answer, which tells how to to alter layout of x axis:
I can't test it, but reading https://plot.ly/python/reference/#layout-yaxis-titlefont suggests this code:
fig = ff.create_annotated_heatmap(z, x=x, y=y,annotation_text=z_text, colorscale=colorscale, hoverinfo='z')

# Altering x axis
fig['layout']['xaxis']['titlefont']['family'] = "Arial"
fig['layout']['xaxis']['titlefont']['size'] = 14

# (same procedure for 'yaxis')...

plotly.offline.iplot(fig, filename='annotated_heatmap_numpy')

Comment: Thank you! I will try it out now :)
Comment: Hmmm.. it is not causing any errors, but then it isnt doing anything either. Ha! :).... not sure if it is my fault, the link you gave did refer to 3.* when I am on 2.7?
Comment: Sorry, works perfectly! Thank you... turns out my x and y axis are called 'tickfont'... I changed that and it worked :)  ty again!
Answer: I've played with the animation methods, therefore, I had to annotate the heatmap using the go.Heatmap directly.
Here is my solution:
from functools import reduce
from itertools import product
z = [[1, 2, 5],
     [2, 5, 1],
     [5, 1, 2]]

def get_att(Mx):
    att=[]
    a, b = len(Mx), len(Mx[0])
    flat_z = reduce(lambda x,y: x+y, Mx) #Mx.flat if you deal with numpy
    coords = product(range(a), range(b))
    for pos, elem in zip(coords, flat_z):
        att.append({'font': {'color': '#FFFFFF'},
                    'showarrow': False,
                    'text': str(elem),
                    'x': pos[1],
                    'y': pos[0]})
    return att

fig = go.Figure(data=[go.Heatmap(z=z)])
fig.update_layout(annotations=get_att(z))
fig.show()


How to create wrapping menu tabs with CSS in Omega

Question: I'm using the menu api (MENU_LOCAL_TASK) to create tabs in Drupal 7. In Omega, I can't figure out how to wrap the tabs in css so that they are responsive. I'm new to Omega. This was easily accomplished in other themes.
Comment: What do you mean 'wrap the tabs in CSS'?  Do you mean that you need to add classes to each tab?  On another note, you might want to work on your [acceptance rate](http://drupal.stackexchange.com/faq#howtoask) to get answers more quickly.
Answer: It appears that the default system.menus.css in Drupal sets the white-space property to:

white-space: nowrap;

The default value for white-space is normal.  So, if you set the white-space property on your menu's UL to white-space:normal they will wrap when your screen size gets smaller.
I placed the following in my global.css.

ul.primary {white-space: normal; }


partial derivatives of order $n$

Question: Be $f : \Bbb R^m \rightarrow R$  a function with continuous partial derivatives up to order $n$. How many derivatives of order $n$ does the function have?
I proved it for $n=1$
and I got that the number of derivatives was $m$
then I proved it for $n=2$
(second-order partial derivatives)
and I got $m^2$
but I'm stuck, because for proving by induction, I need a hypothesis right?
to get $m^n$?
Comment: @Arthur It's not clear to me whether $\frac{\partial ^2 f}{\partial x \partial y}$ and $\frac{\partial ^2 f}{\partial y \partial x}$ should be counted as being "distinct derivatives". Does the fact that they are equal mean that they are "the same derivative"? I think both answers can be argued for here.
Comment: Let's say $m=n=2$. I get three partial second derivatives, not four.
Comment: @BenGrossmann: You're forgetting *Schwarz' theorem*.
Comment: @Bernard: I don't think he's forgetting it. He did say "does the fact that they are equal...". I think he's unclear if OP's question regards them as distinct derivatives or not.
Answer: Supposing  the order of differentiation is not taken into account, this is a purely combinatorial problem: it is the number of $m$ objects taken $n$ at a time with repetitions:
$$\Gamma_m^n=\binom{m+n-1}n.$$
Answer: For a general function $f$ (that has $n$-th order partial derivatives), you may have up to $m^n$ many different $n$-th order partial derivatives. The logic that you used to make this claim is that you can take the derivative with respect to any variable. Then do it again. And again, until you get to the $n$th derivative. This is all correct in general.
However, if these $n$-th order partial derivatives are continuous, then many of these derivatives are in fact the same. By Clairaut's Theorem, $f_{xy}=f_{yx}$ for the continuous function $f(x,y)$. Similarly, $f_{xxxyy}=f_{xyxyx}$, etc.
So for the question that you asked, you have to handle this idea of repetition. As Bernard mentioned, you are effectively asking how many ways are there to choose $n$ objects out of the $m$ choices, where repetition is allowed. This is indeed given by the formula $$\binom{n+m-1}{n}.$$
Comment: Because all the partial derivatives are continuous we don't need to explicitly specify $f$ is continuous. So the repetitions must be taken into account.
Comment: @Peter what do you mean?
Comment: @DanielaMichel, Check https://en.m.wikipedia.org/wiki/Symmetry_of_second_derivatives in the section Theorem of Schwarz. For the theorem to apply at a point you need $f$ To be defined in a neighborhood of the point and the function to have continuous second partial derivatives at the point. Since the question states that all the partial deriviatives are continuous, the theorem applies irrespective of whether $f$ itself is continuous. This means you need to take account of the repetitions of many of the partial derivatives and only count them once, even if $f$ is not explicitly continuous.
Comment: @Peter thanks, I edited it to actually take the hypothesis in the question as the reason for citing Clauraut's Theorem.
Comment: @Peter As said in the comments to the question post, the fact that the derivatives give the _same result_ doesn't necessarily mean they are the _same derivative_. The question is ambiguous in this regard.
Comment: @Arthur, if a derivative is a function it does, because a function can be defined by its values. In the same way $\frac{1}{2}$ and $\frac{2}{4}$ are the same number, though they are different expressions. If a derivative is not a function, how would you define continuity?

partial derivatives of order $n$


How to determine the convergence behavior of the sequence $x_{n}=\sqrt{n^{2}+11n+21}-\sqrt{n^{2}+6}$?

Question: How to determine the convergence behavior of the sequence $x_{n}=\sqrt{n^{2}+11n+21}-\sqrt{n^{2}+6}$ and its limit?
My effort: I don't know where to begin.
Answer: Hint: multiply and divide $x_n$ by $\sqrt{n^2+11n+21}+\sqrt{n^2+6}$
$\sqrt{n^2+11n+21}-\sqrt{n^2+6}=
(\sqrt{n^2+11n+21}-\sqrt{n^2+6})({\sqrt{n^2+11n+21}+\sqrt{n^2+6}\over {\sqrt{n^2+11n+21}+\sqrt{n^2+6}}}$
$={{11n+15}\over{\sqrt{n^2+11n+21}+\sqrt{n^2+6}}}$. So the limit is $11/2$.
Answer: Hint: Write $\sqrt{n^2+an+b}=n\sqrt{1+\frac an+\frac b{n^2}}$ and use Taylor expansion $\sqrt{1+x}=1+\frac12 x+O\left(x^2\right)$ as $x\to 0$.
Answer: As G. Sassatelli and Zack Ni answered, Taylor series are very useful not only to get the limit but also how it is approached.
Using, for small $y$, $$\sqrt{1+y}=1+\frac{y}{2}-\frac{y^2}{8}+O\left(y^3\right)$$ then $$\sqrt{n^2+a n +b}=n \sqrt{1+\frac a n+\frac b {n^2}}=n\left(1+\frac{a}{2
   n}+\frac{4b-{a^2}}{8n^2}+O\left(\frac{1}{n^3}\right)\right)$$ $$\sqrt{n^2+a n +b}=n+\frac{a}{2}+\frac{4b-{a^2}}{8n}+O\left(\frac{1}{n^2}\right)$$ So, using your numbers $$x_n=\frac{11}{2}-\frac{61}{8 n}+O\left(\frac{1}{n^2}\right)$$ For illustration purposes $$x_{10}=\sqrt{231}-\sqrt{106}\approx 4.90305$$ while the approximation gives $\frac{379}{80}\approx 4.73750$.


Cannot connect live mysql database in local server, hosted in google cloud hosting

Question: I am unable to connect the live mysql database in local server, hosted in cloud hosting. I am not getting a place to set the host url in Remote MySql as I am not having cPanel. Please give suggestion to set the host url, such that I can set the db settings properly in local and access the live database. Currently my project is not running due to improper db setting.
Answer: If the database is hosted locally on the server , you do not need to enter any URL for it. Just use localhost as the DB host and it should work correctly.
Answer: Live MYSQL database can only be connected if you have proper rights from the CPanel. You must have a static ip on local/Remote machine to connect to the Remote mysql. This permission Can be configured only if you have access to CPanel. Remote database Authenticates the local Machine using IP address of the machine if you want to connect from Local machine you must buy a static IP address and then in CPanel
 databases >> Remote MYSQL >> enter image description here
Enter your IP address you will have instant access to MYSQL remote database Until your IP address isn't changed. Now connect by giving IP address of your server as HOST and then the database name with Password you are successfully connected.


High disk I/O when cache is used?

Question: A few days ago I noticed a disk I/O wait and disk activity drop (which was great). Then I also notice that my cache was full(*) and fragmented. Then I flushed cache. After that, disk latency and disk activity jumped to the previous level (which was bad).
IOtop shows that [jbd2/sda2-8] and [flush-8:00] are always on top of disk usage. This is a Dell R210, hardware RAID 1 (H200) with a lot of free memory (16 GB in total, of which about 8 GB are buffer/cache).
(*) The cache is APC opcode cache for PHP, which reduces disk access for PHP script execution. Cache was full and fragmented because it included files from development instance. When I noticed that, I filtered them out.
The question is: why disk I/O increases when theorically it should decrease? Below are some graphs from munin. Cache was full from Feb 6 to 8.

Change after I commented out apc.mmap_file_mask as told by @cyberx86

And after a few days https://serverfault.com/a/362152/88934
Comment: That graph doesn't show an increase in IO.
Comment: @psusi There are/were multiple problems that I can only resume, not explain: 1/ APC cache miss (but OS cache hit for those PHP files, so very little disk I/O, less wait time but more avg I/O time, which mostly MySQL InnoDB transaction commit) 2/ APC cache hit but APC was using files (then OS cache miss, don't know why) 3/ brief, my question is "when cache worked badly, there is (almost) no disk I/O" - what you're saying is completely contrary to that.
Comment: If you use file-backed memory mapping (e.g. `apc.mmap_file_mask=/tmp/apc.XXXXXX`) you might see elevated I/O. Try setting `apc.mmap_file_mask` to use shared memory (e.g. `/apc.shm.XXXXXX`) or to `/dev/zero` (anonymous mmapped memory).
Comment: @psusi from Feb 6th 12pm to Feb 8th 12pm it was low, then increased.
Comment: @cyberx86 I've just changed it (commented out that line to use anonymous mmapped memory) and it looks like that help. I'll monitor a few minutes more to see. Thanks.
Comment: It was zero during that time, then returned to about the same level it was at before.  Presumably the site was down or something during that time.
Comment: @psusi I was nearly zero during two days, and I was on it, so I know that it was not down. The traffic was normal (a few dozens of thousand of visitors/day). The only difference in those two days is cache was full and heavily fragmented.
Comment: so you are saying that the cache was working miraculously well during that time ( since there was no disk IO, it must have had a 100% hit rate ), and not at any other time?  In other words, when you were worried about the cache being full it was working perfectly, and your fix put it back to working only normally?
Answer: If you use file-backed memory mapping (e.g. apc.mmap_file_mask=/tmp/apc.XXXXXX) you might see elevated I/O.
Try setting apc.mmap_file_mask to use shared memory (e.g. /apc.shm.XXXXXX) or to /dev/zero (anonymous mmapped memory). Keeping the setting undefined defaults it to using anonymous mmapped memory.
Usually, mmapped files is a great thing:

Compared to storing something fully in memory, mmapped files usually require less memory
Compared to saving something to a file, mmapped files require less disk I/O (since writes can be aggregated together).

However, compared to storing something purely in memory, they do incur added I/O - considerably so when the file is continuously changing. The downside of not using mmapped files is a lack of persistence - your cache will not survive a restart, since it is stored only in memory.
One may suggest therefore, that while the cache was filling up and stabilizing, it was undergoing the most change, which had to be constantly written to disk; once the cache was full, the ttl for each object slowed the rate that data in the cache was being turned over, decreasing the change and reducing disk writes.
Answer: After a few days, now I want to come back with some graphs. The change improves much that situation. It reduces everything, except the IO service time (I think it's because there is no longer trivial small PHP file read which is cheap).

The server load (it was quite low already, so I had not discovered the change).
Comment: Could you please provide the changes that you made?
Comment: Read the question comment and the accepted answer. I commented out `apc.mmap_file_mask=/tmp/apc.XXXXXX`
Comment: Hey, sorry to bother you. Did you ever see any side effect on commenting out the mmap_file_mask line?. I'm seeing the same problem... and this clearly solves my I/O usage issues. But i was wondering... if nothing else will break!. Thanks!
Comment: I didn't have any problem commenting out that line.

High disk I/O when cache is used?


How to convert a Gamma GLM to a Pearl's Structural Causal Model (SCM) with exogenous noise terms?

Question: Assume both X and Y are univariate for this. So in Judea Pearl's SCM, you have endogenous variables and exogenous noise. A regular causal Bayesian Network like X->Y where X and Y|X is normal can be represented as both a PGM and an SCM as follows:
PGM representation:
$X \sim ~ N(\mu_X,\sigma_X)$
$Y \sim ~ N(\beta_0 + \beta_1*X,\sigma_Y)$
SCM representation:
$\epsilon_X \sim N(0,\sigma_X)$
$ X \sim~ Dirac(\mu_X + \epsilon_X) $
$\epsilon_Y \sim N(0,\sigma_Y)$
$Y \sim ~ Dirac(\beta_0 + \beta_1*X + \epsilon_Y,\sigma_Y)$
Essentially, the mapping Y=f(X) is now deterministic, and the noise is separated. This enables one to answer counterfactual queries in Pearl's framework where by inferring the noise, it is possible to see what would have happened at an individual level if X were set to something else.
I'm wondering, how can one do the above if Y|X is say Gamma distributed or some other GLM distribution?
In the case of logistic regression, it seems possible following the latent variable formulation here https://en.wikipedia.org/wiki/Logistic_regression#As_a_latent-variable_model where it is possible to simulate the error exogenously. But I am wondering how do it it for a general case like the Gamma.
The hard part seems to be that with a Gamma, the noise is not independent of the mean, so I'm not sure how to separate it. Does that imply SCMs cannot capture other distributions?
Answer: With GLMs we usually presume that the distribution is determined by the mean. So $\mu = \beta_1 X + \beta_0$ determines some Gamma distribution $g_\mu(y)$.
Next, consider the inverse $G^{-1}_\mu(e)$ of the cumulative function $G_\mu(y)$ of $g_\mu(y)$. Now, use as exogenous variable $\epsilon_Y$ a uniformly over $[0, 1]$ distributed variable $\epsilon_Y\sim U(0, 1)$. Then you obtain as your SCM representation for $Y$:
$$
Y = G^{-1}_\mu(\epsilon_Y),
$$
which utilizes the endogenous variable $X$ through $\mu = \beta_1 X + \beta_0$ and an exogenous random variable $\epsilon_Y$.
Comment: Oh wow, didn't think it would involve inverse transform sampling with U(0,1). Is there no simplification available as there is with the Normal and Binomial cases? Performing counterfactual inference on this sort of model seems difficult
Comment: You often have [additive noise models (ADM)](https://proceedings.neurips.cc/paper/2008/file/f7664060cc52bc6f3d620bcedc94a4b6-Paper.pdf), in which case it is easy.


Elementary Proof: If $x \in [a]$ and $y \in [b]$, then $x+y \in [a+b]$ where $a\sim b$ is an Equivalence relation if $5| (b-a)$

Question: If $x \in [a]$  and  $y \in [b]$, then $x+y \in [a+b]$ where $a\sim b$  is an Equivalence relation on $\mathbb{Z}$ if $5| (b-a)$.
Honestly I don't know where to start on this one, I know the definition of an equivalence relation and some the key proposition used such as
Given $\sim$ equivalence relation on $A$ I know the equivalence class of $a \in A$ is
$$[a]:= b \in A:b\sim a$$
and by some proposition I know
(i) $a \in [a]$
(ii)  $a \sim b$ if and only if $[a]=[b]$
Where do I go from here?
Edit:
I know that if $x \in [a]$ then $5| (x-a)$
and if $y \in [b]$ then $5|(y-b)$.
This means by definition of divisibility $(x-a) =5j$ where $j \in $  $\mathbb{Z}$ and $(y-a) =5r$ where $r \in $  $\mathbb{Z}$
So I want to show $x+y \in [a+b]$ which means $5| (x+y) -(a+b)$. By some basic math I see  $5| (x-a)+(y-b)$ and by replacement...
$5| 5(j + r)$ which is clearly true.
Answer: If $x \in [a]$ then $5|x-a$.
Similarly $5|y-b $.
Now you need to show that $5|(x+y)-(a+b)$. Can you take it from here?
Comment: Thank you but how do you know if  $x \in [a]$ then $5|x-a$ and $5|y-b$ and that $x+y \in [a+b]$ means $5| x+y \in [a+b $? I am new to equivalence relations, is just the definition or some proposition?
Comment: You said it in your post. If b in [a] then b ~ a. This follows from the definition.


Logistic regression model is ignoring most of my conditons

Question: So I have a logistic regression model in R with 2 variables, year (integer-10 values) and faculty (factor with 2 levels).
For some of my year/faculty conditions, the number of successes were the same as the total number of cases (i.e proportion = 1.0). So when I produce my model is it ignoring these cases, and the model is significantly under predicting. How can I fix this?
Comment: Assuming you are using standard R packages, these cases will certainly not be ignored in estimation. That they are under-predicted (fitted) makes sense: you can't expect a perfect fit unless you are badly overfitting, and there is nowhere else to deviate from 1.0 than downward. If you can post your data and a minimal working example exhibiting your problem, we may be able to help you.
Comment: @StephanKolassa That seems like an answer to me.
Answer: Assuming you are using standard R packages, these cases will certainly not be ignored in the estimation.
That actual 1s they are under-predicted (fitted) makes sense: you can't expect a perfect fit unless you are badly overfitting, and there is nowhere else to deviate from 1.0 than downward. For the same reason, 0s will be "over"fitted, i.e., the fitted value will be larger than the observed 0.
If you can post your data and a minimal working example exhibiting your problem, we may be able to help you.
(See here for a motivation for short answers. Longer answers are always welcome.)