How to achieve "Burn Rubber on Me" synth bass effect?

Question: At the beginning, the bass imitates tire scratching with very quick short percussive sound and a slide. Is this kind of effect often done by quickly press keys with one hand or by alternating hands? How to get the slide sound?
Is there any tutorial or video talking about this kind of bass music making?
Thanks!
Answer: That seems more like a "Glide" (or "Portamento") effect.
How to obtain that depends on the instrument: the synth that appears on the video is more likely an ARP Pro/DGX, which is a monophonic synth. While the instrumentation shown in videoclips at that time didn't always match the actual instruments being used in the record, polyphonic analog synths were a bit of a rarity and were not normally used for these kind of "bass-lines" for which monophonic synths were (and somehow still are) much more flexible.
On monophonic synthesizers, the "glissando" is usually obtained by pressing and keeping pressed the "starting" key, then press the "ending" key (and possibly releasing the previous one), and finally release the last key to stop the sound.
If the effect has to start immediately, the performer has to carefully learn how to "time" the whole press/press/release/release sequence.
Results can vary depending on how the instrument works, how the envelope is set, and how the instrument behaves with multiple keys being pressed.
For instance, an instrument could start a new envelope when a new key is pressed, even if a previously key is still being kept down, and the "glissando" could be triggered only on release of that new key if the other key is still down.
Unfortunately, there's no straight and common way to achieve this: the effect is common to many instruments, but the technique might be very different.
Considering a parallel with "classical" instruments, while a glissando is an effect that can be achieved with most of them, each instrument has its own technique: it can be done relatively easily with stringed instruments (but there's the limitation of the string range), "key-based" instruments are normally limited by their keys/strings/bars, which have discrete intervals (opposed to continous pitch changes, and usually related to the intervals between each "key"). It doesn't even depend on the instrument family: wind instruments can have a slide (trombone, slide whistle) or not, and it's up to the performer's technique to achieve the wanted effect; some percussions allow that in a continuous way (timpani, rototom), some others in a discrete way similarly to a piano, others are just not able to play a distinct and modifiable pitch (similarly to a "noise generator" for electronic instruments)[1].
You have to find the instrument that can do a similar sound, and then find out how it works in order to understand if and how the glissando can be obtained.
If you also have to perform it live, you obviously have to practice it 40 hours a day ;-)
[1] technically speaking, almost any perceived sound can be modulated to a different "pitch", as sound is based on a sum of harmonic frequencies, as long as they have a sufficient duration: you can "pitch" a snare drum, a finger snap, and even a white/pink/etc noise.


Is it important for a guitarist to know how to use a pick?

