Banach contraction theorem exercise

Question: Use Banach contraction theorem to find a solution of x+e^x=0 correct to 3 decimal places.
Any suggestions how I should begin? Banach contraction theorem is new to me.
Comment: You usually apply the banach contraction theorem to solve equations, so there is an equals sign $(=)$ missing. Are you sure you didn't mistype the question?
Comment: Yes. I corrected it now.
Comment: Using MathJax can improve formatting. For example, $x+e^x=0$ rather than x+e^x=0.
Answer: Banach's contraction theorem tells you, that given an operator $\Phi:\mathbb{R}\rightarrow \mathbb{R}$, a solution to the equation
$$\Phi(x)=x$$
can be approximated by fixed point iterations if $\Phi$ is a contraction. To apply this here, we can rewrite the equation
$$x+e^x = 0$$
as
$$x=-e^x$$.
The map $\Phi$ is therefore $\Phi(x)=-e^x$. Now we can take an initial guess for the solution $x_0=-1/2$ and define
$$x_1 = \Phi(x_0),\ x_2=\Phi(x_1),\ x_3 = \Phi(x_2),\ ...$$
in case the contraction property is fulfilled, the resulting sequence satisfies
$$\lim_{n\rightarrow \infty}x_n = x^*$$
where $x^*$ is the solution to $x+e^x=0$.
Note that choosing a "right" starting value is important for this problem since $\Phi$ only fulfills the contraction property in a neighbourhood of $x^*$.
Comment: One could also add how to estimate the error of each iteration, i.e. how to estimate a priori how many iterations one needs to fulfil the "3 decimal places correctness". If $\theta$ is the contraction constant, you get $||x_k - x^*|| \leq \frac{\theta^k}{1-\theta} \cdot ||x_1 - x_0||$
Comment: Thank you so much, but how do you calculate it is -1/2?
Answer: $e^X+X=0$ so we need the function $f(x)=-e^x$. Is it contractant?
If $f(X)=X$ , then $X$ must be negative since $e^x$ is always positive. Assuming this it follows that $f$ is contractant at the negative neighborhood of the fixed point $X$; in fact
$$|-e^{x_1}-(-e^{x_2}|=|e^{x_2}-e^{x_1}|=|x_2-x_1|\cdot|1+\frac{x_2+x_1}{2}+….|$$ so the last factor is $<1$
Furthermore the function $e^x+x$ is increasing and $e^0+0=1$ and $e^{-1}-1=-0.367879-1<0$ hence the fixed point $X$ is in the interval $[-1,0]$.
Choosing  $x=-a$ we have successively $f(-a)=-e^{-a}$; $f(f(-a))=-e^{-e^{-a}}$;  $f(f(f(-a)))=-e^{-e^{-e^{-a}}}$;….
It seems to me the only way is to calculate the successive iterations till an approximation we consider adequate. Seeing at the graphs of $-e^x$ and $x$ we can see the point $X\approx 0.567$.

Banach contraction theorem exercise


Why are Gabon playing in the African Cup of Nations 2017 qualifiers when they're hosts and how will group I work?

Question: I recently saw Sierra Leone beat Gabon in the qualifying competition for the African Cup of Nations 2017. Gabon and Sierra Leone are in qualifying group I.
But Gabon are the hosts of AfCON 2017, so they get automatic qualification.
How does this work?

Why are Gabon in the qualifiers, if they have already qualified?
Can any other teams qualify from group I?
Are qualifying games against Gabon the same as any other qualifying game?

I've looked on the official AfCON site but it seems to treat Gabon like any other team in the qualifiers, and I can't find any explanation elsewhere.
I read on a Sierra Leone news site that points against Gabon don't count:

The match was part of the 2017 African Cup of Nations (AFCON) group I qualifying schedule but didn't count towards qualification as Gabon are hosting the finals in January

...but that appears to be contradicted by the official table, which does include Sierra Leone's three points from beating Gabon:

So I'm confused about how this works. Can no-one else qualify from group I? Or are the Gabon-related points deducted and the highest-finishing team excluding Gabon qualifies? Or was the Sierra Leone news site wrong and it's simply the top team in the Group I (excluding Gabon) who qualify? Or something else?
And why are Gabon in a qualifying group in the first place when they have automatic qualification?
Answer: Gabon national team is qualified because of nation host.
The team was insert in Group I and has played friendly against other team of the same Group
Wikipedia has insert Gabon in the Group A of qualified teams:
The host nation team will also be drawn into a group and will play games against those in that group; however, these matches will only be considered as friendlies and not counted for the standings.

Qualification criteria are:

the winner team for each Group will be qualified for AFC2017
the two best second teams for each 4-team composed Group (so not group I and group G) can be qualified by rankings
Comment: Group I is formally considered by 3 teams: Cote d'Ivorie Sudan and Sierra Leone: the first one will be qualified for AFC2017 tournament
Comment: @PhilipKendall It seems impossible to believe, but in my opinion this official table is wrong. As soon as I can I will search other sources to confirm that
Comment: Yes, I know Gabon have automatic qualification as hosts. That's why I'm asking the question! AfCON seem to be treating Gabon's qualifying games as official games (see the table), so my question is what happens to the other teams in group I, can they still qualify, etc?
Comment: So are you saying the [official table](http://www.cafonline.com/en-us/competitions/qcan2017.aspx/standings.aspx) is wrong?
Answer: The official table as it stands without Gabon. So the highest ranked team out of the 3 remaining countries Ivory Coast, Sudan & Sierra Leone will qualify for AFCON 2017.
Comment: Welcome to SE.Sport. This reply seems do not add any info to the previus one


Is there a namespace aware alternative to PHP's class_exists()?

Question: If you try using class_exists() inside a method of a class in PHP you have to specify the full name of the class--the current namespace is not respected.  For example if my class is:
 <?
    namespace Foo;

    class Bar{
       public function doesBooClassExist(){
            return class_exists('Boo');
       }
    }

And Boo is a class (which properly autoloads) and looks like this
   namespace Foo;

    class Boo{
       // stuff in here
    }

if I try:
$bar = new Bar();
$success = $bar->doesBooClassExist();
var_dump($success);

you'll get a false...  is there an alternative way to do this without having to explicitly specify the full class name ( i.e. class_exits('Foo\Boo') )?
Comment: Have you tried prepending the class name with `__NAMESPACE__` in your `doesBooClassExist()` method?  Or am I misunderstanding what you're trying to do?  (see http://www.php.net/manual/en/language.namespaces.nsconstants.php )
Comment: @Crontab This could be done as you indicate if there is not another way that's already namespace aware--just a personal preference.  You should make this an answer.
Comment: I am not sure, but I think that its correct for the class_exists to search not in the namespace.. If it checks directly in the namespace how you will be able to check for class outside any namespaces from inside?
Comment: @Ray Looks like a few others beat me to it over lunch.  =)
Answer: Prior to 5.5, the best way to do this is to always use the fully qualified class name:
public function doesBooClassExist() {
    return class_exists('Foo\Boo');
}

It's not difficult, and it makes it absolutely clear what you're referring to. Remember, you should be going for readability. Namespace imports are handy for writing, but make reading confusing (because you need to keep in mind the current namespace and any imports when reading code).
However, in 5.5, there's a new construct coming:
public function doesBooClassExist() {
    return class_exists(Boo::class);
}

The class pseudo magic constant can be put onto any identifier and it will return the fully qualified class name that it will resolve to.......
Comment: Note that this can't be used with dynamic class names. It will throw **Fatal error: Dynamic class names are not allowed in compile-time ::class fetch** - but if they reside in the current namespace you can assemble the fully qualified class name by hand: `$fqcn = __NAMESPACE__.'\\'.$class_name`
Comment: Shouldn't the backslash be escaped (per the [PHP namespaces FAQ](http://php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.quote))?
Comment: + This is a better approach


What is the difference in accuracy in answers from Definite Integration and Simpson's rule?

Question: I have worked out the same equation with the Definite Integration and Simpson's Rule. I now need to comment on the accuracy of these answers. I know Simpson's rule is an approximation, but does that make the answer from the Definite Integration a $100$% accurate? or is it just a more accurate estimation?
Answer: If you have been able to find the definite integral, then that is the exact area required. You can then find the error in your Simpson's Rule approximation by working out the difference between your two values. The relative error is given by dividing the error by the true value; it can be expressed as a percentage or as a decimal.


show $k! = m^\alpha$ is impossible

Question: I am not sure how to show that $$m^\alpha = k!$$ is impossible $\forall m,\alpha,k > 1$. I am supposed to use Bertrands theorem which states:  There exists atleast one prime in the open interval $(x, 2x)$ This is a homework question.
Comment: what do you know about the prime factorization of $m^\alpha,$ and what do you know about the prime factorization of $k!$
Comment: Will Jagy's question is your answer!
Comment: Perhaps you should specify that $\alpha$ (and $m$) are integers.
Answer: Note that since $a>1$, every prime number appearing in the decomposition of $m^a$ has power greater than 1.
Let $k>2$. If $k$ is even,  there is a prime number $p$ between $k$ and $k/2$ and this prime number $p$ appears only once in $k!$, hence $k!\neq m^a$.
When $k$ is odd, there is a prime nubmer $p$ between $k-1$ and $(k-1)/2$  and this prime number $p$ appears only once in $k!$, hence $k!\neq m^a$.
This is a basic idea and you need to fill gaps.
Comment: I see the solution but what are the gaps I need to fill. Isnt your answer sufficient enough or is it missing something'
Comment: Maybe you need to write why that prime $p$ appears only once in the decomposition of $k!$.
Comment: Thats by bertrands theorem, correct? Consider $n! = 1 \cdot 2 \cdot 3 \ldots \cdot n$. We know there exists a prime between $(\frac{n}{2}, n$ by Bertrands theorem. So $n/2 \leq p \leq n$. so then by definition of the factorial, p can only appear once
Comment: Yes, you are right. But a slight problem is that when $k=4$, you might take $p=2$. In this case, $p$ appears more than once.
Comment: but its an open interval, so if $k = 4$ then there is some prime between $(2, 4)$ which is 3.
Comment: Ok, I thought it is closed interval. In that case it is fine.
Comment: could you discuss the case where its closed? just for personal satisfaction.

show $k! = m^\alpha$ is impossible


Asymptotic difference between a function and its binomial average

Question: The origin of this question is the identity
$$\sum_{k=0}^n \binom{n}{k} H_k = 2^n \left(H_n - \sum_{k=1}^n \frac{1}{k 2^k}\right),$$
where $H_n$ is the $n$th harmonic number.
Dividing by $2^n$, we have
$$2^{-n} \sum_{k=0}^n \binom{n}{k} H_k = H_n - \sum_{k=1}^n \frac{1}{k 2^k}.$$
The sum on the left can now be interpreted as a weighted average of the harmonic numbers through $H_n$ -- where the weights, of course, are the binomial coefficients.  Thus the difference between $H_n$ and its "binomial average" (I'm guessing there's no term for this) is
$$H_n - 2^{-n} \sum_{k=0}^n \binom{n}{k} H_k =  \sum_{k=1}^n \frac{1}{k 2^k}.$$
The sum on the right is known to converge to $\ln 2$ as $n \to \infty$.  (Substitute $-\frac{1}{2}$ into the Maclaurin series for $\ln (1+x)$.)
This leads me to my question:

Can we classify nonnegative functions $f(n)$ for which
  $$\lim_{n \to \infty} \left(f(n) - 2^{-n} \sum_{k=0}^n \binom{n}{k} f(k) \right)$$ is finite and nonzero?

It would seem that if $f$ increases sufficiently rapidly, then the limit would be $\infty$.  This is the case with both $f(n) = a^n$ and $f(n) = n$.  If $f$ decreases or is constant, then the limit is zero.  If $f$ has basically logarithmic growth, then it seems the limit would behave as $H_n$.  But can this be proved?  And what about other sublinear, increasing functions?
Comment: I agree that logarithmic growth is what you need. The "binomial average" of $f(n)$ should be about $f(n/2)$.
Answer: The function $f(n)$ must be $\Theta (\log n)$.  Update: As Didier Piau points out in the comments to the question after I asked it on Math Overflow, we can say something stronger: $\frac{f(n)}{\log_2 n} \to L$ as $n \to \infty$.  See the update at the end of the argument.
Suppose, for some positive $L$ (the negative case is similar), $$\lim_{n \to \infty} \left(f(n) - 2^{-n} \sum_{k=0}^n \binom{n}{k} f(k) \right) = L.$$
Thus $$f(n) = L + r(n) + 2^{-n} \sum_{k=0}^n \binom{n}{k} f(k)$$ for some function $r(n)$ such that $r(n) \to 0$ as $n \to \infty$.  This gives us a recurrence relation for $f(n)$.  Since $r(n) \to 0$, $L + r(n) > 0$ for all sufficiently large $n$.  So, for all sufficiently large $n$, there exist positive constants $C$ and $D$ such that $C < L + r(n) < D$.  Since the initial terms in the function eventually become negligible in determining the value of $f(n)$ via the recurrence relation, there exist functions $g(n)$ and $h(n)$ such that for all sufficiently large $n$, $g(n) \leq f(n) \leq h(n)$ and $g(n)$ and $h(n)$ satisfy
$$g(n) = C + 2^{-n} \sum_{k=0}^n \binom{n}{k} g(k),$$
$$h(n) = D + 2^{-n} \sum_{k=0}^n \binom{n}{k} h(k).$$
So the problem reduces to showing that $g(n)$ and $h(n)$ are $\Theta (\log n)$.  The argument is the same for both.
There are some different ways to do this; my favorite is to interpret the $g(n)$ recurrence probabilistically.  Suppose we start at time $g(0)$, we flip a set of $n$ coins simultaneously each round, and it takes $C$ time units to do one round of flips.  When a coin turns up heads for the first time, we cease flipping it.  Let $T(n)$ be the time at which the last coin to achieve its first head does so.  To find $E[T(n)]$, condition on the number of coins that achieve heads in the first round of flips.  This yields $$E[T(n)] = C + 2^{-n} \sum_{k=0}^n \binom{n}{k} E[T(n-k)] = C + 2^{-n} \sum_{k=0}^n \binom{n}{k} E[T(k)].$$  Thus $g(n) = E[T(n)]$.
Another way to view $T(n)$ is that it is $g(0) + C M_n$, where $M_n = \max\{X_1, X_2, \ldots, X_n\}$ and the $X_i$'s are independent and identically distributed geometric $(1/2)$ random variables.  (Each geometric random variable models the first time a head appears.)  Thus $g(n) = g(0) + C E[M_n]$.  It is known that $\frac{H_n}{\log 2} \leq E[M_n] \leq \frac{H_n}{\log 2} + 1$ and, more precisely, that $E[M_n]$ is logarithmically summable to $\frac{H_n}{\log 2} + \frac{1}{2}$.  (See, for example, Bennett Eisenberg's paper "On the expectation of the maximum of IID geometric random variables," Statistics and Probability Letters  78 (2008) 135-143.  See also this MO question, "What is the Expected Maximum out of a Sample (size $n$) from a Geometric Distribution?")
Thus $g(n) = \frac{C}{\log 2} \log n + O(1)$, which means that $h(n) = \frac{D}{\log 2} \log n + O(1)$ and $f(n) = \Theta (\log n)$.
Update: Given $\epsilon > 0$, if we take take $C > 0$ such that $L - \epsilon \leq C < L$ and $D = L + \epsilon$, this argument shows that
$$L - \epsilon + O\left(\frac{1}{\log n}\right) \leq \frac{f(n)}{\log_2 n} \leq L + \epsilon + O\left(\frac{1}{\log n}\right).$$
Thus, as $n \to \infty$, $\frac{f(n)}{\log_2 n} \to L.$
For some other ideas that pertain to this result, including what are effectively some alternative derivations, see Pradipta's recent MO question, "Coin Flipping and a Recurrence Relation".  In fact, reading Pradipta's question and some of its answers gave me the ideas needed to construct this argument!  So, thanks go to Pradipta, Didier Piau, Emil Jeřábek, and Louigi Addario-Berry.
Answer: Here's an idea that might lead somewhere.  Let $F(x) = \sum_{n \ge 0} \frac{f(n)}{n!} x^n$, let $g(n) = \frac{1}{2^n} \sum_{k=0}^{n} {n \choose n-k} f(k)$, and let $G(x) = \sum_{n \ge 0} \frac{g(n)}{n!} x^n$.  Then it's not hard to see that $G(x) = e^{\frac{x}{2}} F \left( \frac{x}{2} \right)$, so we are looking for functions $F$ such that
$$F(x) - e^{\frac{x}{2}} F \left( \frac{x}{2} \right) = A(x)$$

for some $A(x)$ with Taylor coefficients tending to some nonzero limit.  Let $H(x) = e^x F(x)$.  Now we want

$$H(x) - H \left( \frac{x}{2} \right) = e^{-x} A(x).$$
This condition is easier to work with on the left now but harder to work with on the right.
Comment: Thanks, Qiaochu.  This is a nice formulation of the problem in terms of exponential generating functions and gives another line of attack.
Answer: A very quick and rough approach:
It seems probable to me that the particular weights of the averaging are not important, that things would be similar with a (eg) uniform averaging. Assuming this, in the continuous, a simple analogy would be
$\displaystyle \lim_{x \to \infty } f(x) -\frac{\int_0^x f(x) dx }{x} = \lim_{x \to \infty }f(x) - \frac{F(x)}{x} = k \hspace{1cm}$  with $f(x) >0 $ and  $0 <k <\infty$
And $f(x) = a \log(x) + b  $  (or any function that grows logarithmically) fits the bill. And, in particular, the harmonic numbers, grows in this way.
Comment: You may be right that the particular weights of the averaging are not important, but I think I would need to see a proof of it before being convinced.  (That might make for a good, separate math.SE question, actually. :) )
Comment: The weights of the averaging matter. Note that, for large $n$, the analogue of the binomial sum applied to $f$ is more like $f(x/2)$ than like the integral of $f$ on $(0,x)$ normalized by $x$. This is because a binomial random variable of parameters $(n,\frac12)$ concentrates around $\frac12n$ rather than becoming spread out over the interval $(0,n)$.
Comment: @Didier: yes, i saw that - i first tried to write the same equations as a convolution with a gaussian, but I prefered this simplification of a simplification. I don't think it changes the law of growth. We could also write the other extreme aproximation (a delta centered at x/2 instead of a uniform) as `f(x) - f(x/2) ~ k` , and we also get `f(x) ~ log(x)`


"split" dataframe per month based on columns Start/End

Question: I need to "split" a 15 million line df of the following form:
library(lubridate)
dateStart <- c(lubridate::ymd("2010-01-01"))
dateEnd <- c(lubridate::ymd("2010-03-06"))
length <- c(65)
Amt <- c(348.80)

df1 <- data.frame(dateStart, dateEnd, length, Amt)

df1
#    dateStart    dateEnd length   Amt
# 1 2010-01-01 2010-03-06     65 348.8

into something like:
dateStart    dateEnd length   Amt
1 2010-01-01 2010-01-31     31 166.35
2 2010-02-01 2010-02-28     28 150.55
3 2010-03-01 2010-03-06     6 32.19

Where length is the number of days and Amt is the pro-rata amount for the number of days. Does anybody know how to do this? Someone mentioned the padr package to me but I do not know how to use it for this specific purpose.
Thank you in advance
Comment: How do you define lengths 30 and amount 160.98? Why 30 days(?) in a month?
Comment: i corrected the lengths in the example to show the real number of days. Amount is pro-rata
Answer: I'm going to assume you have an some sort of unique id field in your data set so you have a unique record. Otherwise this is not going to work. I also added 1 extra record so we can see everything works on multiple records.
Data:
library(lubridate)
id <- c(1:2) # added id field needed for unique record and needed for grouping
dateStart <- c(lubridate::ymd("2010-01-01", "2011-01-09"))
dateEnd <- c(lubridate::ymd("2010-03-06", "2011-04-09"))
length <- c(65, 91)
Amt <- c(348.80, 468.70)

df1 <- data.frame(id , dateStart, dateEnd, length, Amt)

First create a data.frame which has the id and missing months. We need dplyr, tidyr and padr. Create groups per unique id, gather the dates so we have start and end date in 1 column. For padr to extend months we first need to thicken the data.frame. Get rid of not needed columns and fill in the missing months.
library(dplyr)
library(tidyr)
library(padr)

#create last_day function for later use
last_day <- function(date) {
  ceiling_date(date, "month") - days(1)
}

dates <- df1 %>%
  select(id, dateStart, dateEnd) %>%
  group_by(id) %>%
  gather(names, dates, -id) %>%
  arrange(id, dates) %>%
  thicken(interval = "month") %>% # need to thicken first for month interval
  select(-c(names, dates)) %>%
  pad(interval = "month")

dates
# A tibble: 7 x 2
# Groups:   id [2]
     id dates_month
  <int> <date>
1     1 2010-01-01
2     1 2010-02-01
3     1 2010-03-01
4     2 2011-01-01
5     2 2011-02-01
6     2 2011-03-01
7     2 2011-04-01

Next join back the data to the original data.frame
df_extended <- inner_join(dates, df1, by = "id")

df_extended
# A tibble: 7 x 6
# Groups:   id [2]
     id dates_month dateStart  dateEnd    length   Amt
  <int> <date>      <date>     <date>      <dbl> <dbl>
1     1 2010-01-01  2010-01-01 2010-03-06     65  349.
2     1 2010-02-01  2010-01-01 2010-03-06     65  349.
3     1 2010-03-01  2010-01-01 2010-03-06     65  349.
4     2 2011-01-01  2011-01-09 2011-04-09     91  469.
5     2 2011-02-01  2011-01-09 2011-04-09     91  469.
6     2 2011-03-01  2011-01-09 2011-04-09     91  469.
7     2 2011-04-01  2011-01-09 2011-04-09     91  469.

Now to get to the end result. need to use case_when, ifelse doesn't return the data in date format for some reason. The case_when replace set the correct start and end dates (I assume you need the exact start date, not the first of the month, otherwise adjust code to use dates_month instead.) I create an amount per day (amt_pd) variable to be able to multiply this with the number of days in the month to get the pro-rata amount for the number of days in the month.
df_end <- df_extended %>%
  mutate(dateEnd = case_when(last_day(dates_month) <= dateEnd ~ last_day(dates_month),
                             TRUE ~ dateEnd),
         dateStart  = case_when(dates_month <= dateStart ~ dateStart,
                                TRUE ~ dates_month),
         amt_pd = Amt / length,
         length = dateEnd - dateStart + 1,
         Amt = amt_pd * length) %>%
  select(-c(dates_month, amt_pd)) # get rid of not needed columns

df_end
# A tibble: 7 x 5
# Groups:   id [2]
     id dateStart  dateEnd    length Amt
  <int> <date>     <date>     <time> <time>