Question: I've been playing guitar for almost a year and a half now and I still don't know how to use a pick. I strum very hard and I'm afraid that my guitar strings would break from the pick. Would this be detrimental to my playing in any way? Wouldn't I advance in learning guitar if I didn't know how to use one?
To get you in perspective on my playing skill, I could play "If" by Bread (by plucking), "Norwegian Wood" and "Here Comes The Sun" by The Beatles, and the intro of "Stairway To Heaven" and "Dust In The Wind"(the reason I only play the intro in the former I'm still unfamiliar with the song and the latter I lost the tabs).
Am I learning too slowly? Would knowing how to use a pick affect my playing skills?
Can a guitarist even make do without using a pick?
Comment: "I'm afraid that my guitar strings would break from the pick." Seriously?
Comment: Um, yeah, it's acoustic, and I strum too hard, people tell me.
Comment: See how hard Jack Black is strumming his guitar... The strings seems to survive, at least for the show ! There is no risk with a thin pick
Comment: Mark Knopfler, Lindsey Buckingham, Chet Atkins, Leo Kottke, Mississippi John Hurt, etc. etc.  Fingerpickers all, no pick needed.  Go watch some of their YouTube videos, you'll see how unnecessary a pick can be.
Comment: Just for completeness, Chet Atkins used a thumb pick and had amazingly long nails. Just amazing how he played. If you want to watch Chet Atkins and Mark Knopfler play together, check this out on YouTube: http://www.youtube.com/watch?v=5wTVLIZaxMk&feature=related. You can see in the closeups how they attack the strings. They use a lot of finesse, and the more you listen to them the more subtleties you'll pull out of their music.
Comment: You can definitely break strings playing too hard. Some people break strings frequetly, others hardly at all - I saw Ed Sheeran break _all_ his strings playing too roughly live, whereas I have _never_ broken a string.
Comment: I use a pick but strike the strings with the wider "shoulder" of the pick. Better grip and warmer sound and better control, for me.
Answer: Yes, you can make do without a pick if that is your preference.
Use or non-use of a pick (or plectrum) tends to vary by musical style.  Flat picks are not used in classical guitar playing (to my knowledge), nor are they used in fingerstyle playing, for example (although fingerstyle guitar players may use a thumb pick).
It is true that picks are commonly used in playing rock and jazz, but there are exceptions.  Mark Knopfler is an example of a rock guitar player who does not use a pick, and Wes Montgomery is an example of a jazz guitar player who did not use a pick.
As to your progress, that's difficult to judge based solely on your post.  I would recommend playing for a more-experienced friend and see what he or she thinks.  Or go to a guitar teacher (although he or she may suggest you try a pick!)
You probably should at least try a flat pick and see what you think if it, especially if you intend to play rock.  Try starting with a thin pick if you're worried about breaking the strings, and have a teacher or friend show you how to use it.  There's no need to be overly-concerned about breaking the strings unless you're using a really heavy pick and whacking the strings way harder than necessary.
Answer: Here are two reasons you might want to use a plectrum.

Your goal is to make the kinds of sound that a plectrum makes
You want to broaden your insight into music, by which I mean you don't want to perform with a plectrum, but you want to incorporate what you learn from practising with one into your finger-picking repertoire.

For strumming, the main effect of a pick is that it sounds different from the same chord strummed with fingers. Whether you like that sound, is entirely up to you.
For plucking individual strings, the sound is still different, but there's more to think about.
Fast melodic figures that are very difficult with fingers, become fairly straightforward once you've got the hang of bidirectional picking with a plectrum (try the rhythm pattern from Howlin' Wolf's The Killing Floor)
Techniques such as palm-muting seem to me to be a lot easier to achieve when you're picking with a plectrum -- something about the position of your hand when holding a plectrum.
Of course there are a tremendous number of finger-picking techniques you can't achieve with a plectrum.
Many guitarists play exclusively with a pick, and are asking the opposite question to yours - "is it worth learning to finger-pick". The answer in both cases, is that it's up to you how broad or narrow you want your guitar expertise to be.
If you play so violently that you're worried about breaking strings, you should probably learn to play more gently. I doubt it sounds all that good if you're pounding the strings with all your might.
Answer: There are a few techniques that require the use of a pick (especially ones with "pick" in the name, such as "sweep-picking"!)...
Also, there are obviously techniques that don't require the use of a pick, such as fingerstyle and slapping/popping(/whatever it is that Victor Wooten's brother does!).
I have found it useful to play with and without a pick. Early on as a guitarist, I would worry about dropping picks. But since I became proficient at playing without one, I almost never drop picks!
Comment: It's a little more difficult, but you *can* do sweep-picking without a pick by using the back of your index nail (i') for a down-stroke and the back of your thumb nail (p') for an up-stroke. YMMV.
Comment: Thanks, @luser. I forgot to mention the benefits of "chicken pickin" - where you hold the pick between thumb and index finger, then use the other three fingers to pluck strings as necessary/desired.
Answer: You might try going halfway and investigate hybrid picking. You hold the pick between just the thumb and index finger and pluck with the middle and ring fingers. It works for travis-picking like Blackbird, and adds emphasis to the bass in Stairway.
When the song changes gear, you've already got the pick ready.
There are other pragmatic reasons why you should at least learn how to use a pick, even if you don't adopt it as your personal style.

It's what the music director wants.
It's the way the record goes.
Answer: Whether you use a pick or not really just comes down to personal goals, preferences and tastes. If you want to learn rock, jazz or other genres that mainly use electric guitar, then you would probably want to learn to use a pick. If you want to learn classical or fingerstyle, then you can just use your fingers or a thumbpick. I don't think it would be detrimental to your playing or ability to improve if you do not use a pick. Having said that, some techniques are definitely easier to with a pick (sweep-picking, speed-picking). However there are no hard and fast rules. Paco De Lucia and Lawson Rollins are examples of guitarist that manage to achieve ridiculous speeds without using their fingers. Jeff Beck is a rock guitarist who decided to stop using a pick. Then we have Tommy Emmanuel and Andy McKee, both guitarists that started learning with a pick, then transitioned to fingerstyle and became amazing at it. Both of them still use a pick in some of their songs. I personally played guitar for about two years before learning to use a pick. And some guitarists (usually classical) such as John Williams, never use a pick, and he's amazing at playing the guitar.
If you were to ask me, I'd say learn to use a pick. I found that learning to use a pick allows me to play a wider variety of styles and technique. If I were you, I wouldn't worry about breaking strings. I can use a 2mm pick with no problems, and Tommy Emmanuel uses even thicker picks (even when strumming!) If you're still worried about breaking strings, you can always use a thinner pick. After some practice, you should be able to gain control of your strumming. Of course, the choice is really up to you.
Answer: Watch bluegrassers. Watch Lester Flatt. Watch Pete Townshend. Watch Michael Hedges. Watch any flamenco players. If you are near the record for trying to hit the strings hard, without protecting your fingers, you have iron fingers and feel no pain.
Many of my favorite players, electric and acoustic, play with their fingers and no pick. Tommy Emmanuel. Michael Hedges. Jeff Beck. All the other names mentioned. I palm the pick and play with fingers for slower songs sometimes. Good skills to have.
But when you pick with a pick, you pick up clarity and volume, and while there can be a lot to it, such as alternate picking, downpicking, pick angle and a host of other stuff, but at the first, when it's just strumming, picking is just easy. But it's called dynamics. If you wanna go "Ever since I was a young boy, I played the silver ball....", going between the F and the Fsus4 means you have to strum hard and fast, but if you want to play "Baba O'Riley", there's the big chords, but they have to pop out when you want them, which means you have to pull back the strong right arm a little bit.
Comment: I was responding to this: *"I strum very hard and I'm afraid that my guitar strings would break from the pick."* Playing hard might occasionally break strings if you're Godzilla or play with a metal pick, but breaking strings comes more from string age, metal fatigue and problems with the instrument. Never meant to imply Pete doesn't play with a pick, just that the worry is not well founded.
Comment: One of the main reasons I bought a guitar is because of "Pinball Wizard"! I never knew Pete Townshend didn't use a pick. Thanks for that information and your answer, ^^


Is the Jackknife estimation better than Maximum Likelihood Estimator?

Question: I'm trying to estimate distribution parameters with Maximum Likelihood Estimator (MLE) and Jackknife estimator based on it. The estimation statistic is mean.
Jackknife estimator is considered to be better than MLE, but somehow I get the same numbers.
What am I doing wrong?
I'm using the following R code:
# Function to return sample mean as estimator
MME_estimate_lambda <- function(vec){
    return(mean(vec))
}

# Function to perform Jackknife estimation
Jacknife_estimate_lambda <- function(vec){
    n <- length(vec)
    estimators <- sapply(seq(n),function(i) MME_estimate_lambda(vec[-i]))
    return(n*MME_estimate_lambda(vec) - (n-1)*sum(estimators)/n)
}

set.seed(123)
mysample <- rexp(50,1) # sample from Exponential distribution
MME_estimate_lambda(mysample)
Jacknife_estimate_lambda(mysample) # Both estimators are the same

Answer: You are not doing anything wrong, the are suppossed to give the same number (in this simple setting):
# the true mean of y is 0
y <- rnorm(1000)

# The MLE estimator is simply the sample mean:
MLE <- mean(y)

# The Jackknife estimator is:
require(bootstrap)
JKE <- mean(jackknife(y, mean)$jack.values)

# Both estimator's results in:
# 0.009662955
# Exatcly the same number.

# However the estimated standard error is different:
JKE_se <- jackknife(y, mean)$jack.se
# 0.0307548
MLE_se <- sqrt(var(y) * (length(y)-1) * 1/length(y))
# 0.9725519

Oops! The estimated sd for the jackknife is way off. There is general lesson here, provided you are willing to asumme the distributional assumptions imposed by MLE you cannot do any better. The nice thing about the jackknife, and orther resample methods, is that they do not impose such rigorous assumptions.
Of course today, with modern computers, there isnt really a reason to rely on the jackknife, instead you would almost always be better of using a simple bootstrap - because you learn something about the sampling distribution.
Answer: Comparing maximum likelihood estimation (MLE) and the jackknife is like comparing apples and oranges. These techniques accomplish different things.

Maximum likelihood estimation is a method for estimating parameters and fitting models. Since it's based on maximizing the likelihood function, it's a model-based algorithm.
The jackknife is a method for estimating the bias and variance of estimators. It doesn't make distributional assumptions about the data generating process, so it's nonparametric.

Let's highlight the difference between estimating a parameter and estimating the variance of that estimator. I'll use @Repmat's example.
Let $x_1,\ldots,x_n$ be independent draws from a population with mean $\mu$. The sample average $\bar{x} = \sum_{i=1}^nx_i/n$ is an estimator of the mean $\mu$.
How accurately does $\bar{x}$ estimate $\mu$? In other words, what is the variance of $\bar{x}$?
The jackknife's answer is:
$$
\begin{aligned}
\widehat{\operatorname{var}}_{\text{jack}} &=
\frac{n-1}{n}\sum_{i=1}^n\left(\bar{x}_{(i)} - \bar{x}_{(.)}\right)^2
\end{aligned}
$$
where the $\bar{x}_{(i)}$ are the jackknife values:
$$
\begin{aligned}
\bar{x}_{(i)} = \sum_{j\neq i}\frac{x_j}{n-1}
\end{aligned}
$$
and $\bar{x}_{(.)}$ is the average of the $\bar{x}_{(i)}$s.
Now let's assume further that the $x_i$s are independent draws from a Normal distribution with mean $\mu$ and variance $\sigma^2$. Since we've made a distributional assumption, we can use maximum likelihood to estimate $\mu$ and $\sigma^2$.
$$
\begin{aligned}
\hat{\mu}_{\text{MLE}} = \bar{x}, \quad \hat{\sigma}^2_{\text{MLE}} = \sum_{i=1}^n\frac{(x_i - \bar{x})^2}{n}
\end{aligned}
$$
In the Normal model, how accurate is $\bar{x}$ as an estimate of $\mu$? We start by computing the variance of $\bar{x}$ in terms of $\sigma^2$.
\begin{align}
\operatorname{var}(\bar{x})
= \sum_{i=1}^n\frac{\operatorname{var}(x_i)}{n^2}
= \frac{\sigma^2}{n}
\end{align}
And since we don't actually know $\sigma^2$, we use the plug-in principle and substitute $\hat{\sigma}^2$ for $\sigma^2$.
To sum up, we have an estimator $\bar{x}$ of the mean $\mu$ and two estimates of the variance of that estimator, one derived with the jackknife and the other with maximum likelihood. Let's calculate them on some data.
set.seed(1234)

# We simulate some normal data but the jackknife makes no distributional assumptions.
n <- 1000
x <- rnorm(n)

# The MLE estimate of the population mean is the sample mean:
xbar <- mean(x)

# The MLE estimate of the population variance:
s2 <- sum((x - xbar)^2) / n

# The plug-in estimate of the variance of the sample mean:
s2 / n
#> [1] 0.0009936879

Now use the jackknife implementation in the bootstrap package.
library("bootstrap")

# The jackknife estimate of the variance of the sample mean:
(jackknife(x, mean)$jack.se)^2
#> [1] 0.0009946825

Okay. So the jackknife has a slightly bigger estimate for the variance of $\bar{x}$. Does it mean that it's better? The MLE estimate of $\sigma^2$ is biased by a factor of $n/(n-1)$: $\widehat{\sigma}^2_{\text{MLE}}$ is a little too small on average, so when we plug it in for $\sigma^2$ we underestimate the variance of $\bar{x}$. The jackknife estimate is corrected for that bias, hence it's better in a certain sense. For large samples the difference is negligible.
PS: With some algebra you can show that the difference between the MLE and the jackknife estimates of the variance of $\bar{x}$ is a factor of $n/(n-1)$.
PPS: What @Repmap calls MLE_se is the MLE estimate $\hat{\sigma}$ of the population standard deviation $\sigma$. Not an estimate of the standard error $\widehat{\operatorname{se}}$ of the sample mean $\bar{x}$.


Proof that the reals are uncountable by Königsberger

Question: I found this proof in Chapter 2 (Satz 7) of "Analysis 1" by Königsberger (hope it is not a duplicate)
It begins by defining an "Intervallschachtelung" (I don't know any good translation), which is a sequence $I_1,I_2,...$ of closed intervals (in the real line) such that:

$I_{n+1}\subset I_n$ for every $n\in\Bbb N$
For every $\epsilon\gt0$ there is one intervall $I_n$ with length $\vert I_n\vert\lt\epsilon$

The book gives the next as a principle: For every Intervallschachtelung in $\Bbb R$ there is a real number that belongs to every interval (Intervallschachtelungprinzip)
Now the proof: Let $\Bbb R=\{x_1,x_2,...\}$ be the countable set of every real number. Now we construct an Intervallschachtelung $(I_n)$ such that $$x_n\notin I_n$$ beginning by setting $I_1=[x_1+1,x_1+2]$ and getting $I_{n+1}$ from $I_n$ by recursion: divide $I_n$ in three equal parts and choose $I_{n+1}$ to be the one that doesn´t contain $x_{n+1}$. $(I_n)$ is an Intervallschachtelung and therefore there is a number $s\in I_n$ for every $n\in\Bbb N$ but if $s$ had been some $x_k$ in $\Bbb R$, then $x_k=s\in I_k$ which is a contradiction and thus $\Bbb R$ is uncountable
Now my question: isn't this the same as Cantor's diagonal argument? You are "making" a number different from the ones that you have listed, if so, why is it necessary the some unproven principle? (I haven´t found any proof anywhere)
Why is it important to divide each interval into three parts? I'm asking because in a previous Staz, two (equal) parts were enough. I think it only serves to avoid having $x_{n+1}$ right between the two parts but could two non-equal parts also do the job (given that you have a procedure of avoiding that)?
Thanks
Comment: The main advantage of this approach to Cantors is that it doesn't rely explicitly on digits. Cantor is implicitly assuming a lot of principles about the real numbers that this proof is making specific. But it is certainly a related proof.
Comment: Note that the 'Intervallschachtelungsprinzip' is not unproven, it is equivalent to the fact that the real numbers are complete, i.e. that any Cauchy series converges or that any bounded set has a supremum.
Comment: I'd translate "Intervallschachtelung" as "sequence of nested intervals."
Comment: Also note that the authors splits the interval into 3 parts because if you split into two parts, you get problems if the next $x_n$ is in the middle of the invterval. Of course you could just split into non-equal parts in that case, but this would cause some technical issues which might make the proof harder to follow...So you better just split into 3 parts and you are fine.
Comment: @ThomasAndrews It may not be the diagonal argument, but it's still due to Cantor: https://en.wikipedia.org/wiki/Georg_Cantor%27s_first_set_theory_article#Second_theorem
Comment: @JackM Well, it is a bit like Cantor. It is essentially picking the number digit by digit (base 3) and we are ensured that the resulting number up to the first $n$ digits differs "enough" from $x_n$ to be distinct.
Comment: And, of course, Cantor is using the completeness of the real numbers implicitly when assuming that any infinite sequence of digits is a real number.
Comment: It's weird the the proof is used to find a single element. You could, in theory, let $I_{n+1}=I_n$ when $x_{n+1}\not\in I_n$. Then you are using the related property that the intersection of descending sequence of closed intervals is always non-empty.
Answer: A a high level, this is the same as the diagonal argument: both have the general form:

Assume that $f$ is any function $\mathbb N\to\mathbb R$. Then here is a procedure to find a real number that is not in the range of $f$. (bla bla bla bla). Therefore $f$ is not surjective.
Since $f$ was arbitrary, we have concluded that there is no surjective function $\mathbb N\to\mathbb R$. In particular there is no bijection.

They differ in how the procedure for finding a number that is not hit works.
(But notice that if we change the construction you cite to divide into ten subintervals instead of three, what actually happens is very close to the diagonal argument).
The nested-intervals method was the first uncountability proof Cantor published in 1874. The decimal-based diagonal argument came later, in 1891, and is generally thought of as more instructive (especially in the modern age where elementary-school mathematics puts a lot more weight on decimals than on fractions).

Dividing the interval into exactly three equal parts is not particularly important. It's just the easiest way to make sure that there is one of the subintervals that doesn't contain $x_n$.
If we divided the interval $[a,b]$ in to only two parts $[a,\frac{a+b}2]$ and $[\frac{a+b}2,b]$, we would be stuck if $x_n$ happened to be $\frac{a+b}2$, because that is in both intervals. As you say, this is easy enough to remedy if you hit the problem: just shrink one of the intervals slightly. You can view the three-intervals division as simply the remedy that the author thought would be simplest to describe.
Note that it is never necessary to select the middle interval, so we could also describe the same construction as "for $I_n = [a,b]$, consider the two intervals $[a,\frac{2a+b}3]$ and $[\frac{a+2b}3, b]$ ..." -- but this is again (at least arguably) slightly more involved to write and understand than just saying "divide $I_n$ into three equal parts".

As MooS says in comments, the Intervallschachtelungsprinzip is not unproven, it is equivalent to the fact that the real numbers are complete, i.e. that any Cauchy series converges or that any bounded set has a supremum.
In particular we can find a number is the intersection as the limit of the sequence of left endpoints. This sequence is upwards bounded (by the right endpoint of the first interval), and non-decreasing; therefore it has a limit. And it is a simple exercise to see that this limit must be in each of the intervals.
It may seem that the fact that such a sequence has a limit is a "new unproven assumption" that is needed only for this variant of the proof. But in fact the very same assumption is used in the diagonal proof -- hidden inside the taken-for-granted fact that  every infinite sequence of decimals defines a real number.


Str_replace special character mail template

Question: I have a email template but i want dear text replace from textarea.
i'm use str_replace to edit text.
If use this code and content have character
' result is \'
$html =str_replace('{{dear}}',$content,$html);

if use code
$html =str_replace(array('\'', "'"), '', $html);

result all image url error.
Comment: PHP doesn't add backslashes to strings by itself. Something else is doing that. Are you sure there are really backslashes in there? If you use `json_encode()` it escapes some special characters, but they'll be decoded when you use `json_decode()` so the right thing should happen.
Answer: Use stripslashes function and $html =str_replace("'", '', $html);
PS
OR In your Code use the below line.
$html =str_replace(array("\'", "'"), array('',''), $html);


How to compact large directories

Question: Is there a way to compact a very large directory under EXT2/EXT3 without simply remaking the directory?
I recall that perlfunc cautions that the OS implementations of seekdir and telldir run the risk of directory compaction. which sounds like what I want in this case, but I'm unfamiliar with those semantics in practice.
background:
I've a few directories that are themselves many MB in size -- they were overrun with a zillion small files in the past:
$ ls -lh
drwxr-x--- 2 root root 1.3M Oct  5 12:49 big
drwxr-x--- 2 root root 2.3M Oct  5 12:49 this_one_is_empty_now
drwxr-x--- 2 root root 6.1M Oct  5 12:49 yikes

Comment: Reiser3 is the answer. :-)
Answer: Directories can not be compacted online exactly because of the requirements of seekdir/telldir.  They require any program to be able to maintain position within the directory for indefinite time and still only read any given entry once; therefore, the entries can not be moved around while the fs is mounted.
You can compact the directory offline with e2fsck -D.
Comment: I think those are rather soft requirements, as the GNU docs for `dirent` caution that seekdir/telldir may not be reliable.  The point about e2fsck is well taken. +1
Answer: Have you looked into pigz?  It's an improved gzip.
John Allspaw talks about it on his blog here:
http://www.kitchensoap.com/2010/04/02/pigz-parallel-gzip-omg/
Comment: I think the OP wants to reduce the size of the directory file within the filesystem rather than compress the actual files

How to compact large directories


Postfix Maildir to MySQL migration

Question: I'm currently running postfix on a CentOS 6.5 box.The mail is currently stored in the users Maildir directory. Users utilize roundcube as a web mail client.
This is a low priority machine and there are only a handful of users (less than 10). The total amount of mail storage consumed is less than 1G, however someone in my dept is insisting I migrate the mail to MySQL because it's more secure and efficient.
What I need to know is:
Firstly are the benefits mentioned accurate? Are there any other benefits or drawbacks to using Postfix with MySQL? The system currently receives a very low volume of mail (less than 20 a day).
What (briefly) are the steps involved in migrating the mail (if it's even possible) ? If it's going to be a disruptive exercise it might not be worth it.
Thanks!
Comment: What kind of POP/IMAP server you have used now?
Comment: Ask that someone why MySQL would be more secure and efficient. I'm assuming this would be for storage of the mail itself?
Comment: Further details - IMAP provided by Dovecot. I *think* this is just for mail storage, I'm not entirely sure if it was being suggested that postfix configuration be stored too.
Answer: While nothing prevents Postfix from delivering mails to an MDA that stores the received mail in an SQL database (maildrop-mysql exists, AFAIK), it wouldn't make sense to do so if common IMAP servers like Cyrus, Courier or Dovecot are involved to access the mail as they are unable to use an SQL database as a storage backend.
Also I would consider the claim that storing the mails in a MySQL database is more secure and faster as plainly wrong. If the correct permissions are set on the maildirs and Dovecot is correctly configured and up to date, it wouldn't be any more secure, as everyone who can read the maildir files would likely be able to get a dump of the SQL tables as well. And since Dovecot etc. are highly optimized to work with large volumes of mails I can't see how using an SQL database with all its overhead (and the lack of tree data structures) would offer a performance benefit.
Tell your colleague that this whole thing doesn't make any sense.
Comment: Even more - dovecot have its own indices that makes access very, very fast. Also dovecot can deduplicate messages and filter them by the `sieve`. There is no reasons to prefer mysql storage.
Comment: Thanks so much for you answer. I feel better armed to have a good debate about the topic now!

Postfix Maildir to MySQL migration


Why does a root extension has a Galois closure?

Question: The following are a definition and a lemma (Lemma 14.38 in Dummit's "Abstract Algebra").

Definition. An element $\alpha$ can be expressed by radicals or solved for in terms of radicals if $\alpha$ is an element of a field $K$ which can be obtained by a succession of simple radical extensions
\begin{equation}
F=K_0\subsetneq K_1\subsetneq\cdots\subsetneq K_i\subsetneq K_{i+1}\subsetneq\cdots\subsetneq K_s=K
\end{equation}
where $K_{i+1}=K_i(\sqrt[n_i]{a_i})$ for some $a_i\in K_i$ and $n_i\in\mathbb N^*$, $i=0,1,\ldots,s-1$. Here $\sqrt[n_i]{a_i}$ denotes some root of the polynomial $x^{n_i}-a_i$. Such a field $K$ will be called a root extension of $F$.

Lemma. Let $F$ be a field of characteristic $0$. If $\alpha$ is contained in a root extension $K$ as in the definition above, then $\alpha$ is contained in a root extension which is Galois over $F$ and where each extension $K_{i+1}/K_i$ is cyclic.

The proof starts with this:

Proof: Let $L$ be the Galois closure of $K$ over $F$. ...

But how do I know that there is a Galois closure $L$? I think the proof that there is a Galois closure $L$ should go like this.

All $K_{i+1}/K_i$ is a finite extension.
All $K_{i+1}/K_i$ is a separable extension.
Thus $K/F$ is a finite separable extension, since finiteness and separability of extensions are transitive.
All finite separable extension has a Galois closure, so $K/F$ has a Galois closure.

I couldn't prove 2. If $K_{i+1}$ is a splitting field of the minimal polynomial $m_{\sqrt[n_i]{a_i},K_i}(x)$, then $K_{i+1}/K_i$ is Galois since it is a splitting field of a separable polynomial, so it is separable. But I don't know if it really is a splitting field.
Comment: In characteristic zero, any finite extension is separable, so is contained in a Galois extension.
Answer: If $K$ is a separable algebraic extension of a field $F$, then its Galois closure is the smallest extension field, in terms of inclusion, which contains $K$ and is Galois over $F$.
If $K=F(\alpha)$ where $\alpha$ has irreducible polynomial $f$ over $F$, then the Galois closure of $K$ is the splitting field of $f$ over $F$.
If you have a finite extension in characteristic zero, then it is automatically separable. Hence there exists a Galois closure.


Get distance between top of scrollable parent and one of nested child nodes

Question: I have vertically scrollable
 with several
 in it.
HTML:

item1

item2

item3

item4

item5

item6

item7

CSS:
ul {
    max-height: 50px;
}
li {
    display: block;
    height: 10px;
}

Then with JS I get <ui> and one of
 nodes:
let ul = document.querySelector('ul')
let li = document.querySelector('li:nth-child(3)')

And I want to make function which gets ul and li nodes (something like getDistance(ul, li)) which returns distance between top of the ul and li in pixels.
The question is how to make that function.
Comment: Why? For `nth-child(3)` it is probably 3 ?
Comment: `getDistance(ul, li)` is for getting distance in `pixel` or `percentage` ?
Comment: Distance in pixels.
Comment: [Hope this works](https://stackoverflow.com/a/50628644/9674579)
Answer: x = /*your ul element*/
y = /*your li element*/
distX = y.offsetLeft - x.offsetLeft;
distY = y.offsetTop - x.offsetTop;
distance = Math.sqrt(distX*distX + distY*distY);
alert(Math.floor(distance));

but you have to substract first x's height and width, if you put something inside. This method has some issues with support and border width of elements in different browsers.
Comment: If my answer works for you,  then please accept it and up vote it ;)


Cumulocity Regionalization

Question: Is it possible to adapt data display in Cumulocity to the current location of the accessor. E.g. to adapt date, time and units to the location and timezone of the current viewer.
This is necessary for machines that are distributed worldwide but data in cumulocity is viewed remote of the machine location. Therefore data need to adapt to preferred unit at that location as well as current timezone.
Does anybody have a solution approach or best practice to solve this issue?
Answer: Cumulocity UI uses moment.js so all timestamps are displayed in the local time of the browser.
For storage every timestamp is stored with the timezone that it was send with and will be returned as such on the REST API.

Cumulocity Regionalization


How to best code the N/A response of the Likert-type rating scale?

Question: Say I have a dataset of people's opinion/"rating" on something, and they have to choose 1 out of 5 possible answers for each question - Very happy, Happy, Neither happy nor unhappy, Unhappy and Very unhappy. In addition, some people don't answer anything - so let's say we mark these as N/A. We can map Very happy to 5, Happy to 4, and so on until Very unhappy is 1. But, how should N/A be mapped?

Should I regularize it and make it the mean of the possible options (i.e., 3)? What are the disadvantages of this method?
Should I make it 0, in which case it might affect some prediction results later?
Should I convert the features into one-hot encoding, in which case if there are n columns with these same possible answers, we'll have increased the number of features to 6n?
Should I make an extra column for only the N/A as one-hot encoding, so that there are 2 columns for rating - one for "non-N/A" (or valid scores), and one for N/A?
Should I randomly assign a number from 1 to 5 to the N/As?
Comment: You should try and see if not answering that question is correlated to the outcome. If it is, you'll have to model the `NA`s explicitly. If not, you can use multiple imputation.
Comment: Also, your data are ordinal. There are methods for estimating how they would relate to a numerical scale, but I wouldn't just go with 1-5 without looking into this first.
Answer: Some of the answers here seem more complicated or hi-falutin' than may be needed or indeed justified. For example, in many projects short of say Ph.D. level, getting into imputation may be beyond the time available or the skill level expected.
Also, the title says "N/A" which often means "not applicable". In the question itself the OP treats N/A as the researcher's coding for blank answers, in effect "no answer". Some of my answer covers N/A as a deliberate and allowed reply to a question. There is a lot of turbulent water between these interpretations.
It seems to me that the simplest possibilities have not yet been mentioned at all.

N/A is just another category. A side-effect of that: the scale is no longer ordinal.
Leave out the N/As from the data analysis. That is ethically sensitive as well as statistically sensible. Seriously, if I fill in a questionnaire and am given N/A as an option and then use it, that's my right within the survey I undertake. It should be taken that I meant what I said. Suppose that I really don't play golf or use Twitter or whatever it is, and that is why a question on preference for golf clubs or my Twitter attitudes really doesn't apply. I don't want some fool of a researcher analysing the data to presume or assume that I "really" meant something else and that the rest of my answers somehow are informative on what that might be. This also applies if I leave a question unanswered, given scope to do that.
There is one alternative that occasionally may make sense, which is to guess that N/A is in some sense equivalent to the neutral category. This has to be argued carefully, but the spirit is, perhaps, that for some questions they may both be flavours of "don't care".
Whatever the research strategy, if N/As are at all common, then a really careful study will include some kind of sensitivity analysis and explore different ways of analysing them, and explain how much difference it makes to the results of the study. Researchers often prefer not to do this, partly because it tends to underline how lousy the data are.
Comment: My answer was trying to say what Nick has said, but Nick said it better.  :-)
Comment: How best to do something still depends on circumstances: if I get similar questions from beginning students and senior colleagues, I may temper advice accordingly. Also, not every analysis is based on the idea that there is an underlying construct.  I have to demur on ethics in data analysis: there is at least one book on the subject https://www.crcpress.com/A-Statistical-Guide-for-the-Ethically-Perplexed/Hubert-Wainer/p/book/9781439873687 and even if there weren't any implication that questionnaire recipients have no rights to respect is perplexing. and contrary to best practice. .
Comment: I think "high falutin" answers are justified when the question is "how to *best* code..." I would also argue that, while it may be ethically sensitive to allow participants to skip questions, that has no bearing on data analysis. Participants who respond NA still (in most cases) have a score on the underlying construct. We want to estimate this score to better understand that construct. Throwing NAs away or assuming then to be the neutral response would bias your results as I explained in my answer.
Comment: I'll check out that book, but I don't see how using MI or ML to handle missing item data is a violation of participants' rights or contrary to best practice.
Comment: @NickCox Well, the `N/A`s in the questionnaire mean `did not answer`. Like I said in the question, there are 5 options to answer with for each question - `Very happy`, `Happy`, `Neither happy nor unhappy`, `Unhappy` and `Very unhappy`. So, when people do not answer anything, its recorded as `N/A`. I think I've covered at least 2 of your points in my question - your point 1 is my point 4 (and possibly point 3 as well); and your point 3 is my point 1.
Comment: About your point 2, I considered it, but the problem is, each row is a record of 1 person with 34 columns (questions). If I decide to remove the `N/A`'s, that whole row containing it becomes unusable. And since the `N/A`s appear randomly, it won't fare well for the analysis, as I'd have to remove more than half the data. Lastly, about your point 4, I am doing that. The `N/A`s are not extremely common, but occur often enough that they can't be ignored.
Comment: What's specific to your project is naturally for you to explain and to decide. As is explicit, I treated the question more broadly than your specific details, especially in view of the general title. On CV it's generally in order to underline wider or related variants of the question. That said, was "did not answer" literally in the questionnaire or just the researcher's coding? If you have disappointing data, you may need to act accordingly. I don't see why missing values for one question mean that you must remove one person, if that's what "row" means.
Answer: Filling in the missing values and then running your analyses would be called "single imputation," regardless of how you did so (e.g., setting them to the mean or setting them to some static or random numbers). Although this would be very simple to implement, it would unfortunately bias your results. If you used the mean, for instance, there would then be more data points near the mean and thus less variability in your data. As a result, your standard errors would be too small and you would become more likely to commit a type I error (false positive). Similarly, excluding people with missing data from the analysis would be called "listwise deletion" and would also bias results.
Instead, you should treat the missing values as missing values; modern statistical programs have a way to denote this (e.g., NA in R or NaN in MATLAB). Then use a missing data analysis technique to run your analysis in the presence of missingness. The two techniques to consider would be "multiple imputation" (MI) and "maximum likelihood" (ML). Both techniques can be combined with most common statistical analyses and will yield unbiased results assuming your data is "missing at random" (MAR) or "missing completely at random" (MCAR). These are complex concepts that you should read more about to fully understand, but know that a red flag (i.e., a sign that your data may not be MAR or MCAR) would be if you think that participants were more likely to not answer your question based on what their answer to that question would have been. For instance, if people who are extremely unhappy were more likely to leave this question blank than to answer it with a low score, this could violate the assumptions of MI and ML.
Comment: This answer is great but why not just partial out N/A as a separate variable, as I have suggested in my answer?
Answer: The safest way to manage this issue is Method 4 - create an indicator variable for answered/did_not_answer.
The advantage of Method 4 is that you retain all the information from your survey respondents. Marking N/A may be qualitatively different from filling out a score from 1 to 5. By treating N/A as an indicator variable, you give yourself the ability use it as a predictor variable without making risky assumptions or imputations beforehand (or, worse, analysing the data and making post hoc 'predictions' about what N/A means).
Related to the above paragraph, Methods 1, 2, and 5 decrease the informational value in your data. Method 3 would be better for the same information-preserving reasons that Method 4 makes sense, but the results will be harder to interpret, and you will lose the informational value that the 1-5 values are ordinal.
So, as an example with some Stata pseudo-code, let's say you have a rating scale from 1 to 5, where 'Not applicable' is coded as 6.
Then:
gen ratingapplicable =.
replace ratingapplicable = 1 if rating != 6
replace ratingapplicable = 0 if rating == 6
label define ratingapplicablelab 1 "Rating applicable" 0 "Rating not applicable"
label values ratingapplicable ratingapplicablelab

// Then, you can regress some new variable (let's say it's 'bonus')
// on rating and ratingapplicable
regress bonus rating ratingapplicable
// Note that you'll get a coefficient for rating, let's say it's 3045.
replace rating = 600 if rating ==6
regress bonus rating ratingapplicable
// Note that the coefficient for rating will still be 3045. Hoorah!
// Note that you'll still *also* have a coefficient for ratingapplicable,
// which represents the effect (on bonus) of the rating being applicable at all.

Edit: Method 3 may make a lot of sense if you're not sure that you should treat the scores as ordinal. This would be equivalent in Stata to using i.rating as a covariate, which will treat rating as a factor variable with no specific ordering between Very happy, Happy, Neither happy nor unhappy, Unhappy, Very unhappy, and N/A.
Comment: `ratingapplicable =.rating != 6` is pseudocode that works across various languages as returning 1 if `rating` is not 6 and 0 otherwise. (It's also a hint to slim your first three Stata statements into one.)
Comment: I played around with this method today and it works. The coefficient for rating doesn't change even when you change the value of the not_applicable from 6 to 600.
Comment: The stop within the code in the previous comment is a typo. Should be `ratingapplicable = rating != 6`.


Is Fisher's exact test right for this problem?

Question: Let's say I have 4 plants and I measure something under 2 conditions. For example:
The entries in the table show how many times I saw something under condition (C1 or C2) for plant (P1, P2, P3 or P4).

     P1,  P2,  P3,  P4
C1    0   20    0   19
C2  100   80  180  150

Now I would like to answer the question "what is the probability that these 39 times of seeing something is unevenly distributed between these 4 plants"?
I am much interested in observation like this, rather than, say:

     P1,  P2,  P3,  P4
C1   25   20   15   19
C2  100   80  180  150

Is it right to use Fisher's exact test for this? I just extended the question from a 2*2 table to 2*4.
Comment: No.  Fisher wouldn't answer your question.  And I am not sure you asked what your real question is.  Further reading:  http://en.wikipedia.org/wiki/Fisher's_exact_test
Comment: I already read that and framed the question from that. Maybe it goes something like this. For example 1, "Knowing that 39 out of 549 times I see `something` under C1, and that 100, 100, 180 and 169 of them are from P1, P2, P3 and P4 respectively, What is the probability that these 39 `something` are so unevenly distributed between the 4 plants? And this is what I desire.
I agree the second table is a bit misleading. It might or might not be significant (depending on the parameters that fisher's exact test computes).
Comment: Or in other words, if I were to find `39 something` under C1, what is the probability that there are none of them from P1 and P3 and 20 and 19 of them from P2 and P4? This I suppose would be far from random distribution and hence a very significant p-value. Did I misunderstand something here?
Answer: There's no reason you can't apply Fisher's exact test to this problem. Or you could use a standard chi-squared test for independence, as the expected cell counts aren't that small.
Neither approach will answer the question "what is the probability that these 39 times of seeing something is unevenly distributed between these 4 plants" though. That would require a fully Bayesian analysis.
Comment: Why is a Bayesian analysis called for here?  This is phrased as a straightforward probability question.
Comment: Arun, my understanding is that Fisher's exact test is not limited to 2x2 tables, even if the original example was of that size. See for instance, C.R. Mehta and N.R. Patel(1986) Algorithm 643. FEXACT: A FORTRAN Subroutine for Fisher's Exact Test on Unordered r x c Contingency Tables, ACM Trans. Math. Soft. vol. 12, p. 154-161.
Comment: onestop, Thanks for your answer, however doesn't fisher's exact test answer the same question for a 2*2 table? or am I wrong even there? From the wiki page, under example, this is the question they ask: "what is the probability that 9 of them would be among the 12 women, and only 1 from among the 12 men"?
Comment: whuber, I thought so as well.


robust pylint disable for an option recently introduced

Question: We have several versions of pylint in various stages of our CI system (for good reasons: we want to test that our code works across a range of package versions).
Now, an option import-outside-toplevel was introduced as per pylint=2.4.0 (according to the changelog).
How do we disable that pylint error in a robust way (or conditional on pylint>=2.4.0)?
I have tried:

# pylint: disable=import-outside-toplevel
# pylint: disable=C0415
No disable.

In case 1 and 2, running pylint version 2.4.3 (on a CI stage aligned with anaconda=2019.03) causes E0012: Bad option value.  In case 3, running pylint version 2.4.2 (on a CI stage aligned with anaconda=2019.10) causes C0415: Import outside toplevel.
Answer: For now, I am disabling the whole 'C' category for just the scope (in my case, a single line):
def blah(...):
    import foo.bar  # pylint: disable=C

That works across pylint 2.3 to 2.5, although it isn't as specific as I would like.


Defining a line

Question: I've read this:
To describe a line, we needed a point $b$ and a vector $v$ along the line. We could also start with two points $b$ and $a$ and take $v=a−b$.
In the first sentence, why do we need a point $b$ and a vector $v$ along the line in order to define it? Isn't a vector $v$ along it just enough? I see we don't need point $b$ with it . Am I right?
Comment: @ZaKh Please note that a vector, even though sometimes thaught to can start at any point in space, always *only* describes a direction and length, never a starting point, i.e. can be thought of as starting *always* in the origin. You can see this in the notation: where does $(1,2,3)^\top$ start? If a vector would contain the information of a starting point, then one vector would be enough to define a line. But as it does not, you need another point $b$ to fix the starting point as coffeemath explained.
Comment: If you change the start point $b$ you get another line which will be parallel but not typically the same line.
Comment: also have a look [at this post](https://math.stackexchange.com/questions/1420269)
Comment: Ah :) you're right . Thank you . You should have better posted your comment as an answer
Comment: @GCab thank you , but I will comment under your post :)
Answer: You're correct that each vector $v \in \mathbb{R}^3$ defines a line $$\{av : a \in \mathbb{R}\}.$$ But such lines always go through the origin. Thankfully, we can generalize. If we have a point $p$ and a vector $v$, there's a corresponding line $$\{p+av : a \in \mathbb{R}\},$$ and such lines needn't go through the origin. Indeed, every line can be described in the latter form.
Answer: A regular old vector simply just says "go right by x, up by y, and forwards by z". It's kind of like the gradient in y = mx + c, and is not to be confused with a position vector, which says "go from the origin to this point in a straight line".
We often combine a vector with a variable coefficient, such as $ t(1, 3, 5) $ in order to make it extend infinitely in both directions. However, it still has no set point. It's like a ruler , with a physically fixed angle of course, that you can place anywhere on a piece of paper to draw a line.
However, it has no definite equation until we introduce a point to create a vector equation of a line, where we say "it goes through this point, with this gradient". The same goes for y = mx + c when you have both a co-ordinate and the gradient.
One thing to note is that many fixed positions will create the same line, since the line extends infinitely, including negatively. If our equation is: $ r $1$ = (1, 2, 3) + t(2, 5, 10)$, this is equal to $ r $1$ = (3, 7, 13) + t(2, 5, 10)$. If our variable coefficient was to have a value, the specific fixed position would matter.

Defining a line


Is there an exchange lemma for permutation groups?

Question: I have a set $P$ of permutations of size $s := |P|$.
By repeated application of those permutations I can generate $m$ permutations(or reach $m$ states?) that constitute the set $M$.
I am unable to generate the same $m$ permutations with any proper subset of $P$.
But I wonder if there is a subset $X$ of $M$ with $|x| < s$ that can generate $M$.
If we were talking about a vector space I could use the Steinitz exchange lemma to proof that there can be no base spanning the wholes space smaller than an existing base with linearly independent vectors.
But things are quite different with a permutation group, e.g. the permutations do not commute.
How can I prove that my "group base" is minimal?
Comment: There is no exchange lemma for generating sets of permulation groups. Minimal generating sets need not have the same cardinality. So proving minimality requires arguments on a case by case basis. There are no universally applicable general methods. If you have a particular example you are wondering about you can ask a specific question.
Comment: @EthanBolker thanks! I've made a specific example: https://math.stackexchange.com/q/3320160/180934
Answer: Let $n\ge4$. The symmetric group $S_n$ is generated by the $(n-1)$-element set $P=\{(1\ 2),(1\ 3),\dots,(1\ n)\}$ and by no proper subset of $P$, but the $2$-element set $X=\{(1\ 2),(1\ 2\ 3\ \dots n)\}$ also generates $S_n$.


How to set value of transform property using javascript variable

Question: I found a similar answer to this on here, but it doesn't work for me. I am trying to make a scrolling single page layout, but by using css3 animations instead of jquery animate. What i'm shooting for is taking the variable set as the position of the hash and passing it into the transformX(). Here is what i have so far.
<!DOCTYPE html>

    <meta charset="utf-8">
    <link rel="stylesheet" href="css/style.css" type="text/css">

home

work

about

contact

Relevant CSS:
html,body {
  height:100%;
  text-align:center;
  transition:all 1s ease-in-out;
    -webkit-transition:all 1s ease-in-out;
    -moz-transition:all 1s ease-in-out;
    -o-transition:all 1s ease-in-out;

}

and Relevant Javascript:
$(".nav-li > a").click(function(event){
         event.preventDefault();
         //calculate destination place
         var dest;
         if($(this.hash).offset().top > $(document).height()-$(window).height()){
              dest=$(document).height()-$(window).height();
         }else{
              dest=$(this.hash).offset().top;
         }

         //go to destination
         $('body').css('transform', 'translateY('+ dest +')');
                      //('-webkit-transform', 'translateY('+ dest +')');
                      //('-ms-transform', 'translateY('+ dest +')');
                      //('-moz-transform', 'translateY('+ dest +')');
                      //('-o-transform', 'translateY('+ dest +')');
         console.log(dest)
     });

I am definitely getting the right value for 'dest' as you can see with console.log(dest). Is this not possible?
Comment: You can also pass an object into the css method, so that way you don't have to create a new function for every single browser prefix.
Answer: Fiddle Example
Change your code from
$('body').css('transform', 'translateY(' + dest + ')');
to
$('body').css('transform', 'translateY(-' + dest + 'px)');
You need to specify a unit for translation. the -ve sign is to move the body upwards rather than downwards which is what you would expect.
Comment: I have a same problem and you answer unfortunately didn't help.
any idea?


Y-Embedding of a Scheme

Question: Let $f:X \to Y$ a morphism of schemes and $\mathcal{F}$ a $\mathcal{O}_Y$ module. Futhermore we have a embedding $X \subset Proj(Sym^{\cdot} (\mathcal{F}))$.
My question is what does it mean if $X \subset Proj(Sym^{\cdot} (\mathcal{F}))$ is a "$Y$-embedding"? Therefore what extra structure induces the "$Y$-blabla?
Answer: This means that $X \subset Proj(Sym^{\cdot} (\mathcal{F})$ is actually a commutative triangle (since both schemes come with a fixed map to $Y$). The extra structure comes from the fact that the relevant sheaves are $\mathcal O_Y$-modules.

Y-Embedding of a Scheme


When to use HC1 vs HC2 errors in estimating heteroskedasticity robust standard errors?

Question: Suppose I have data $Y$ regressed against $X$, where $Y$ is the level of health for an individual (from 1 to 10), and $X$ is the whether or no the individual is above 50 years of age. If I wanted to estimate the difference in mean level of health in individuals above or equal to 50, and under 50 — and wanted standard errors, should I use

Regular OLS standard errors
HC1 errors
HC2 errors

?
Thanks
Comment: How many observations do you have?
Comment: @dimitriy I have around 3000 observations
Answer: With a bounded outcome like that and a linear regression model, you will have heteroskedastic errors. The logic is similar to why you get heteroskedasticity with a linear probability model (LPM). That knocks out (1).
There is no theorem with a guarantee (yet), but with $\frac{k}{n}$ small, HC1 SEs tend to be smaller than HC2. Here $k=2$ and $n=3,000$ which favors HC1. But I suspect that the choice may not matter too much with this sample size and number of covariates.
You can always do a simulation to confirm.
Comment: @Dave Yes and edited.
Comment: @user321627 It can be a function of x, but does not have to be. There are many ways to be unconstant. It can be a function of some omitted z, uncorrelated with x. You can also have a homoskedastic DGP (say a standard ordered probit with homoskedastic normal errors), but using OLS induces misspecification and heteroskedastic errors. But you can think of it as a function of both y and x here since the residual at y=k will depend on whether x=0 or x=1. In fact, in this simple model, each value of y will have 2 distinct residuals.
Comment: LPM being a linear probability model?
Comment: What is the connection between the bounded outcome and hetereoskedastic errors?
Comment: @user321627 Suppose $y=8$ on an 1-10 scale. If there is a positive error, it can only be +2 at the most but down to -7 in the other direction. These limits depend on the value of y, so the error variance cannot be constant.
Comment: @dimitriy Thank you for this, what confuses me is that I had always assumed hetereoskedasticity meant $Var(\epsilon_i)$ was some function of $x_i$. But here, is the fact $Var(\epsilon_i)$ is a function of $y_i$ also imply hetereoskedasticity? In other words, a function of $y$ vs. a function of $x$?


What is this 4 bar part of music called?

Question: In the song Amie by Pure Prairie League there is a repeated section of muisc that is about 4 bars long(or 2 depending on how you count it). It occurs between every section of music except near the end with it is left out(I assume to keep the momentum going and because it is not as crucial).
It occurs right before the verse(or the first 4 bars of the verse before the lyrics come in).
About the best thing I can think to call it seems to be a pre-verse but this does not feel quite right. I know most will probably want to lump it in with the verse but this doesn't feel quite right either(to general).
Any ideas?
Comment: A [*bridge*](http://en.wikipedia.org/wiki/Bridge_%28music%29)  maybe?
Comment: @percusse No, a bridge is usually defined as a complete contrasting section of music... I'm not sure why as it doesn't seem to be a useful definition. It does seem to "bridge" the verse with what comes before it and I'd love to use that term if it didn't have a standard meaning already.  Another term is possibly "linker" but I'd prefer something else and something more standardized.
Comment: Bridge can mean a lot of things.  Originally it actually WAS used to indicate exactly the kind of section we're discussing.  The way we use it today, usually means a much larger section of music, either a B or C theme that may happen once every verse or just once in a tune.
Comment: @ecline6 That maybe or may not be true but unfortunately the common terminology is that it is a complete section of music. I wouldn't mind using the term cause it makes sense to me but it could cause more confusion than not...
Answer: I would call it an interlude: a short instrumental section to be played between two other sections.
Comment: That doesn't seem quite right. I tend to think of interludes as being much longer and more involved. This 2 bar part seems to be integral to the verse. It is a sort of pre-verse but was hoping for a better name. I have used pre-verse in the meantime.
Comment: An interlude can be short or long.
Answer: It's called a transition.  Typically they are just a few bars long and don't introduce any new themes or material that would be developed.  You can think of them as a way to constructively waste some time in a song because starting the next section right away feels rushed or abrupt.
Comment: Yes, transition seems like a good term but also seems a bit too general. In this case the transition is always before the verse, as if it is attached to it. Maybe the term transitional interlude or transitional bridge would be appropriate?
Comment: @AbstractDissonance  From the dictionary...  Transition
a. A modulation, especially a brief one.
b. A passage connecting two themes or sections.
Comment: Yes, but again, it's too general for what I'm asking. From some site "An interlude is a short sequence that often re-uses themes and feel from another section of the song. Literally an interlude provides, when needed, breathing space between sections of the song. Interlude sections are almost always instrumental as they literally provide space for a singer to breathe." Which, if it was standard, would be a good term for what I am talking about.
Comment: But I generally think of an interlude as something longer as from VT's dict: "Any piece of music played or sung between the movements of a larger composition."
Comment: From VT's dict, Transition - "Passing out of one key into another; also, a passage that takes the composition from one key into another."
Comment: VT's dict: Bridge - "Transitional passage connecting two sections of a composition." Which would be a perfect definition if some idiot didn't call it a complete section of music... I don't know how that term got refined so easily ;/
Comment: (Note that bridge is more specific than transition... which is why I said transition was too general)
Comment: @AbstractDissonance  If I were analyzing this particular song though, I would just call it part of of the verse or A section, since it is always part of it.  It also happens at the beginning of the song too, which suggests it's not a bridge or a transition at all.
Answer: That sounds like a turnaround, which is a short transitional passage that leads back to (i.e. 'turns around' into) the start of a section — often to the verse, or the start of the piece.
The term originated in jazz and blues, but I've seen it used for many other genres such as gospel, rock, and hymn singing; I think it can apply to any form with repeated sections.
It often takes the form of a 2- or 4-bar chord progression, sometimes with a short melody, to add interest in between verses. It's particularly important when the previous section ends with a different chord (or even key), and so the turnaround can lead naturally into the new chord without a jarring change. But even when that's not the case, it provides a short breather. And in choral/group/congregational singing, it can indicate exactly when the singers should come in again.
(There are many refs online…)


Learn music with odd rhythms

Question: I've always had problems with tuplets (3/2, 4/3, etc), until I was taught this nifty trick:

subdivide the total duration (4 quartuplets, 3 triplets, etc) by the least common multiple (12, for 4/3)
place the tuplets along the appropriate subdivisions (4/3: quartuplets = 12/4 = every 3 subdivisions, triplets = 12/3 = every 4 subdivisions)
tap out, and learn, the rhythm

For example, for 4/3:
<code>|           |           |           |           |
o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o--o
o---o---o---o---o---o---o---o---o---o---o---o---o
|           |           |           |           |
</code>
This works fine for simple rhythms (3/2, 3/2, 3/4, 4/3, 2/5, etc), but Leo Ornstein's 4th sonata (or Cowel's Fabric) is too complicated:

Rhythms shift to quickly (4/7 -> 2/4 -> 2/6 -> 4/2.5 -> 3/2.5 -> 8/5 -> 12/10)
Rhythms are too plentiful and exotic to be learned using the above method

Right now I'm just guessing when to play the notes by their positions on page. Unfortunately, there's just something about this approach that hinders (muscle) memorization and practice. For example, while I have already learned and am consistently playing - at a slower tempo - sections of equal or greater technically difficulty with straightforward (or simple, 3/2, 4/3, 5/2) rhythm, I am still stumbling through sections with unusual rhythms, despite having practiced them more.
In situations such as these, with much more practice than I'd prefer, over time I become sufficiently familiar these poly-rhythmic sections that eventually my hands intuitively, subconsciously converge towards a "good-enough" estimation of the actual rhythm. Then, I learn the section "normally", as if were a mono-rhythmic passage. So you see, this "two-pass" learning procedure is very inefficient. Eventually, with sufficient mastery, I can adjust the speed/rhythms of each hand independently.
I've been told, "just practice each hand separately, then put them together". First, I've never been able to, or just never understood, this. Of course it helps to practice each hand independently, but I've never had a piece "magically" come together with both hands, after each has achieved independent fluidity. Perhaps this is because I'm a notorious sheet/sight reader - I'm always looking at the page, never my hands - and I (almost) never memorize music. Secondly, even if I was able to "put them together", the rhythms are just to exotic to practice independently in the first place. As I mentioned near the beginning, I'm used to practicing rhythms against each other - for example, triplets against the steady beat of quartuplets.
Anyway, I'm curious about your techniques for efficiently & quickly learning difficult poly-rhythmic passages, such as from Ornstein's 4th sonata (in particular, PDF pp 6-7 or numbered pp 4-5, starting with "Tempo I°").
P.S. If you do recommend "practicing each hand independently", please calibrate to my shortcomings and experience with that method, as I've described.
Edit:
I've settled on practicing each hand separately, with a metronome, for measures 45 - 52 (starting with Tempo I). The hands are sufficiently independent and even-rhythmed that I think I do a decent job when practicing them together. Since the left hand is arpeggiated with a strong tempo while the right hand plays a simple, repetitive, and catchy melody, I find it simpler to just "fit/squish" the few single-beat occurrences of 3/7 or 4/7 into the overall beat. For longer repetitions of the more complicated rhythms (more than just a beat) I would practice as suggested by Scott Wallace. I'm impressed that he's already on 7/4 - I've just mastered 4/3. However, I don't think anyone realizes how chaotic measures 54 and 56 are - how dynamic the poly-rhythms are. I've inscribed those measures in Denemo to produce a training PDF. Each measure is preceded by a duplicate identical in all respects, except the notes have been normalized per-staff (much as in drum notation). I've then recorded the resulting MIDI using the Salamander Grand Piano V3 soundfont, at 15bpm and 50bpm (published tempo is 76bpm). Some friends commented, "so basically, it's a play-whatever-the-#$@&%*! you want measure". To contrast: the least-common-multiple-method that Scott Wallace and I mention would require dividing each measure into 120(!!) subdivisions (60 excluding the 16th-triplets) to ensure that each note falls evenly on an interval. Anyway, I plan on leaving the question unanswered for a while longer - I was hoping to generate a wider range of answers.
Edit #2:
I've inscribed the full first movement into MuseScore. It is available for online listening at
Ornstein, Leo: Piano Sonata No.4, SO 360: I. In comparison, notice how - especially in measures 54 and 56 - the official Poon Hill Press edition on IMSLP actually places the noteheads incorrectly or even out-of-order for the more involved poly-rhythmic sections. It goes to show how little you can depend on note positions on the page.
Answer: The way I approach polyrhythms is this: I break them down much as you do, in terms of their lowest common denominator, but I try to memorize the sound of the pattern right away and not rely on seeing it graphically.  At UC we learned an example for two against three:  "FARMS in BERkeley".  I then practice it in many different ways- tapping the two parts with my hands, or hands against feet (I spend a lot of time walking to work this way- probably looks pretty weird) or voice, and then I do it with the fingers, also counting up or down on them, preferably in some yet different number of beats.  And then alternating hands.  And so forth.
All of this happens before I try playing my double harp in this rhythm.  This ensures that I have a polyrhythm really well internalized before worrying about melodies.  Currently, I'm working on seven against four: my left hand plays seven, counting up and down to eight on the fingers, and my right hand plays four, counting up to five.  It's fun, and when I get it down, I'll try making some music with it.
But what I do is relatively simple- no polyrhythms with both factors over four, and no complex shifts such as you describe.  However, it might not be disadvantageous to get away from the printed page for a bit, and making sure you have the rhythms flexibly ingrained before tackling the melodies.
cheers from rainy Vienna, Scott
Comment: Readers outside the San Francisco Bay Area may not be familiar with the "FARMS in BERkeley" reference and the pacing of it. This was the closing line from the radio commercials for the Berkeley Farms dairy. (Or still is? I haven't heard it in a long time.) Berkeley, of course, is pronounced with two syllables, not three, and there's also a "moo" at the end of the line. So if you count out equal beats it goes "FARMS? (tap) (tap) in BERK-ley? (tap) (tap) MOO..." where the "moo" is about three beats, trailing off at the end, done in your best cow impersonation. Certainly a memorable line!
Comment: Yes, good answer. Getting your ear familiar with the pattern as much as possible helps a lot, I think. This site http://bouncemetronome.com/video-resources/polyrhythms may be of some help. Despite promoting a commercial product it offers some free demonstrations with some quite complex polyrhythms.
Comment: Good point about getting the rhythm down before tackling the melodies.
Comment: @joseem- yes, this is very much along the lines of what I do, but without looking at anything.  Definitely worth checking out- thanks.
Comment: After watching a couple more of these polyrhythm clips at joseem's link above, I can't help but wonder if any human being can halfway accurately do, say, 14 against 15.  But some people can do amazing things.
Comment: Check this out: https://youtu.be/lzkOFJMI5i8 and download the app too
Comment: @ScottWallace - do you find this least-common-multiple subdivision method worthwhile for rhythms lasting only a beat? Especially in arpeggiated sections with a strong tempo, it seems that practicing to a tempo (ie, "fit/squish" all the notes into a beat while the accompanying hand plays a simple, "catchy" melody) is more effective. I've updated my question to reflect this.
Comment: @user19087 - no, I suspect for rhythms lasting only a beat your method is probably better.  But I can't say for sure since I've mostly only worked on patterns lasting for many bars.  Also, what I do is far less complex rhythmically than what you describe: I tend to stick to the same note values in each hand.  It sounds as though you are on the right track- good luck!
Answer: You'd need to combine several strategies. Practising polyrhythms as such (away from keybord) until that's easy would be a good start. Break up the score, practise segments of two or three beats in isolation, first each hand separately, then together. Use a metronome and get a feeling for how to fit the required notes into the available time.
The midi rendering is of course much stiffer than the composer likely intended, so when you begin to master it, you can start thinking of adding rubato to taste.
Answer:
I've settled on practicing each hand separately, with a metronome, for
  measures 45 - 52 (starting with Tempo I). The hands are sufficiently
  independent and even-rhythmed that I think I do a decent job when
  practicing them together. Since the left hand is arpeggiated with a
  strong tempo while the right hand plays a simple, repetitive, and
  catchy melody, I find it simpler to just "fit/squish" the few
  single-beat occurrences of 3/7 or 4/7 into the overall beat.

You got there. With a very few exceptions (e.g. Steve Reich's use of "phasing" with slowly shifting rhythms) it is wrong to be too literal or mathematical about this. Humans musicians don't usually play even "simple" rhythms with a mathematically accurate tempo, and if you get a computer to play them that way the result usually doesn't sound much like "music". In fact notation software like Finale has a "human playback" option with several different controls of how far to deviate from "the exact written notation".
The root of the problem is that when you started learning the piano, you spent a long time learning how to synchronize your two hands (and the pedals) in mathematically simple rhythms. Now, you have to unlearn how to do that when you don't want to.

Learn music with odd rhythms


Analogue of Fermat's Theorem

Question: The question is "Establish an analogue of Fermat's Little Theorem for the ring $\mathbb{Z} [\sqrt{3}]$. I know you begin by letting $\alpha \in \mathbb{Z} [\sqrt{3}]$ so there exists integers $a$ and $b$ s.t $\alpha ^{p}=(a+b\sqrt3)^{p}$ where p is prime. Then I was told you need to use a binomial expansion and Fermat's Little Theorem to get $\alpha ^{p} =a+b(\sqrt3)^{p}$ mod $p$ but I am unsure how you do this. Then I was told you can use Euler's criterion and the definition of the Legendre symbol for $(\frac{3}{p})$ to establish an analogue but again i am unsure how you do this.
Answer: As you said, if $\alpha \in \mathbb{Z}[\sqrt3],$ there exists integers $a$ and $b$ such that $\alpha = a+b\sqrt3$.
Now, we have to show $\alpha^p = a+b(\sqrt3)^p \pmod p$.
Raise $p$ power to the both sides of $\alpha = a+b\sqrt3$ to get:
$\alpha^p = (a+b\sqrt3)^p $.
$=a^p+ p a^{p-1}\sqrt3b+\frac{p(p-1) a^{p-2}}{2}3b^2 + \cdots + p a\sqrt3^{p-1}b^{p-1}+ b^p\sqrt3^p$
Using Wilson theorem we have $a^p =a \pmod p$ and $b^p =b \pmod p.$
Also, since we are reducing mod $p$, all the terms except the first and last will become zero.
Therefore $\alpha^p = a+0+b(\sqrt3)^p = a+b(\sqrt3)^p.$

Analogue of Fermat’s Theorem


create drupal 7 webform programmatically?

Question: I have already created a webform and I need to fill it programatically.
how can I create webform ? Can i create it like node creation:
$node = new stdClass()
$node->type = 'webform'
$node->webform['components'][1]['value'] =  'sss'

Answer: See code below:
function _add_webform_components($node) {
  $components = array(
    0 => array(
      'name' => 'First name',
      'form_key' => 'first_name',
      'type' => 'textfield',
      'mandatory' => 1,
      'weight' => 1,
      'pid' => 0
    ),
    1 => array(
      'name' => 'Name',
      'form_key' => 'name',
      'type' => 'textfield',
      'mandatory' => 1,
      'weight' => 2,
      'pid' => 0
    ),
    ... and so on

  );

  webform_ensure_record($node);
  foreach($components as $component) {
    $component['nid'] = $node->nid;
    $component['extra']['title_display'] = 'inline';
    $node->webform['components'][] = $component;
    webform_component_insert($component);
  }
  $email = array(
    'nid' => $node->nid,
    'email' => 'email@example.com',
    'subject' => 'default',
    'from_name' => 'default',
    'from_address' => 'default',
    'template' => 'default',
    'excluded_components' => array(),
  );
  webform_email_insert($email);
}

Comment: thax very much mr.lenni, my question now is how i can migrate data was interred in drupal 6 webform form to drupal 7 webform? i can access the drupal 6 database and get all the data, but my problem is i cant add the old data to drupal 7 webform and submit it programatically? i hope that my question is clear!
Comment: @genaro, if this is your requirement, edit the question accordingly.
Comment: This is working splendidly for me in Drupal 7. Since I am using it within a script that generates new nodes I had to move the call to ``_add_webform_components()`` after ``node_save($node)`` to avoid errors.
Comment: This looks like it will come in very handy for me, is there a specific function that will allow me to change the settings of the webform? ie, redirect, confirmation message etc?
Comment: Getting issue "Integrity constraint violation: 1048 Column 'machine_name' cannot be null" and I found one more key need to add in components array
      'machine_name' => $node->title . '__first_name'
Answer: Maybe it is easier to understand with this example:
function hook_node_insert($node) {
  if ($node->type == 'your_content_type') {
    webform_ensure_record($node);
    $components = _my_function_webform_components();
    foreach($components as $component) {
      $component['nid'] = $node->nid;
      $component['extra']['title_display'] = 'inline';
      $node->webform['components'][] = $component;
      webform_component_insert($component);
    }
    $email = array(
      'nid' => $node->nid,
      'email' => 'email@example.com',
      'subject' => 'default',
      'from_name' => 'default',
      'from_address' => 'default',
      'template' => 'default',
      'excluded_components' => array(),
    );
    webform_email_insert($email);
  }
}

function _my_function_webform_components() {
  $components = array(
    0 => array(
      'name' => 'Name',
      'form_key' => 'name',
      'type' => 'textfield',
      'mandatory' => 1,
      'width' => '40',
      'maxlength' => '75',
      'weight' => 1,
      'pid' => 0
    ),
    1 => array(
      'name' => 'Age',
      'form_key' => 'age',
      'type' => 'number',
      'mandatory' => 1,
      'max' => '99',
      'excludezero' => 1,
      'weight' => 2,
      'pid' => 0
    ),
    ...
  );

  return $components;

}

Answer: You can make use of drupal_form_submit  I didn't tried it.
Anyway this may can help you.

This function allows you to supply values for form elements and submit
  a form for processing.

The idea is to find the form_id check for the form fields and
// register a new user
$form_state = array();
$form_state['values']['xxx'] = 'yyyyy';
drupal_form_submit('xxx', $form_state);

Give a try and please paste the code here if you succeed.


How does multi field mapping work in Elastic Search

Question: I want to support both text search (match query) as well as exact match (term query) on a single field in my elasticsearch index.
Following is the mapping that I have created:
PUT multi_mapping_test/_mapping
{
  "properties": {
    "name": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword"
        }
      }
    }
  }
}

However, the term query is not behaving as I am expecting it to (may be understanding of it is wrong).
For example, here are couple of sample documents indexed:
POST multi_mapping_test/_doc
{
  "name": "abc llc"
}

POST multi_mapping_test/_doc
{
  "name": "def llc"
}

Following term query yields no results:
GET multi_mapping_test/_search
{
  "query": {
    "term": {
      "name": {
        "value": "abc llc"
      }
    }
  }
}

Am I doing anything wrong or is my understanding of exact matches with term query incorrect?
P.S. The term query works fine when I put mapping for only keyword type.
Answer: Term query: Returns documents that contain an exact term in a provided field.
When you're searching for exact match you should use keyword field types. Like the following:
GET multi_mapping_test/_search
{
  "query": {
    "term": {
      "name.keyword": {
        "value": "abc llc"
      }
    }
  }
}

In addition, You can use bool query for both text search (match query) and exact match (term query) in your elasticsearch index.
GET multi_mapping_test/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": "abc llc"
          }
        },
        {
          "term": {
            "name.keyword": {
              "value": "abc llc"
            }
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

Note: You can also use the match_bool_prefix query if you need to autocomplete the feature.
Details: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-bool-prefix-query.html

"abc llc" _score will be higher than "def llc" because it matches both match and term queries.


Oracle: Overwrite values in a column with the longest string

Question: I'm running into a problem.
Say, I have columns called "C1, C2, C3...." in a table. I'd like to use the longest string in C1 to replace every other cells in C1 column without disturbing other columns.
I tired several ways but I cannot get my Oracle code run. Could someone please show me a sample code to do this problem? I typed my question using a cellphone so I apologize for not showing you my code. But I think my description is fine... Thank you!
Answer: I would use window functions.  Oracle has a very convenient functionality with keep:
select max(col1) keep (dense_rank first order by len(col1) desc) over () as col1,
       col2, col3, . . .
from t;

You can incorporate this into an update:
update t
    set col1 = (select select max(col1) keep (dense_rank first order by len(col1) desc) over () as col1
                from t
               );

Answer: For example:
SQL> select * from test;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> update test set
  2    dname = (select max(dname)       --> MAX fixes TOO-MANY-ROWS because ACCOUNTING
  3             from test               --  and OPERATIONS have same length
  4             where length(dname) = (select max(length(dname))
  5                                    from test
  6                                   )
  7            );

4 rows updated.

SQL> select * from test;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 OPERATIONS     NEW YORK
        20 OPERATIONS     DALLAS
        30 OPERATIONS     CHICAGO
        40 OPERATIONS     BOSTON

SQL>

[EDIT, GROUP BY]
Another example is based on a different table, which reflects what you described in a comment. The DEPTNO (department number) is used to "group" employees, and I'm going to update the JOB column value to the longest job name within that department.
Query is similar to the previous one; it just joins appropriate columns (DEPTNO) throughout code.
Sample data:
SQL> select * from test order by deptno, ename;

    DEPTNO ENAME      JOB
---------- ---------- ---------
        10 CLARK      MANAGER
           KING       PRESIDENT  --> the longest in DEPTNO = 10
           MILLER     CLERK

        20 ADAMS      CLERK
           FORD       ANALYST
           JONES      MANAGER    --> as long as ANALYST, but MAX(JOB) will return this value
           SCOTT      ANALYST
           SMITH      CLERK

        30 ALLEN      SALESMAN   --> the longest in DEPTNO = 30
           BLAKE      MANAGER
           JAMES      CLERK
           MARTIN     SALESMAN
           TURNER     SALESMAN
           WARD       SALESMAN

Update and the result:
SQL> update test t set
  2    t.job = (select max(t1.job)
  3             from test t1
  4             where t1.deptno = t.deptno
  5               and length(t1.job) = (select max(length(t2.job))
  6                                     from test t2
  7                                     where t2.deptno = t1.deptno
  8                                    )
  9            );

14 rows updated.

SQL> select * from test order by deptno, ename;

    DEPTNO ENAME      JOB
---------- ---------- ---------
        10 CLARK      PRESIDENT
           KING       PRESIDENT
           MILLER     PRESIDENT

        20 ADAMS      MANAGER
           FORD       MANAGER
           JONES      MANAGER
           SCOTT      MANAGER
           SMITH      MANAGER

        30 ALLEN      SALESMAN
           BLAKE      SALESMAN
           JAMES      SALESMAN
           MARTIN     SALESMAN
           TURNER     SALESMAN
           WARD       SALESMAN

Comment: Thank you so much!!!! But I forgot to add one condition that some values in C1 have the same value in C2. And I actually need to find the "local longest" string and overwrite other values in C1 within each C2 group...Could you please further give an example?
Comment: You're welcome. I edited my message by adding another example; have a look, please.


To prove: $ [K : \mathbb{Q}] = 2 \ \Longrightarrow \ \exists \zeta \text{ primitive root of unity}, \ \mathbb{Q}(\zeta) \ \supseteq \ K $

Question: I have to show that the following statement is true:
Let $K$ Be a field extending $\mathbb{Q}$ such that $[K: \mathbb{Q}] \ = \ 2$. Then there is a root of unity $\zeta$ such that $K \subseteq \mathbb{Q}(\zeta)$.

What I did
Since $2$ is prime, there can't be a field $L$ such that
$L \supset K \supset \mathbb{Q}$. That means that
$ K \ = \ K(\alpha) \ \cong \ \mathbb{Q}[X] /(X^2 +aX +b) $
for some $a,b \in \mathbb{Q}$. Now I have to show that one always can find a number $n \in \mathbb{N}$, and $a_0, a_1, \cdots , a_n \in \mathbb{Q}$ such that
$$
\alpha = a_0 + a_1\zeta + a_2\zeta^2 + \cdots + a_n-1\zeta^{n-1}
$$
But I don't really know how.

Try to answer my own question using the hint
Since the roots of $X^2 +aX+b$ are $\frac{\pm\sqrt{a^2-4b}-a}{2}$, we only have to add $\sqrt{a^2-4b}$ to get the field $K$. Now we replace $m = a^2-4b$, and we split $m$ in prime numbers.
$$
m \ = \ p_1^{k_1} \cdots p_t^{k_n}
 \quad \text{ so } \quad
\sqrt{m} \ = \ \sqrt{p_1}^{k_1} \cdots \sqrt{p_t}^{k_n}
$$
Now I write
$\gamma_p
\ := \
\sum_{a=0}^{p-1} \left( \frac{a}{p}\right) \zeta_p^a
$.
We know that
$
\gamma_p^2
\ = \
p \left( \frac{-1}{p}\right)
$,
thus
$
\gamma_p \ = \ \pm \sqrt{\pm p}
$.
Now we see that
$$
\sqrt{m} \ = \ \pm g_{p_1}^{k_1}\cdots g_{p_t}^{k_t}
\ \in \ \mathbb{Q}(\zeta_{p_1}, \cdots \zeta_{p_t})
$$
We know that $\zeta_{p_1} \cdot \zeta_{p_2} \cdots \zeta_{p_t}$ is a primitive root of unity as well. If we link up all this knowledge we have:
$$
\mathbb{Q}(\alpha) \ = \ \mathbb{Q}(\sqrt{m}) \ = \
\mathbb{Q}(\pm g_{p_1}^{k_1}\cdots g_{p_t}^{k_t} ) \ = \ \mathbb{Q}(\zeta_{p_1}, \cdots \zeta_{p_t})
\ = \ \mathbb{Q}(\zeta_{p_1} \cdot \zeta_{p_2} \cdots \zeta_{p_t})
$$
Which means that the product of those primitive roots is the root of unity we had to find.
Comment: Do you mean $Q \subset L \subset K$?
Comment: For future reference: this is the first case of a very general, beautiful, and difficult theorem that says that if the Galois group of $K$ over the rationals is abelian, then $K$ is contained in a cyclotomic extension of the rationals.
Comment: And that is the [Kronecker–Weber theorem](https://en.wikipedia.org/wiki/Kronecker%E2%80%93Weber_theorem).
Comment: Here's a hint to step in a slightly different direction: can you show that you can take $\alpha$ to be $\sqrt{N}$ for some $N\in\Bbb{Z}$?
Comment: Related: https://math.stackexchange.com/questions/475370, https://math.stackexchange.com/questions/2004676, https://math.stackexchange.com/questions/282757, https://math.stackexchange.com/questions/1616900, https://math.stackexchange.com/questions/31485
Answer: Hint: As said in the comments, every quadratic extension of $\mathbb{Q}$ is of the form $\mathbb{Q}(\sqrt{\alpha})$ with $\alpha\in\mathbb{Z}$. Try proving the assertion first for $K=\mathbb{Q}(\sqrt{\pm p})$ with $p$ prime. For that, consider the Gauss sum $\gamma = \displaystyle\sum_{a=0}^{p-1} \left(\dfrac{a}{p}\right)\zeta_p^a$ where $\zeta_p$ is a primitive $p$-th root of unity and $\left(\dfrac{a}{p}\right)$ is the Legendre symbol. Prove that $\gamma^2 = p \left(\dfrac{-1}{p}\right)$. Prove that $\gamma$ is fixed by the only  subgroup of $\mathrm{Gal}(\mathbb{Q}(\zeta_p)/\mathbb{Q})$ of index $2$.
Comment: Sorry, $\sum_{a=0}^{p-1}\zeta_p^{a^2}$.
Comment: One can also work with the sum $\sum_{a=0}^{p-1}\zeta_p^a$.
Comment: That sum is zero. Maybe you meant something else?
Comment: @Nacho Darago, thank you for your hint! I have tried to solve the assignment now, I hope that you can check whether I understood everything.
Comment: Seems right. When you say $\mathbb{Q}(\pm g_{p_1}^{k_1}\ldots g_{p_t}^{k_t}) = Q(\zeta_{p_1},\ldots , \zeta_{p_t})$ you mean $\mathbb{Q}(\pm g_{p_1}^{k_1}\ldots g_{p_t}^{k_t}) \subseteq Q(\zeta_{p_1},\ldots , \zeta_{p_t})$.
Also, you should still prove that $\gamma_p^2 = \left(\dfrac{-1}{p}\right) p$. However, all the ideas seem fine.


copyToRealmOrUpdate not working

Question: I would like to update an realm object, but I haven't had success. I tried different ways, but I'm still getting the same exception.

First, I create a plant and then I search it in order to be updated. This works. But, when I try to update the plant with its new name, I received the exception related to the primary key constraint. So, is it supposed that the method copyToRealmOrUpdate will be used the key for search the object?
private void updatePlantRealm() {

    RealmConfiguration config = new RealmConfiguration.Builder(this)
            .name("garden.realm")
            .build();

    PlantRealmRepository repository = new PlantRealmRepository(config);

    Plant plant = new Plant();
    plant.setId("234");
    plant.setName("test");
    plant.setSize(30);
    plant.setGardenId("1452345");

    repository.add(plant);

    PlantByIdSpecification spec = new PlantByIdSpecification(plant.getId());

    repository.query(spec).subscribe(plants -> {
                Plant p = plants.get(0);
                p.setName("name");
                repository.update(p);
            }
    );

    spec = new PlantByIdSpecification(plant.getId());

    repository.query(spec).subscribe(plants -> {
                Plant p = plants.get(0);
                Assert.assertEquals(p.getName(), "name");
            }
    );
}

Update method. ToPlantRealm is a mapper, which transforms plant into plantRealm.
@Override
public void update(Plant plant) {

    final Realm realm = Realm.getInstance(realmConfiguration);
    realm.executeTransaction(realmParam -> realmParam.copyToRealmOrUpdate(toPlantRealm.map(plant)));
    realm.close();
    deleteDB(realm);
}

ADD Method
@Override
public void add(final Iterable<Plant> plants) {

    realm = Realm.getInstance(realmConfiguration);

    realm.executeTransaction( realmParam -> {
        for (Plant plant : plants) {
            realmParam.copyToRealm(toPlantRealm.map(plant));
        }
    });

    realm.close();
}

The error is produced in this line
realm.executeTransaction(realmParam -> realmParam.copyToRealmOrUpdate(toPlantRealm.map(plant)));

I debugged inside Realm library and it says that the key already exists.
UPDATED
Comment: @Christian Melchior Any idea about this?
Comment: The stack trace and the the code you posted doesn't seem to match, so it is hard to tell what is going on, e.g. what does `repository.add(plant)`  do?
Comment: @Christian Melchior I would like to know why the copyToRealmOrUpdate method decides that my object is new instead of old. That's way, the exception about the constraint is triggered.
Answer: Your add method is wrong. You should use copyToRealmOrUpdate instead of copyToRealm
@Override
public void add(final Iterable<Plant> plants) {

    realm = Realm.getInstance(realmConfiguration);

    realm.executeTransaction( realmParam -> {
        for (Plant plant : plants) {
            realmParam.copyToRealmOrUpdate(toPlantRealm.map(plant));
        }
    });

    realm.close();
}

copyToRealmOrUpdate not working


Term for a note in a chord, versus a note in a key scale?

Question: Let's say we're talking about a song in C, and at some point in that particular song, we happen to be playing an E minor chord. In this case, Em is known as the iii chord in the key C major, because it's built on the 3rd degree of the C major scale.
What if we want to talk about the note G inside that Em chord? It's the 3rd note if we count up the (Phrygian) chord scale from E, but is there a known term, like "degree", that would help us refer to G, the third note in the chord-scale without confusing it with the third degree of the key-scale?
I think maybe I've heard "aspect" used to distinguish from "degree", but can anyone confirm this, or tell me what's most commonly said? Thanks very much.
Answer: In my experience, to avoid this confusion, people generally treat the chord-scale as a giant chord, naming each of its notes as if it were part of the chord. root, third, fifth, seventh, ninth, and so on. In other words, the "2" would be referred to as a 9 regardless of if it's inside the voicing or above it. This would give rise to the feeling that "scale degree 2" probably belongs to the key and not to some theoretical chord scale invoked by the moment. And that a "third" would probably belong to the chord of the moment, as that seems to best fit the context.
As for differentiating the function of a note in the chord from the function of the note in the key, it would generally be understood that "G" is the third of the chord without further clarification. If you wanted to talk about its function in the key, you could say it's the  fifth note of the key or you could add the emphasis that it's the third note of the chord. But if you're looking for terminology to clarify between these two roles, I don't know of one that's in common contemporary use. Maybe someone else can clarify whether there is indeed proper terminology.
The only thing I can think of which comes close to this is the function name of the key's pitches. You have the tonic, supertonic, mediant, etc. However many of these terms are used only rarely and therefore may not help if your aim is to add clarity.
Comment: I don't think I've heard of any term other than saying "of the chord" (if it could be ambiguous). As in: "The seventh scale degree is the third of the dominant."
Comment: By the way, the role of the note in the current harmonic structure is usually more important than the role it has in the key. There are some exceptions as when the root or fifth of the key are used in the melody to give stability to chords borrowed from other modes, or when the leading tone of the key creates a deceptive resolution. But in general, pitches considered individually give more meaning to the chord they're living in than to the overall key. Hope this helps!
Comment: Thanks for the context, it's helpful for sure. "Note of the chord" seems like as good a term as any.
Comment: This is a good answer! @Duncan, if it helped you, it's a good idea to upvote it right away, but before accepting (check mark) it's a good idea to allow 24-48 hours for other people to answer. There might be an even better answer out there, and people are more likely to post it if there isn't one already accepted.
Comment: I agree, and if someone does come up with a better answer or is able to add information I left out, it's perfectly acceptable to "unaccept" my answer and accept a different answer.
Answer: I think 'chordal' is the term you're searching for. As in that G would be a 'chordal minor third'. Chordal coming from 'of the chord'.As opposed to its place in the parent scale of 'dominant'note.
Answer: I think if I were trying to make this distinction, I'd call the first referent (the em in C) "the third degree of the scale" and the second referent (minor third of that em chord) the "third above the root":
Ie. "In C major, the chord of em is built on the third scale degree, and the note G is the third above its root."
rwf
Answer: I recently found the term "factor", which describes this idea: Wikipedia article on "Factor (chord)"