1     1 2010-01-01 2010-01-31 31     166.350769230769
2     1 2010-02-01 2010-02-28 28     150.252307692308
3     1 2010-03-01 2010-03-06 6      32.1969230769231
4     2 2011-01-09 2011-01-31 23     118.462637362637
5     2 2011-02-01 2011-02-28 28     144.215384615385
6     2 2011-03-01 2011-03-31 31     159.667032967033
7     2 2011-04-01 2011-04-09 9      46.354945054945

All of this could be done in one go. But if you have 15 million rows it might be better to see if the intermediate steps work. Also note that pad has a break_above option.

This is a numeric value that indicates the number of rows in millions
  above which the function will break. Safety net for situations where
  the interval is different than expected and padding yields a very
  large dataframe, possibly overflowing memory.


Exchange 2010 SSL certificate requirements for multiple domains

Question: I've read this, and I'm still not 100% on this.
If our Exchange server is hosting email for multiple authoritative domains, do I need matching SAN names on the SSL certificate for each one?
In our setup the AD domain is company.local, the email domain for most people is company.com, but we also have some people that have email addresses @othercompany.com.
So when I buy the SSL certificate, I assume I would need:

mail.company.com
autodiscover.company.com
legacy.company.com
mail.othercompany.com
autodiscover.othercompany.com
legacy.othercompany.com

Is that right?
Answer: Apart from the required internal FQDN's and server names, you only need the domains on your certificate that you need to securely access your server on (OWA or ActiveSync for example). Your Exchange server can accept mail for any number of other domains, but if you only access OWA on mail.acme-widgets.com then that is the only external DNS name that needs to be on the certificate.
As an example, our Exchange server accepts mail for about 30 domains, but we only have the following things on our certificate (pardon the whole Acme Widgets thing, but you get the idea).
svr03                               (Internal server name)
mail.acme-widgets.com               (OWA domain)
autodiscover.corp.acme-widgets.com  (AutoDiscover internal FQDN)
autodiscover.acme-widgets.com       (AutoDiscover external FQDN)
legacy.acme-widgets.com             (Legacy domain)
svr03.corp.acme-widgets.com         (Internal FQDN)

If I recall correctly, when I was going through the Exchange certificate wizard it did include all of our auxiliary domains, but I chose to remove them. It shouldn't hurt to leave them on, and if the certificate wizard includes them by default, it's certainly not wrong to leave them.
Comment: Thanks. I'm still in the planning phase, so running the certificate wizard isn't an option right now. Obviously, the more alternate names I add the more expensive the certificate gets, hence the need to figure this out sooner rather than later.
Comment: If you have it set up this way, does AutoDiscover still work for users whose email address is not in the acme-widgets.com domain? From what I understand, it shouldn't but maybe I'm missing something?
Comment: @Graeme that's a very good question. I'm inclined to say for AutoDiscover to work, the domain *will* need to be on the certificate, but without testing it I wouldn't like to say for certain. That might explain a bit better why the behaviour of the certificate wizard is to add all your accepted domains though. I guess I'm lucky that all my primary email addresses are `@acme-widgets.com` so I don't run into this issue.
Comment: Hmmmm I guess a little testing is in order. Will fire up a VM and play around a bit.
Answer: Actually if you reconfigure your Exchange correctly you can make use of only one domain / certificate (for example mail.company.com) for both internal and external access. However then your owa / outlook configuration will always have to point to this chosen domain name. This is simplest/cheapest scenario.
This link can help you to setup Exchange 2010 to use only one  domain for everything. Otherwise if you want to keep using different domain names for different people you need to use SAN certificate. This can be expensive solution.
One domain solution for everything (internal / external access) can even be cheaper by using completely free certificates from StartSsl for 1 year (extended every year for free). If general company name mail.company.com is too big problem (this could be an issue if your employees wouldn't feel right by accessing mail.microsoft.com while being from IBM and vice versa - although I doubt this would be a problem in your case) you could always buy some unrelated domain name to the company's name like mailserver.com or something similar and use that. Then neither employees from legacy company or new company will complain.
Comment: There's no "legacy" company, the legacy hostname is required for Exchange 2007/2010 co-existence. AFAIK, clients supporting AutoDiscover will look for https://autodiscover.example.com/bla if the email address is @example.com. Doesn't using 1 name break AutoDiscover?
Comment: I've followed this Microsoft Article and it seems to work fine for 2 of my clients.


Dell 62xx (6224) QinQ configuration (Double-Vlan)

Question: I have a few Dell 6224 and a bunch of 3524's and some 5324 - with the latest firmware.
I need to configure QinQ between ports, conveniently called "Customer port" on the 35xx and the 53xx, and it works like a charm there, can even do the config right from GUI - set the port to customer mode, and tag the VLAN to use for the transport. (ingress data tag data is ignored and a outer heading added for transport, egress strips the outer tag).
But, the 62xx will not play nicely - it has what is called "double-VLAN" or dvlan-tunnel, which is supposed to provide the same features.
The manual is junk and support haven't provided an answer in days now.
The best online info I could find was at community.dell.com,
but that still doesn't tell me the correct way of using dvlan-tunnel - as soon as I enable it on any interface, all other trunks stops forwarding.
Does anyone know how to configure this correctly without bringing down the rest of the switch, when you have a mix of normal q-tags and need some q-in-q for just a port or two?
Answer: The 'mode dvlan-tunnel' option on the 62xx switches does work, but it's "backwards". You enable the 'mode dvlan-tunnel' option not (as one would expect) on push/pop ports, but instead on all trunks that will carry your provider tags. Then you set your customer-facing push/pop ports as standard access ports with the access vlan of your provider (outer) tag, and let customers do their thing within.
Comment: wow - so there is no way to configure without downtime unless I had set it on all regular trunks from the beginning.. heh..  what a wonderful world - Dell really should stick to one OS when it comes to its switches... thank you
Comment: btw that did work just fine - and looking at the original URL it was right in there, the answer was too complicated on that page for my farted out brain to get :)  I don't know why that wouldn't be a default option on all trunk ports then, and to explicitly turn it off for "customer ports"... oh well, Dell works in mysterious ways


Complex promql queries

Question: I have prometheus with metrics of many users. I need to apply some promql functions to EACH metric. Can i create one request to prometheus, to get metrics in desired format?
For example, apply avg on CPU metric and irate on IO at the same time
Answer: That's not possible, each query/query_range API call can only evaluate one PromQL expression.

Complex promql queries


Electric guitar neck crack. Worth repairing?

Question: Recently I noticed a crack on the neck of my 20 years old Ibanez RG. I'm not sure how it happened, I never knocked it over and never messed with the truss rod.
Days ago I was switching strings for a higher gauge but the tremolo springs were dead so the bridge went way up and I just bagged the guitar like that for maybe a day or two, until I got the new springs.
A few days later I noticed these two cracks on the neck, just below the headstock. Could this have been created by the high action caused by the dead springs?
And is it worth trying to fix it? The cracks are too small to insert glue in them so I would have to clamp the neck. But clamping it enough to get the glue in there might increase the cracks even further, so I don't know if I should go for it or just ignore it and keep playing until it gets worse, and only then do something about it.
I know that taking it to a luthier is the most sensible thing to do but I'm not a very sensible person. Just enough to get this posted.
Comment: That just looks like grain to me. If you can touch it and feel the edge, sure, but with my eyes, I'm not seeing the problem.
Comment: anything with a bolt on neck is not that hard to replace, I would consider replacing it myself as all you need to do is remove some screws.
Comment: What the heck are 'dead springs'?
Comment: @Tim springs that have lost their tension.
Comment: @NeilMeyer my goal is to repair it, if worth it. Repaired broken headstocks can last a lifetime if done properly. Otherwise I'll just replace it.
Comment: I agree with Dave Jacoby, from this picture it just looks like you're pointing to wood grain that isn't cracked or split.
Comment: @DaveJacoby I know it's not the best lighting/angle on the picture, but yes I can feel the edges of the cracks. As I said, those are really small but definitely not wood grain.
Answer: Ask your local luthier to be sure. Honestly, it's the best way.
By the picture, I can't tell what you're seeing as cracks. I am sure it's more obvious in person. I had an Ibanez acoustic with a Wizard neck and headstock that I tossed because the truss rod started cracking out the back of the neck, and that was very obvious to see
I guess the question is how nice an RG is it? The line goes from like $150 to $3000. I'm seeing replacement RG necks around $120, so it goes from it being cheaper to buy a new guitar than a new neck to bring perhaps a downgrade. Beyond that, there's whatever sentimental connection you have to your instrument.
Maybe, with more pictures, I could give better guidance, but really, all the answers can best be answered in the bench. Find a good repair shop and get an estimate. It's the best choice.
Answer: I'm looking at the picture and it appears to me the the wood grain is not oriented the same as a quarter sawn neck, thus indicating to me that the strength and stiffness of the neck have probably never been optimal and  the orientation of the grain might be the reason the neck is beginning to fail. Add to that fact, the condition of the neck having be weakened further by the position of the holes drilled to facilitate the locking mechanism, and I can imagine why it might fail. If it were my guitar, I would choose to replace it with a better quality neck, preferably quarter sawn and drilled out by someone with experience installing locking mechanisms. I'd just consider it an upgrade to my instrument.
Answer: It almost looks like wood grain or a joint between two different pieces of wood.
The real issue might be if the locking bolts were tightened too much?
It is strange that a 20 yo guitar with no issues would do this.  It is definitely worth taking to a luthier and pricing what it would cost to fix.  If the wood split along the grain a fix should be easy.  I snapped the head stock off a Les Paul copy I made in high school and the brake was so clean that the grain lined up.  Epoxy and a clamp and good as new (though I'm not a luthier).
Don't speculate, get an estimate.  I'd get it fixed.
Answer: A few observations:

Looking at the grain and wood fiber relative to the line of the neck, I would conclude that the cracks have been probably caused by a significant impact, such as the instrument falling backwards, perhaps a foot or two. Another possibility is that the wood has always been weak along the grain in those places, and has finally come apart after a long time, perhaps after an otherwise unremarkable impact, or perhaps even because of the continuous pull of the strings in the opposite direction. But the latter seems less likely, I still think that some kind of impact is the most likely cause.

Because of the size and position of the cracks, and because they seem to be relatively superficial, looking from a distance, I'd say there is a 60/40 chance that nothing else will happen vs the chance that the crack will expand.

If the instrument is not particularly valuable or critically important to you, I'd say that it would not be unreasonable to wait and see what happens.

Put some kind of mark at the end of the crack. If the crack ever extends beyond that, it's likely to keep getting worse, and a trip to the luthier will be inevitable, and sooner will be better than later. If the cracks don't expand even if you continue using the instrument, it's likely nothing further will happen.

To fix it, a luthier would remove the strings, bend the neck or slightly force the cracks open to inject some glue all the way down, then press it back, clean away the extra glue that gets squished out, and clamp it close until the glue cures (with something soft in between to protect the neck, obviously). If you attempt to do this by yourself, it's critical that you use the correct type of glue for the job. There are also many videos on YouTube where luthiers show these kinds of repairs.


Distributional derivative of Weierstrass function

Question: How can we compute the distributional derivative of the Weierstrass function
$$W(x) =\sum_{k=1}^\infty \lambda^{(s-2)k}\sin(\lambda^k x)$$
where $s \in (0,2)$ and $\lambda$ are fixed parameters?
We know that the Weierstrass function is nowhere differentiable. This implies that it does not have a weak derivative. However, since $W \in L^1_{loc}$, we can consider the associated distribution $T_W$ and compute its distributional derivative.
I'm having troubles doing that computation because of the series representation of $W$.
Comment: I'm glad you edited it to fix that, but it doesn't address 2 of the 3 issues in my comment; since this is not a do-my-homework site, please [edit] the question to *actually* improve it.
Comment: @TedShifrin We take those parameters to be fixed.
Comment: Your question doesn't make sense as written. What are you actually trying to do, what tools do you have available, and what is the motivation?
Comment: @T.Bongers Sorry, there was a typo (that is, I had mistakenly deleted the main verb of the sentence).
Comment: @T.Bongers Done.
Comment: You have two parameters: $s$ and $\lambda$. How is $W$ a function just of $x$?
Comment: Why do you think the function is nowhere differentiable? I think this should only be true if $s\in (0,1]$ but not if $s\in (1,2)$.
Comment: @Shalop Why is that?
Comment: Sorry I meant the other way, it's differentiable if s is in (0,1) but not if s is in [1,2). That's because the series of derivatives converges uniformly in the former case
Answer: For some $r \in (1/2,1)$ let
$$W(x) = \sum_{m=0}^\infty r^m e^{2i\pi 2^m x}$$
The series converges uniformly to a continuous function and for any $\phi \in C^\infty(\Bbb{R/Z})$ smooth $1$-periodic $$\langle W,\phi \rangle = \int_0^1 W(x)\phi(x)dx = \sum_{m=0}^\infty r^m \hat{\phi}(-2^m), \qquad \hat{\phi}(n) = \langle e^{-2i \pi n x},\phi \rangle$$
Which defines a distribution $W \in D'(\Bbb{R/Z})$.
Then
$$W^{(k)}(x) = \lim_{M\to \infty}(2i\pi)^k\sum_{m=0}^M (2^k r)^m  e^{2i\pi 2^m x}$$
(with the limit taken in the sense of distribution)
defines a distribution
$$\langle W^{(k)},\phi \rangle = (2i\pi)^k\sum_{m=0}^\infty (2^k r)^m \hat{\phi}(-2^m)$$
the series converges absolutely since $\hat{\phi}(n) = O(n^{-l})$ for every $l$.
Comment: Thank you. 1. Why can we rewrite $W(x)$ in that way for some $r \in (1/2, 1)$? 2.  Why can we take $\phi \in C^\infty(\mathbb{R}/\mathbb{Z})$ instead of just $\phi \in  C^\infty(\mathbb{R})$? 3. What did you deduce the decay of $\hat \phi$ from? 4. Can we rewrite the series in the last formula in a more explicit way?
Comment: If you want to consider $W$ as a distribution on $\Bbb{R}$ then $\langle W,\varphi \rangle_\Bbb{R} = \langle W, P \varphi \rangle_\Bbb{R/Z}$ where $P \varphi(x) = \sum_n \varphi(x+n)$, so it doesn't change anything (as $P$ is a continuous linear map $ C^\infty_c(\Bbb{R}) \to  C^\infty(\Bbb{R/Z})$), equivalently replace the Fourier series coefficients of $\phi$ by the Fourier transform of $\varphi$.
Comment: The faster-than-polynomial decay of Fourier coefficients of smooth functions is well-known : $|\hat{\phi}(n) (2i\pi n)^l| \le \|\phi^{(l)}\|_{L^1(0,1)}$
Comment: anything unclear ?
Comment: Thank you for your comments. Why is it true that there exists $r \in (1/2,1)$ such that
$W(x) = \sum_{m=0}^\infty r^m e^{2i\pi 2^m x}$? Could you add some details on that?
Comment: Come on you are supposed to look at $Im(W(x))$.
Comment: What do you mean?
Comment: Don't see how to go from $ \sum_{m=0}^\infty r^m e^{2i\pi 2^m x}$ to $\sum_{k=1}^\infty \lambda^{(s-2)k}\sin(\lambda^k x)$ ??
Comment: I don't. How do you do it?
Comment: Do you mean $\mathbb{R}/\mathbb{Z}$ as in the quotient ring?


Best way to show that these $3$ vectors are a basis of the vector space $\mathbb{R}^{3}$?

Question: I'm writing a linear algebra exam soon and I'd like to know a fast way to solve a task like that:

$$u=\begin{pmatrix} 0\\  0\\  1 \end{pmatrix}, v= \begin{pmatrix} 1\\
0\\  1 \end{pmatrix}, w = \begin{pmatrix} 0\\  1\\  1 \end{pmatrix}$$
Show that $(u,v,w)$ is a basis of the vector space $\mathbb{R}^{3}.$

I would start by checking if these vectors are linearly independent. I do this by checking determinant $\neq 0$:

Using Sarrus rule, we know that determinant is $1$ and thus these vectors are linearly independent.
Now let $x,y,z \in \mathbb{R}$
$$\begin{pmatrix}
x\\
y\\
z
\end{pmatrix}=\lambda_{1}\begin{pmatrix}
0\\
0\\
1
\end{pmatrix}+ \lambda_{2}\begin{pmatrix}
1\\
0\\
1
\end{pmatrix}+ \lambda_{3}\begin{pmatrix}
0\\
1\\
1
\end{pmatrix}$$
$$x = \lambda_{2}$$
$$y = \lambda_{3}$$
$$z = \lambda_{1}+\lambda_{2}+\lambda_{3}$$
The solution is unique too and thus $(u,v,w)$ is a basis of the vector space $\mathbb{R}^{3}$

Did I solve the task correctly and can you tell me better ways if there are some?
Comment: You can use the Gaussian elimination, get three lines which are not equal to zero, conclude that they are linear independent, and you got three vectors in a space of dimension 3, so it is a basis of the space.
Comment: The second part is enough since it gives a unique solution. (No solutions and it wouldn't be a basis because it wouldn't have enough vectors, more solutions and it wouldn't be a basis because there would be too many solutions). Also, I'd say that the first part is also enough on its own since it's probably known to you that any set in $\mathbb R^3$ with more than three vectors is linearly dependent.
Comment: For the second part, if the solution is unique, then the coefficient matrix has full rank, so its columns (your three vectors) are linearly independent. Another way of looking at it is that for there to be any solution to this system of equations, $(x,y,z)^T$ must lie in the column space of the coefficient matrix. You've shown that this column space consists of *all* or $\mathbb R^3$, which implies linear independence of the columns.
Comment: @Itay4 Thank you I didn't know that was possible! Would it also work with other matrices, such as $3 \times 2$?
Comment: @GitGud Would the second part really be enough? Because we cannot know if $\lambda_{1},\lambda_{2},\lambda_{3}$ equal zero or not. So I did the determinant thing first to know that it's not linearly dependent.
Answer: Once you have proved that the $3$ vectors are linearly independent, you automatically have that they are a basis for $\mathbb{R}^3$, since they generate a subspace with dimension $3$ of a space of dimension $3$ - so they must generate the entire space! As for proving linear independence, the determinant approach proposed in the question is general and works well.
In this particular case, a simpler approach is to see that $v-u=(1 0 0)^T$, $w-u=(010)^T$, $u=(001)^T$ form what is called the canonical basis of $\mathbb{R}^3$, so $u,v,w$ must also form a basis of $\mathbb{R}^3$.
Answer: You were done the second you proved they were l.i., since if you have n l.i. vectors of a given space of dimension n, then those vectors form a base.
Answer: Your answer is correct.
Any $3$ linearly independent vectors in a $3$-dimensional vector space are a basis for that vector space. You can check this, as you did correctly, by calculating that determinant. Notice that when you have a more complex $3$-dimensional vector space where vectors are for example functions, you can perform the same trick using the coordinates of those functions relative to a certain basis you do know. If the determinant of those coordinates is non zero, you have found a basis as well!
Comment: That's true. If the determinant of a matrix is non zero, then the columns are linearly independent. As the columns represent vectors, it is easy to see that the vectors are linearly independent.
Comment: Thanks! Some people said I can stop after this step (after knowing that determinant $\neq 0$). Can you confirm that?
Answer: Computing a determinant will always work to determine linear independence, but in some cases you can determine this by inspection. By definition, a set of vectors is linearly independent if the only linear combination of them that sums to zero has all zero coefficients. Observe that there's no way to generate a non-zero first component of a linear combination of $u$ and $v$, so the coefficient of $v$ in any linear combination that produces $0$ must be $0$. A similar observation shows that the coefficient of $w$ must also be zero, but that means that the coefficient of $u$ must be zero as well to eliminate the third component of the sum. As others have pointed out, at this point you're done because by the definition of dimension, this set of three linearly independent vectors must span the entire space.


How do I reduce N-distance Mininal Vertex Cover to Set Cover?

Question: Given on graph $G = (V, E)$ and an integer $N \ge 0$, $N-MVC$ is a minimal set of vertices such that each edge can be reached from some vertex in $N-MVC$ via at most $N$ edges.
An article named "Approximation algorithms for the L-distance vertex cover problem" by Chen Qiaoyun and Zhao Liang suggested that this problem can be somehow reduced to Set Covering problem. I'm asking for general advice on how such reductions can be performed and what's the theory behind them.
Any advice would be appreciated.
Answer: The idea is the same as in the $N=1$ case. You want to cover the edge set of the graph. For $N=1$, the covering sets are the stars in the graph; that is, for each vertex, you take the set of outgoing edges from that vertex. A vertex cover in the graph is essentially the same thing as a cover of the edge set using these sets.
What sets should you take instead if $N > 1$?

 For each vertex, the set of edges reachable in $N$ steps from that vertex.


render array with images

Question: I have this array in PHP
$link = array(
    '#type'    => 'link',
    '#title'   => 'link1',
    '#href'    => 'http://www.link1.example',
    '#suffix'  => '
',
  );

when i call the render() functions i get the correct html
link1

How i can change the above render array in order to include an image as a link?
In other words i want this as output from the render() function

I have tried to use the theme('image',$array) function but when the result of theme() is passed to the render() i don't see the image to my page but the actual html code.
Answer: The pre-render function for a 'link' element type is drupal_pre_render_link()...looking at the docs, you can pass these parameters:

#title: The link text to pass as argument to l().
#href: The URL path component to pass as argument to l().
#options: (optional) An array of options to pass to l().

You can force a link prepared through l() to display HTML by passing 'html' => TRUE as an option, so you should be able to do the same through the render array:
$image = theme('image', array('path' => 'images/link1img.png'));

$link = array(
  '#type'    => 'link',
  '#title'   => $image,
  '#href'    => 'http://www.link1.example',
  '#options' => array('html' => TRUE, 'title' => 'link1'),
  '#suffix'  => '
',
);

Comment: I tried the above code with no luck. The problem is that in my browser i get that
It's like the htmlspecialchar() PHP functions runs to my code and does not permit the img to appear!
Comment: I forgot to set the $options. OK now! :)
Answer: Better maybe to create a single render array which optionally can be altered through out the render process, ie.:
$image = array(
  '#theme' => 'image_formatter',
  '#item' => array(
    'uri' => '/images/link1img.png',
  ),
  '#suffix'  => '
',
  '#path' => array(
    'path' => 'http://www.link1.example',
    'options' => array(
      'attributes' => array(
        'title' => 'link1',
      ),
    ),
  ),
);

renders into:

If the image has been uploaded using the Field or File module, image_formatter can also be used to apply an image style, ie. thumbnail:
$image = array(
  '#theme' => 'image_formatter',
  '#image_style' => 'thumbnail',
  '#item' => array(
    'uri' => 'public://images/link1img.png',
  ),
  '#suffix'  => '
',
  '#path' => array(
    'path' => 'http://www.link1.example',
    'options' => array(
      'attributes' => array(
        'title' => 'link1',
      ),
    ),
  ),
);

renders into:

For more info, see https://api.drupal.org/api/drupal/modules!image!image.field.inc/function/theme_image_formatter/7

render array with images


Find $7^{1\,000\,000\,000\,000\,000} \bmod{107}$

Question: What is a shortcut to doing this kind of problem?  I know that 7 and 107 are both prime number; thus, I assume that has something to do with the appropriate approach/solution.  But beyond that I am not sure. Any ideas?
Comment: Do you know Fermat's little theorem?
Comment: @ThomasAndrews Since $53$ is a Germain prime it is easy to check that $7$ is a primitive root. Highly improbable this question was assigned without the OP knowing FLT :)
Comment: I don't see how your first sentence is related to the second, @N.S.
Comment: @ThomasAndrews Since the order of $7$ is $106$, calculating the powers of $7$ until they repeat is basically undo-able. And I am not familiar with any other trick which would work, and be taught before FLC.
Comment: That assumes it was an assigned problem. Back when I was in grade school, I encountered these sort of problems in a math game, without a class attached. Anyway, the method of repeated squaring reduces it to about 100 multiplications :) @N.S.
Answer: Hint 1:
Since $107$ is prime
$$7^{106} \equiv 1 \pmod{107}$$
Hint 2:
$$100 \equiv -6 \pmod{106}$$
Hence
$$1,000,000,000,000,000 \equiv 10 \cdot 100^{7} \equiv 10 \cdot (-6)^7 \pmod{106}$$
This is easy to compute.


UTF-8 - I don't understand this byte sequence

Question: I have a data provider that send me some data supposed to be coded with UTF-8. This data presents this sequence of bytes:
28 49 4e 54 e2 80 99 4c 29 20  (INT'L) => "(INT'L)"

For some reason when my java program fetch this data and store it in the database, the above sequence becomes:
28 49 4e 54 19 4c 29 20        (INT.L) => "(INT\u0019L)"

The java program is built on top of hibernate. It first fetches the data from the provider, stores it in an entity and then this entity is persisted in the database (Postgresql).
Why am I loosing the bytes (e2 80 99 becomes 19)  ?
How can I avoid this ?
Here is the core method used to transfer the data fetched from the provider to the entity:
import java.sql.Clob;

//...

public static String convertStreamToString(Clob clob) throws SQLException {
    if (clob == null) {
        return "";
    }

    BufferedReader br = null;
    StringBuilder result = new StringBuilder();

    try {
        br = new BufferedReader(new InputStreamReader(clob.getAsciiStream(), Charset.forName("UTF-8")));
        String lig;
        int n = 0;
        while ((lig = br.readLine()) != null) {
            if (n > 0) {
                result.append("\n");
            }
            result.append(lig);
            n++;
        }
    } catch (IOException ioe) {
         // Exception handling code ...
    } catch (SQLException sqlex) {
         // Exception handling code ...
    } finally {
        IOUtil.close(br);
    }

    return result.toString();
}

// ...

MyEntity entity = ...
oracle.sql.NCLOB clob = ...
entity.setProperty(convertStreamToString(clob));

@Entity
class MyEntity {
     @Column(name="prop", length=100000)
     private String prop;

     public void setProperty(String value) {
          this.prop=value;
     }
}

Comment: Can you show us the code ?
Comment: I want to see how you receive the data from your provider and how you enter it into Hibernate
Comment: Some component that you have strips the high byte from the characters: you would expect to get `\u2019` instead of `\u0019`. As for what causes this, we need to know more about how the data is put in the database and how you get it back out again. I'm pretty confident Hibernate is not a problem.
Comment: @BrianAgnew all the work is done by Hibernate...
Comment: Unless you can give us more details, you are unlikely to get anything other than general guesses.
Comment: @Joni It has been a nightmare for months for storing Oracle NCLOB to Postgresql with Hibernate... (we are fighting this bug: https://hibernate.atlassian.net/browse/HHH-7035)
Answer: You are using the getAsciiStream() to read the contents of a CLOB. As the name says, this method is usable only for ASCII; it breaks all non-ASCII characters.
Use the getCharacterStream method instead.
BufferedReader br = null;
StringBuilder result = new StringBuilder();

try {
    br = new BufferedReader(clob.getCharacterStream());
    ....

Comment: Well I must admit that the problem came from our workaround... but this workaround came from an Hibernate bug (https://hibernate.atlassian.net/browse/HHH-7035) !
Answer: I think DB column type should support UTF-8. In Oracle this is NVARCHAR, in Postgresql it is something like this
create table test (
    utf8fld varchar(50)
);

Comment: The data comes from an Oracle database where it is stored as `NCLOB`. This data is stored in Postgresql as `character varying(100000)`. Any impact ?
Comment: I mean if you have VARCHAR or CLOB column and you write a Unicode character like Ё it may be distorted, while NVARCHAR or NCLOB can store any character


User Interface/ Front End with Django

Question: I'm in the process of developing a website for travel planner. It is my first time to use a web framework which will be Django, I have no idea about it, but I'm in the learning process. I'm trying to figure out how I can integrate my front end or the HTML, CSS, And java script into dingo. I mean I'm going for Django as a back end and I don't know if Django has the ability to facilitate a front end design, I'm concerned a lot about design, so I want to feel free to play around with the front end. So, is there is any way that I can code my own pages in notpad++ and add them to Django as web pages or any platform I should use in order to integrate the front end with Django? Just because prior to my research about Django the front end templating that Django provides has other scripts than CSS and HTML and I honestly have no idea what does that mean! So a little feedback about this would really make a huge help!
Comment: https://jeffknupp.com/blog/2014/03/03/what-is-a-web-framework/
Answer: Django can be integrated with frontend easily.
Use python to write backend, use django template language to integrate frontend. Just be free to write your own html, css.
This should not be a problem.
As for the platform, it is also not a problem, python is cross-platform, so django can be used to most platforms.
Comment: If you really do not want to learn a kind of template language, then use ajax to separate front end from back end. But this means you have to spend more time(just my opinion).
Comment: Thanks! But I know the basic Html, not the Django template language, so any alternatives?
Comment: Django template language is easy enough that you can learn it within short time. If you want to integrate front end in Django, then you have to learn a kind of template language in order to render your front end pages.
Comment: would Bootstrap help in this situation ?
Comment: To be frank, no. Bootstrap just works in front end pages. Moreover, Bootstrap is just a collection of css and js(of course there are related resources like fonts).
Answer: First develop a backend api. In django you can have your views return json data.
In your front end you just call the django api and render the json data returned by the api.
If you are using Django for the first time, I suggest you first understand basics of django framework. MDN Django tutorial is a good place to start.

User Interface/ Front End with Django


Estimate the value of f at a given point

Question: Let $f: \mathbb{R}^2 \rightarrow \mathbb{R}$ be a differentiable everywhere. Assume $f(-\sqrt2,-\sqrt2)=0$, and also that
$|\dfrac{\partial f}{\partial x}(x,y)|\le |\sin(x^2+y^2)|$ and $|\dfrac{\partial f}{\partial y}(x,y)|\le |\cos(x^2+y^2)|$ for each $(x,y) \in \mathbb{R}^2\setminus \{(0,0)\} $. Prove that $|f(\sqrt2,\sqrt2)|\le 4$. I tried to use the Taylor expansion at the point $(-\sqrt2,-\sqrt2)$ as follows,
$f(x,y)=f(-\sqrt2,-\sqrt2)+ \dfrac{\partial f}{\partial x}(-\sqrt2,-\sqrt2)(x+\sqrt2)+\dfrac{\partial f}{\partial y}(x,y)(y+\sqrt2)+ \epsilon(||(x+\sqrt2,y+\sqrt2)||) $
$=\dfrac{\partial f}{\partial x}(-\sqrt2,-\sqrt2)(x+\sqrt2)+\dfrac{\partial f}{\partial y}(x,y)(y+\sqrt2)+ \epsilon(||(x+\sqrt2,y+\sqrt2)||).$
Using Cauchy-Schwartz inequality, we obtain the upper bound of $ \dfrac{\partial f}{\partial x}(-\sqrt2,-\sqrt2)(x+\sqrt2)+\dfrac{\partial f}{\partial y}(x,y)(y+\sqrt2)$ at the point $(\sqrt 2, \sqrt2)$ is 4. However, I don't know how to deal with the $\epsilon(||(x+\sqrt2,y+\sqrt2)||) $. I would appreciate it if someone could help me with this.
Answer: For $0\le t \le 1,$ let
$$g(t) = f((-\sqrt 2,-\sqrt 2) + t(\sqrt 2,\sqrt 2)).$$
Then $g$ is differentiable on $[0,1].$ Note that $g(1)-g(0) = f(0,0) - f(-\sqrt 2,-\sqrt 2).$ By the mean value theorem,
$$g(1) - g(0) = g'(c)\cdot 1 = \nabla f ((-\sqrt 2,-\sqrt 2) + c(\sqrt 2,\sqrt 2)) \cdot (\sqrt 2,\sqrt 2))$$
for some $c\in (0,1).$ Now $|\nabla f | \le 1 $ away from $(0,0),$ so Cauchy-Schwartz applied to the above gives $|g(1) - g(0)| \le 1\cdot 2 = 2.$
The same argument applies to $f(\sqrt 2,\sqrt 2)-f(0,0).$ Put this together with the above and use $f((-\sqrt 2,-\sqrt 2))=0$ to get the result.
Comment: thank you very much for providing another way to solve. Could you please help me to modify my solution using Taylor expansion?


drupalgap webapp setup into subdomain

Question: My main website is www.example.com. And I have 3 types content like: book,food,tutorial.
Now I want to serve all Book item from book.example.com subdomain. Is it possible to develop it with drupalgap using example.com node/content and same authentication?
[After installing drupalgap module, I download web-app drupalgap zip file, and set it to book.example.com but, CORS problem detected.]
anyone help please.
Answer: solving cors problem I just add configuration into my .conf file.
<code>Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Allow-Headers "Content-Type, X-CSRF-Token"
</code>
Answer: Sounds like you simply need to set the cookie domain in your settings.php to "example.com".
Comment: Hi @Karel, Thanx for your answer. I have changed but not working... :(

drupalgap webapp setup into subdomain


Unable to connect to local SQL Express (2008)

Question: I'm trying to get an installation of SQL Express 2008 working, but no matter what I do I can't connect to it with management studio.
I've enabled TCP/IP for the instance.
I've tried connecting with machinename\instance, .\instance, (local), etc etc etc.  Nothing works, and I always get the same message.
If I browse for a server, the only server listed is the local integration services, which I can connect to just fine.
The SQL server service is running (SQLEXPRESS), SQL Server Agent is not (and won't, can't enable it), and SQL Server Browser is.
Anyone have any suggestions on where to go next?  I've tried uninstalling EVERYTHING sql and reinstalling, no change.
Answer: I'm shotting in the dark without knowing the exact error message and the authentication method (integrated or SQL Server), but you could try install it to the default instance instead of using SQLEXPRESS, it simplifies the connection and you don't need to have the SQL Server Browser service enabled.
Note that AFAIK you can only change the instance at installation time, so you would need to uninstall and install it again.
Edit based on new information:
The error you described usually means that the servername/IP is not found or that the SQL server port is blocked by a firewall (or when the service is not running, which is not your case).
Try connecting  using just "localhost" or 127.0.0.1, and if this not work, check if your Antivirus/Firewall is blocking the port (you can use an utility like ZenMap (Download) for checking if port 1433 is open).
Also, do you added your Windows user to the list of administrators when installing SQL Server? This is necessary for connecting using Windows Authentication (previous versions of SQL did this automatically).
Comment: It was installed as the default instance, not a named one.

The error I'm getting is:
'A network-related or instance-specific error occured while establishing a connection to SQL server. The server was not found or was not accessible.  Verify that the instance name is correct and that SQL server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
Comment: I added my windows user account as well as the SA account.  I've tried all the connection methods with both accounts.

The only thing I haven't tried is the firewall/AV.  Will that actually cause a problem even when the SQL service is running on the same machine as management studio?  I'll give it a try anyway, definitely can't hurt!
Comment: I believe it will cause an issue with connections over TCP/IP but not over Named Pipes.
Comment: The firewall *shouldn't* be an issue in local connections, but some security solutions use configurations that could block some connections in certain situations (I have a recent experience with the free edition of an AV blocking all HTTP traffic in the network shield was enabled).
Answer: I've added a rule to the firewall, still no luck.  I'll try disabling my AV software, but I don't think that's blocking it.
At this point, I think I'm going to remove everything 2008 and install 2005.  I don't need any new functionality in sql 2008, so it can't hurt either.
Answer: Have you tried looking at your settings under the SQL Server Configuration Manager and going to SQL Server Network Configuration | Protocols for MSSQLSERVER? Verify that Named Pipes and TCP/IP are enabled. I remember having to manually turn this on for a couple of installations, not sure why it's not on by default.
Comment: Named pipes and TCP/IP are enabled, they weren't originally, but I enabled them a couple days ago.

One other thing I noticed is that in the properties for sql server, sql agent and sql browser there is a field for (running on x64), which I tried setting to yes, but as soon as I press apply and ok, then go back it resets to no.  Not sure if that has anything to do with this though.
Comment: Hmm that seems to be an option that was just added in R2, doesn't appear on my R1 install. I did just go ahead and install R2 express on my laptop to check this out and it has the same behavior. I'm going to assume this is merely a limitation of the express edition. I was able to connect using \SQLExpress as the server name, even when SQL Browser was stopped.

Perhaps a next step is to run the configuration check utility. This is included with the installer that you downloaded. Run the installer again and it will be listed under Tools, it should also be in the start menu.
Comment: The config checker didn't find any issues.  I removed everything sql 2008 related and installed 2005, worked first try.


An element is nilpotent in $\mathbb{Z}/n\mathbb{Z}$ if and only if all prime divisors of $n$ divide the element.

Question: Call an element $x\in R$ of a ring nilpotent if $x^m=0$ for some $m\in\mathbb{Z}^+$.

If $a\in\mathbb{Z}$ is an integer, show that the element $\overline{a}\in\mathbb{Z}/n\mathbb{Z}$ is nilpotent if and only if every prime divisor of $n$ is a divisor of $a$.

Here's my attempt at a proof. If $\overline{a}\in\mathbb{Z}/n\mathbb{Z}$, and there is a $m\in\mathbb{Z}^+$ so that $\overline{a}^m=\overline{a^m}=\overline{0}$. Then $a^m\equiv 0\mod n$ , and so there is a $k\in\mathbb{Z}$ with $a^m=kn$. Now suppose $p$ is a prime divisor of $n$, so that $n=lp$ for some $l\in\mathbb{Z}$. Then $a^m=(kl)p$, so $p$ divides $a^m$. By Euclid's lemma, $p$ must then divide $a$.
Conversely, suppose every prime divisor $p$ of $n$ divides $a$. Then $n=kp$ and $a=lp$. Fix $m\in\mathbb{Z}$, and take $a^m=l^mp^m$, and since $p=n/k$ we have $a^m=(l^m n^{m-1}/k^m)n$, so that $a^m\equiv 0\mod n$. I have a strong suspicion that my proof of this direction is flawed, because it seems to imply that every $m\in\mathbb{Z}$ has $a^m\equiv 0\mod n$. Are there any ways I can remedy this, and is the other direction fine?
Comment: Well, what makes you think $(l^mn^{m-1}/k^m)$ is an integer? The power you must take $a$ to to ensure $a^m\equiv0$ mod $n$ depends on the exponents in the prime factorizations of $a$ and $n$.
Comment: Nope. Does $7^2\mid 7^3$ imply $2$ divides $3$?
Comment: Good point! Are there any restrictions on $m$ that I can make so that it is?
Comment: Well, suppose $a=\prod p^{u_p}$ and $n=\prod p^{v_p}$. Can you go from there?
Comment: I'm not sure where this comes from. Could I have a reference?
Comment: Where what comes from? Do you mean the fact that we can factor numbers as products of prime powers? That's called the fundamental theorem of arithmetic, and should be taught well before students are exposed to the word "nilpotent."
Comment: Oh no I'm aware of the fundamental theorem of arithmetic but I still don't see what $m$ I should choose. Sorry if this is frustrating.
Comment: Well, if we factor $a=\prod p^{u_p}$, then $a^m=\prod p^{mu_p}$. In order for this to be divisible by $n=\prod p^{v_p}$, what can you say about the exponents $mu_p$ in relation to the exponents $v_p$?
Comment: Maybe that $u_p$ divides $v_p$?
Comment: I'm really not sure then. This must be so goddamn obvious.
Comment: Let me ask you this. Does $17^{10}\cdot23^5\cdot29^6$ divide $17^{12}\cdot23^4\cdot29^{10}$? Can you determine this without multiplying out huge numbers and doing long division, but instead simply comparing the exponents? How do you compare the exponents to determine if the first divides the second?
Comment: "This must be so goddamn obvious. "  Okay.  Does $7^2|7^3$?  Why or why not? And does 13^{9}|13^5$? Why or why not?
Comment: Suppose $n= 2^3\cdot 5^2\cdot 7\cdot 11^4$.  And $a = 2^4\cdot 3^2 \cdot 5\cdot 7^3\cdot 11$.  And we want to find an $m$ so that $n|a^m$ that is so that $(2^3\cdot 5^2\cdot 7\cdot 11^4)|(2^4\cdot 3^2 \cdot 5\cdot 7^3\cdot 11)^m$.  How would we do that?
Answer: Let us present an organised argument for this otherwise elementary statement. Let us write $\mathbb{P}$ for the set of all strictly positive prime integers (in other words, the set of nonzero prime natural numbers) and for arbitrary integer $n \in \mathbb{Z}$ let us define $\Pi(n)\colon =\{p \in \mathbb{P} \mid p \mid n\}$ to be the set of all natural prime divisors of $n$. It is an elementary exercise to establish the fact that the relations $m \mid n \Rightarrow \Pi(m) \subseteq \Pi(n)$ respectively $\Pi(mn)=\Pi(m) \cup \Pi(n)$ take place for arbitrary integers $m, n \in \mathbb{Z}$. Note that the latter property can be expressed by saying that the map $\Pi \colon \mathbb{Z} \to \mathscr{P}\left(\mathbb{P}\right)$ is a morphism between the monoids $(\mathbb{Z}, \cdot)$ and $\left(\mathscr{P}(\mathbb{P}), \cup\right)$.
Furthermore, for fixed $p \in \mathbb{P}$ let us introduce the map:
\begin{align}
&v_p \colon \mathbb{Z}^{\times}(=\mathbb{Z}\setminus\{0\}) \to \mathbb{N} \\
&v_p(n)\colon =\max\left\{k \in \mathbb{N} \mid p^k \mid n\right\}
\end{align}
and remark that $v_p(mn)=v_p(m)+v_p(n)$ for any two nonzero integers $m, n \in \mathbb{Z}^{\times}$ (in other words, $v_p$ is a morphism between the monoids $\left(\mathbb{Z}^{\times}, \cdot\right)$ and $(\mathbb{N}, +)$).
Let us also recall the fundamental theorem of arithmetic under the formulation that for every $n \in \mathbb{Z}^{\times}$ one has the relation $n=\mathrm{sgn}(n)\displaystyle\prod_{p \in \mathbb{P}}p^{v_p(n)}=\mathrm{sgn}(n)\displaystyle\prod_{p \in \Pi(n)}p^{v_p(n)}$, where $\mathrm{sgn} \colon \mathbb{Z} \to \{-1, 0, 1\}$ is the sign function of the totally ordered ring $\mathbb{Z}$. We also point out the important relation $m \mid n \Leftrightarrow (\forall p)\left(p \in \mathbb{P} \Rightarrow v_p(m) \leqslant v_p(n)\right)$, valid for arbitrary nonzero integers $m, n \in \mathbb{Z}^{\times}$.
Consider now a fixed natural number $n \in \mathbb{N}$ and write for simplicity $\mathbb{Z}_n\colon =\mathbb{Z}/n\mathbb{Z}$. Furthermore, for arbitrary integer $m \in \mathbb{Z}$ let us denote the residue class of $m$ modulo $n$ by $\overline{m}$. Assuming that $m \in \mathbb{Z}$ is such that $\overline{m} \in \mathrm{Nil}\left(\mathbb{Z}_n\right)$ we infer the existence of $k \in \mathbb{N}^{\times}$ such that $\overline{m}^k=\overline{m^k}=\overline{0}$. This entails $n \mid m^k$ and by virtue of the relations mentioned in the previous paragraph entails $\Pi(n) \subseteq \Pi\left(m^k\right)=\Pi(m)$ (the fact that $k\neq 0$ is required to make the latter relation of equality valid).
Conversely, assuming that the integer $m \in \mathbb{Z}$ satisfies the relation $\Pi(n) \subseteq \Pi(m)$ we infer that $p \mid m$ for each $p \in \Pi(n)$ and since two distinct primes are mutually prime we infer from an elementary proposition in arithmetic that $r\colon=\displaystyle\prod_{p \in \Pi(n)} p \mid m$. If $\Pi(n)=\varnothing$ we infer - in conjunction with $n \in \mathbb{N}$ - that $n=1$ and thus $\mathbb{Z}_1=\left\{\overline{0}\right\}$ is a null ring, all of its elements - $\overline{m}$ in particular - thus being nilpotent. If on the other hand $\Pi(n) \neq\ \varnothing$, since nonempty totally ordered sets have maxima we can in particular consider $h=\displaystyle\max_{p \in \Pi(n)}v_p(n)$. Since in general $p \in \Pi(m) \Leftrightarrow v_p(m)>0$ for any prime $p \in \mathbb{P}$ and integer $m \in \mathbb{Z}$, we ascertain that $h>0$. Since by construction $v_p(n) \leqslant h=v_p\left(r^h\right)$ is valid for each $p \in \Pi(n)$ (and therefore automatically for any $p \in \mathbb{P}$), it follows that $n \mid r^h \mid m^h$, which signifies that $\overline{m^h}=\overline{m}^h=\overline{0}$. As $h>0$, we conclude that $\overline{m} \in \mathrm{Nil}\left(\mathbb{Z}_n\right)$.


URL aliases and Entity Translation (menu name replacement pattern)

Question: I am using entity translation (Field translation) for my nodes, and set the menu name on each 'page'.
The menu itself is arrange to basically have a duplicate tree in the same menu each with a different language, for example:
main-menu
-item 1 english
--sub item 1 english <node/23>
-item 1 german
--sub item 1 german <node/23>

Now when i want to make URL aliases based on the menu it does not translate.
[node:menu-link:parents:join-path]/[node:menu-link]

Keeps the URL as english. i assume this is because of "node".
What replacement patterns could i use to make the URL aliases compatible with my entity translation?
Answer: Instead of using [node:menu-link], use [node:title] instead.


Erro ao instalar pacote "summarytools" no R

Question: Tentei baixar o pacote summarytools e informa esse erro:

library("summarytools")
Error: package or namespace load failed for 'summarytools':
.onLoad falhou em loadNamespace() para 'magick', detalhes:
chamada: set_magick_tempdir(tempdir())
erro: function 'Rcpp_precious_remove' not provided by package 'Rcpp

Como resolver?
Comment: Experimente atualizar o pacote *magick* (ou faça uma atualização completa dos pacotes instalados. Persistindo o problema, edite a questão para incluir detalhes como versão do R e das dependências do pacote, sistema, etc.
Comment: Veja [aqui](https://stackoverflow.com/questions/68416435/rcpp-package-doesnt-include-rcpp-precious-remove). E também [este outro post](https://stackoverflow.com/a/68569969/8245406), muito recente do SO em Inglês.
Answer: As aspas vão apenas no install.packages. Experimente rodar o comando library sem as aspas.
<code>install.packages("summarytools")
library(summarytools)
</code>


dense subspace of $\beta \Bbb N \times \beta \Bbb N$

Question: Let $\beta \Bbb N$ be a Čech-Stone compactification of the discrete space $\Bbb N$ and fix a point $p\in \beta \Bbb N\setminus \Bbb N$. Put $X=\Bbb N\cup \{p\}$ and $Y=\beta \Bbb N \setminus \{p\}$. I have two questions,

$Z=(X\times Y)\cup \{(p,p)\}$ is dense in $\beta\Bbb N\times \beta\Bbb N$ ?
$\{(p,p)\}$ is closed in $Z$?
Answer: $\newcommand{\cl}{\operatorname{cl}}$Yes, and yes. $\Bbb N\times\Bbb N$ is dense in $\beta\Bbb N\times\beta\Bbb N$, so $Z$ certainly is, and $Z$ is $T_1$, so all singletons are closed.
Answering two questions from the comments: Let $U=\{\langle n,n\rangle:n\in\Bbb N\}$.

Why is $U$ clopen in $X\times Y$? $\Bbb N$ is a dense set of isolated points in $\beta\Bbb N$, so every subset of $\Bbb N\times\Bbb N$ is open in $\beta\Bbb N\times\beta\Bbb N$ and hence in $X\times Y$. This also shows that $U$ has no limit points in $\Bbb N\times\Bbb N$. For each $n\in\Bbb N$ and $q\in\Bbb N\setminus(\Bbb N\cup\{p\})$, $(X\setminus\{n\})\times\{n\}$ is an open nbhd of $\langle p,n\rangle$ disjoint from $U$, and $\{n\}\times(Y\setminus\{n\})$ is an open nbhd of $\langle n,q\rangle$ disjoint from $U$. And since $p\ne q$, there is an $A\subseteq\Bbb N$ such that $A\in p\setminus q$; then $\Bbb N\setminus A\in q$, and $(\{p\}\cup A)\times\cl_Y(\Bbb N\setminus A)$ is an open nbhd of $\langle p,q\rangle$ disjoint from $U$. Every point of $(X\times Y)\setminus(\Bbb N\times\Bbb N)$ is of one of those three types, so $U$ has no limit points in $X\times Y$ and is therefore closed as well as open.
Why is $\langle p,p\rangle\in\cl U\cap\cl\big((X\times Y)\setminus U\big)$, where the closure is taken in $\beta\Bbb N\times\beta\Bbb N$ (and hence in $X\times\beta\Bbb N$)? The point $\langle p,p\rangle$ has a local base consisting of all sets of the form $\cl_{\beta\Bbb N}A\times\cl_{\beta\Bbb N}B$ with $A,B\in p$. If $A,B\in p$, then $A\cap B\ne\varnothing$, so let $n\in A\cap B$; then $$\langle n,n\rangle\in U\cap(\cl_{\beta\Bbb N}A\times\cl_{\beta\Bbb N}B)\;,$$ so $\langle p,p\rangle\in\cl U$. Moreover, $A\cap B$ is infinite, so we can choose distinct $m,n\in A\cap B$ and observe that $$\langle m,n\rangle\in(\cl_{\beta\Bbb N}A\times\cl_{\beta\Bbb N}B)\cap\big((X\times Y)\setminus U\big)\;,$$ so that $\langle p,p\rangle\in\cl\big(X\times Y)\setminus U\big)$ as well.
Comment: sorry i have another questions In this problem, $U=\{(n,n):n\in\Bbb N\}$ is a clopen subset of $X\times Y$ why? and why $(p,p)\in \overline{U}\cap \overline{(X\times Y)\setminus U}$ ?
Comment: @TXC: The answers are long enough that I added them to my answer instead of commenting.
Comment: @BrianM.Scott: what does $A\in p\setminus q$ (in line 7) and $A,B\in p$ (in second answer) means?  (principal ultrafilter, $p=\{A\subset \Bbb N: p\in A\}$ ? )
Comment: @George: $p$ and $q$ are ultrafilters on $\Bbb N$, so they are sets of subsets of $\Bbb N$; $A\in p\setminus q$ is a subset of $\Bbb N$ that belongs to $p$ but not to $q$, and $A,B\in p$ are subsets of $\Bbb N$ belonging to $p$.
Answer: All are yes.
Q1, $\mathbb N$ is dense in $\beta\mathbb N$, for $\beta\mathbb N$ is compactification of $\mathbb N$, and hence $\mathbb N \times \mathbb N$ is also dense in $\beta\mathbb N \times \beta\mathbb N$.
Q2, $\beta\mathbb N \times \beta\mathbb N$ is normal because it is Hausdorff compact, and hence $Z$ is at least Tychonoff (which we could see more). Note that the property Tychonoff is hereditary. And hence, $Z$ is $T_1$. Note that every point is closed in a $T_1$ space. So in the discrete space, every point is open and closed.


A statistic representative of time series data

Question: I am working on a project that requires me to analyse a couple of indices over a period of time, around 5 years. My scenario is as follows
I have a feature (% of people who has access to water) country wise. There are 5 percentages for different years (2014-2019)
e.g:

A - 78%, 80%, 81%, 85%, 88% - increasing trend
B - 78%, 85%, 80%, 81%, 88% - increasing, decreasing, increasing trend

Now I need one figure that represents these 5 numbers, something like an average. I know average will not work here, case the average of both the instances A, B would be the same. I need a number that gives something like the mean, variance of the distribution and an indicator of the trend (+/-)
Please let me know what I should be looking into, or if I have missed something here
TIA
=)
Answer: You might cluster your time series in five dimensional space, to see how many types you have. Done that, a good summary might be the centroid of the cluster each series belongs to, possibly suplemented by the distance to such centroid. K-means clustering seems appropriate here.


Exact sequence proof

Question: Show that if $R$ is an integral domain and $0\rightarrow{}A\xrightarrow{f}B\xrightarrow{g}C$ is an exact sequence of left
$R$-modules then $0\rightarrow{}T(A)\xrightarrow{f_T}T(B)\xrightarrow{g_T}T(C)$ is an exact sequence as well.
$T(A)$ is set of all torsion elements of $A.$
We know that $g$ is surjective, $f$ is injective and $\operatorname{im}f=\ker g.$ We want to show $g_T$ is surjective, $f_T$ is injective and $\operatorname{im}f_T=\ker g_T.$ Because $f_T, g_T$ are only restrictions of $f,g$ we have only to show $\operatorname{im}f_T=\ker g_T$. Am I correct?
How to do that?
Comment: The function $g$ need not be surjective. We only check exactness when there are two consecutive morphisms in the sequence.
Comment: What have you tried?
Comment: @jgon Nothing, I don't have any idea
Answer: You are right in that we only have to show im$f_T=$ ker$g_T$. The injectivity of $f_T$ is clear. And im$f_T\subseteq$ ker$g_T$ is also clear.
Say $b\in$ ker$g_T$. Then $b\in$ ker$g$ $\cap$ $T(B)$. By exactness of the previous sequence, $b\in$ im$f$. Say $f(a)=b$. WTS $a\in T(A)$. We have $rb=0$ for some $r\neq 0$. Then $rb=rf(a)=f(ra)=0$. The injectivity of $f$ implies $ra=0$. Thus $a\in T(A)$.
That's the idea.
Answer: As @Joshua Mundinger mentioned, $g$ need not be surjective.
The statement $f_T$ is injective can be obtained directly by considering $f$ is injective. (If $f_T(x) = 0$, then ...)
About $\textrm{im}f_T = \textrm{ker}g_T$, here's a hint:
$$\textrm{ker}g_T = \textrm{ker}g \cap T(B) = \textrm{im}f \cap T(B).$$

Proof of $\textrm{im}f_T = \textrm{ker}g_T$ (by the hint)
Since $f_T$ is the restriction of $f$, $\textrm{im}f_T \subseteq \textrm{im}f \cap T(B) = \textrm{ker}g_T$.
On the other hand, given $b \in \textrm{ker}g_T = \textrm{im}f \cap T(B)$. We may write $f(a) = b$ for some $a \in A$. Since $b \in T(B)$, there exist non-zero $r \in R$ such that $rb= 0$. Hence $f(ra) = rf(a) = rb= 0$, which implies $ra = 0$ since $\textrm{ker} f = 0$. Thus $a \in T(A)$ and therefore $b= f(a) = f_T(a) \in \textrm{im}f_T$. Our proof is complete.

Exact sequence proof


What is the difference between kernel, bias, and activity regulizers, and when to use which?

Question: I've read this post, but I wanted more clarification for a broader question.
In Keras, there are now three types of regularizers for a layer: kernel_regularizer, bias_regularizer, activity_regularizer.
I have read posts that explain the difference between L1 and L2 norm, but in an intuitive sense, I'd like to know how each regularizer will affect the aforementioned three types of regularizers and when to use what.
The motivation for my question is that my understanding is that regularizers are usually applied to the loss function. However, they're even being added to bias term. I'm not able to wrap my head around why one would think to do this, let alone be able to discern when to use L1 and L2 for the bias regularizer. Hence, I wanted to get an overall understanding of all three entities that regularizers are applied on and in general know how the 2 kinds of regularizers can affect each of those entities at a high level.
Answer: What is the difference between them?
You have the regression equation $y = Wx+b$, where $x$ is the input, $W$ the weights matrix and $b$ the bias.

Kernel Regularizer: Tries to reduce the weights $W$ (excluding bias).
Bias Regularizer: Tries to reduce the bias $b$.
Activity Regularizer: Tries to reduce the layer's output $y$, thus will reduce the weights and adjust bias so $Wx+b$ is smallest.

When to use which?
Usually, if you have no prior on the distribution that you wish to model, you would only use the kernel regularizer, since a large enough network can still model your function even if the regularization on the weights are big.
If you want the output function to pass through (or have an intercept closer to) the origin, you can use the bias regularizer.
If you want the output to be smaller (or closer to 0), you can use the activity regularizer.
$L_1$ versus $L_2$ regularization
Now, for the $L_1$ versus $L_2$ loss for weight decay (not to be confused with the outputs loss function).

$L_2$ loss is defined as $w^2$
$L_1$ loss is defined as $|w|$.

where $w$ is a component of the matrix $W$.

The gradient of $L_2$ will be: $2w$
The gradient of $L_1$ will be: $sign(w)$

Thus, for each gradient update with a learning rate $a$, in $L_2$ loss, the weights will be subtracted by $aW$, while in $L_1$ loss they will be subtracted by $a \cdot sign(W)$.
The effect of $L_2$ loss on the weights is a reduction of large components in the matrix $W$, while $L_1$ loss will make the weights matrix sparse, with many zero values. The same applies to the bias and output respectively using the bias and activity regularizer.
Comment: If you apply $L2$ weight decay, the network will try to be less sensitive to small changes. If you apply $L1$ weight decay, it goes further, the network will try to ignore some inputs altogether.
Comment: Can you expand on the last paragraph you wrote? Particularly, what is the consequence of the network when there is reduction in the large components (does the network become more erratic to small changes since the big components no longer over shadow the smaller ones) and what does it mean if there are  more 0 values? Does that mean the network becomes less erratic?
Comment: The network will be less sensitive to small changes (eg. noise) since the matrix $W$ will have small weights.
Comment: Sorry, I'm slightly confused. You previous comment refers to which loss, L1?
Comment: Please look at this demonstration, maybe it will be clearer.
http://nghiaho.com/?p=1796
Comment: Is the sign function here returning $\{0, 1\}$ or $\{-1, 1\}$?
Comment: @EduardoReis: {-1, 1} since |w| = sign(w) * w
Answer: kernel_regularizer acts on the weights, while bias_initializer acts on the bias and activity_regularizer acts on the y(layer output).
We apply kernel_regularizer to penalize the weights which are very large causing the network to overfit, after applying kernel_regularizer the weights will become smaller.
While we bias_regularizer to add a bias so that our bias approaches towards zero.
activity_regularizer tries to make the output smaller so as to remove overfitting.
Answer: I will expand upon @Bloc97 's answer about the difference between $L1$ and $L2$ constraints, in order to show why $L1$ may drive some weights to zero.
In the case of $L2$ regularization, the gradient of a single weight is given by
$$ \delta w = u - 2pw$$
where $u$ is the input from the previous layer being multiplied by weight $w$, and $p$ is parameter weighting the $L2$ penalty.
Without loss of generalization, assume that $u>0$ and $w>0$.
Then the sign of $\delta w$ is given by
$$ sign(\delta w) = sign(\frac{u}{2p} -w)$$
showing that $L2$ regularization will drive $w$ to grow bigger if $w$ drops below $\frac{u}{2p}$.
On the other hand, in the case of $L1$ regularization, the gradient of a single weight is given by
$$ \delta w = u - p$$
so the sign of $\delta w$ is given by
$$ sign(\delta w) = sign(u-p)$$
showing that $L1$ regularization will drive $w$ to grow smaller when the input $u$ is smaller than the $L1$ regularization parameter $p$.
Effectively, $p$ is functioning as a threshold such that, whenever $u$ is less than $p$, $L1$ regularization will push the weight to grow smaller, and whenever $u$ is greater than $p$, $L1$ regularization will push the weight to grow larger.
The above is a local linear approximation of a nonlinear system:  $u$ is actually an average over, for example, all the samples in a batch, and $u$ also changes with with each update.  Nevertheless, it gives an intuitive understanding of how $L1$ regularization tries to drive some weights to zero (given large enough $p$).


ASP.NET MVC Scaffolding para qualquer tabela

Question: Alguém sabe uma forma de eu gerar CRUD automático para minhas tabelas do banco usando MVC?
Tenho 5 tabelas e gostaria de gerar SinglePage apps de forma automática para elas, sem precisar gerar várias views/controllers. A ideia é criar telas de administração básicas para gerenciar estas tabelas que são de controle interno meu e não preciso de designs trabalhados.
A ideia é se surgir outra tabela no futuro eu só precise selecionar em um combobox qual eu quero gerenciar e já seja listados os valores no grid com botões de insert/update/delete.
Já pesquisei algumas coisas mas o que encontro ainda exige um trabalho considerável para fazer o Scaffolding e cria vários arquivos views/controller.
Comment: Você quer gear as `Views` a partir da sua base de dados?
Comment: @rodrigorf Você está usando Code First?
Comment: @RenanCarlos Database First.
Comment: @JcSaint, exato, gerar as views/controllers, mas queria saber se existe uma forma de gerar uma view/controller genérica que atendesse várias tabelas. Se não for possível, pelo menos gerar tudo de forma automatica e já com os métodos CRUD.
Answer: Sim, usando o Entity Framework Power Tools.
Só que tem um problema: essa ferramenta, além de ser um Beta, não foi atualizada para o Visual Studio 2015.
Assim sendo, este cara atualizou a ferramenta pra gente. O link para ela está aqui.
Depois de instalar o VSIX, você precisará voltar o .NET Framework para a versão 4.5.1, senão não funciona.

Feito isso, clique com o botão direito no seu projeto e selecione a opção Entity Framework > Reverse Engineer Code First.

Escolha o servidor e o nome do banco de dados que você deseja fazer o Scaffolding. A ferramenta irá replicar para o código todas as tabelas do banco de dados selecionado.

Se tudo foi feito certo, a ferramenta fará o Scaffolding em segundo plano.
Duas observaçoes:

A ferramenta cria um diretório chamado Mapping com os mapeamentos das entidades em classes separadas. Não é incorreto usar dessa forma, mas deve ser desecorajado por ser uma abordagem antiga e prolixa, que dificulta a manutenção do projeto;
A ferramenta não faz Scaffolding de Controllers e Views: somente de Models. Para os demais ítens de Scaffolding, você terá que usar o Scaffolding nativo ou o MvcScaffolding.
Comment: Agradeço o post bem completo Cigano, pelo que entendi pelo visto não vou encontrar uma ferramenta que gere esse controllers/views para mim de forma fácil, mas fiquei com a sensação que esse Power Tool gera apenas as Entidades sem CRUD, me corrija se estiver enganado, ainda vou testar :).  Outra coisa, você comentou sobre não ser uma boa prática usar esse modelo de mapping, saberia indicar um outro caminho?
Comment: Fazer tudo numa ferramenta só não existe, de fato. Muita informação dos mapeamentos não precisa ser usada porque o próprio *Model* já expressa o relacionamento. As demais informações podem ser substituídas por decoração de atributos. Neste caso, seria necessário você antes modificar o *Model* trazido do banco pra depois eliminar a classe de mapeamento.
Comment: Show. Já facilita minha vida de qualquer forma. Obrigado


Scalpel technique in Guitar

Question: What is Scalpel technique in Guitar ?
I searched on internet but does not show proper results.It says <code>"Scalpel - move only your thumb and forefinger"</code>
Can you please guide me through videos,images that can be helpful.
Answer: In 20 years of playing guitar, I've never heard of this. The description would apply to Travis picking which uses only the thumb and forefinger (variations use additional fingers). Using the two fingers gives more of a point--counterpoint effect than can be achieved with just a single finger, and makes syncopated accompaniments in country/folk/blues styles very simple to execute. The Fleetwood Mac song Never Going Back Again has a very nice example of an advanced Travis-picking style (incorporating other fingers and arpeggios and rolls and flourishes).
A similar technique is used in the Beatles' song Blackbird. In this song, the thumb and middle fingers pluck a bass note and a 10th (octave+third) above together, and then the index finger plucks a note in between the other two on the backbeat. This third note then determines the chord which was suspended on the primary beat. It gives an effect similar to syncopation, although the backbeat is not given any dynamic emphasis.
But t The name Scalpel suggests that folk-blues may not be the appropriate style from which to interpret this. The word is more suggestive of Heavy Metal or a sub-genre like Speed-Metal or Thrash. If this is the case, then it probably refers to a technique using a pick where the hand is rigidly anchored to the bridge of the guitar (best with a fixed-bridge electric like a Gibson-style without a tremolo). This way, you can still control what you're doing sonicly whilst bouncing wildly around the stage. Since the hand and forearm are rigidly anchored, the muscles of the fingers have to do all the work plucking the strings. This limits your dynamic range, but that is not so much of an issue in these styles.
After watching the video in the linked thread from the comment, this last guess is closer to the mark. It's a tremolo technique apparently. As PD in the first video comments, being rigid will lead to fatigue. And allowing more muscles to help will distribute the effort. From a Hatha Yoga perspective, even your left big toe should be doing it's part to help: gripping the floor ever so slightly to counterbalance the other muscular forces.
This video appears to lay-out the exact differences among the different tremolo styles. Scalpel apparently involves just the thumb and forefinger, as you had already gathered, with the hand anchored but not rigid.
There are a number of conflicting physical phenomena that make it difficult to find a comfortable balance. For a nice tremolo picking, you want an even, sustained sound.
If you choke-up on the pick and allow only sharp tip of the point to attack the string, the friction will be low and less energy will be lost into the strings. Less friction means less sound, less oscillatory power is being transferred to the strings. Also, again since little energy is transferred, it will require some musculatory action to stop and turn around.
If you allow more of the pick to attack the string, you may find a sweet-spot where the energy lost from the movement of the hand is exactly what your hand needs to do the stopping. Then you can factor-out that muscle action. Your fingers and wrist don't need to expend energy on the slow-down turn-around. As a baseball analogy, you don't try to land on home plate, you aim for a spot past the plate so you don't throw away your speed, you pass the plate at full-tilt. I suppose the analogy doesn't really hold because our poor ballplayer is obliged to trip over the plate every time.
Ehrm. Does that make any sense?
The video also talks about changing the angle of the pick so there's more edge. This gives a scraping, shimmering effect somewhat evocative of a Sitar which uses a wire plectrum striking the string edge-on. That's friction. It pulls energy out of the motion, so adding this effect will require more expenditure from the muscles to compensate.
Comment: Check this link : http://www.ultimate-guitar.com/forum/showthread.php?t=1187799&goto=nextnewest
Comment: @Siddharth Take a look at this one: [Differences of Alternate, Scalpel and Sarod Picking](https://www.youtube.com/watch?v=thx-HKhb-X8)
Comment: Still more to come as my learning for guitar progresses :)

Scalpel technique in Guitar


How to Grant Apache Access to Directory

Question: I am currently getting a locally hosted website up and running, but have encountered problems in accessing it from the host computer and other computers, as well. I have already created exceptions in the firewall and forwarded port connections. I have created a .htaccess file with the proper code, and edited all other files to allow the connection. When I use the URL of the website on the local host, it works, which is to be expected. However, when I use my IP address on any computer, I receive the following error (the IP address was X-ed out by me for privacy):
Forbidden
You don't have permission to access / on this server.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at XXX.XXX.X.XX Port 80

I have done more than enough research, and believe that Apache might not have permission to access the directory of the website. I am using a WAMP server that is updated completely as of 7/5/2015. Any help getting this site up and running would be appreciated. If you would like more information, just leave a comment and I will edit this post with whatever you need. Thanks!
Comment: Start by turning up the logging, and it should say which policy is preventing the access.
Comment: Since it otherwise works on the local host, check your Listen directive. Look for allow/deny directives that limit it to 127.0.0.1, especially on the Location directive for the root directory.
Answer: The usual reason I've seen for this problem is that you create the files so they are owned by you (the user that you are logged in as).  You can access the files locally because you own them.  When you try to access them remotely, they are accessed by user "apache" or whatever user your web server runs as.  Change the permissions so that the web server can access the files.
Comment: Task Manager has a user name column to tell you what the apache process runs as.  File properties has a security tab which tells you the owner and allows you to edit permissions.
Comment: Sorry, if this seems simple to you, but how does one do what you said on a Windows 8.1 computer?
Answer: Probably you have project moved from apache-2.2 to apache-2.4. Since v2.2 some changes have been introduced to the config files syntax, especially with access definitions. While apache before 2.4 have had the next syntax
Order allow,deny
Allow from all

the 2.4+ versions have the next syntax
Require all granted

Please read carefully notices about upgrading from 2.2 to 2.4
http://httpd.apache.org/docs/2.4/upgrading.html
Comment: Unfortunately, this is not the case. I had already done so, and it did not solve the problem. I appreciate your time, though!
Comment: This was the case for me thank you!

How to Grant Apache Access to Directory