Assessing the effect of an intervention on a time series (in R): terrible Ljung-Box p-values

Question: I am trying to test the effect on the heat flux between indoors and outdoors before and after removing insulation.
Briefly, I have 26 sensors on a wall, measuring heat flow between indoors and outdoors over a number of days. The wall was part of a real world experimental setup so that the insulation on the wall was removed halfway through the experiment.  What I care about is to have a measure of the effect of the removal of the insulation (I am not interested in any form of forecasting).  I am exploring the use of a SARIMA/ARIMAX models with one regressor because, aside from the removal of the insulation, the heat flow between indoors and outdoors was affected by daily cyclical and random environmental effects (heating on or off, daily temperature changes, wind, etc).  Here I will present that data and analysis of one sensor.  My data has been collected hourly, and I have transformed the variable 'insulated' 'not insulated' as a factor of 0s and 1s as indicator.
heat.flux = c(8.677048,6.558642,5.920314,5.583614,5.373176,5.253928,4.938272,7.358305,9.743266,10.46577,11.06201,10.90067,11.49691,13.15236,12.10017,10.60606,10.45875,10.03788,9.588945,9.287318,8.578844,8.024691,10.26936,11.8757,10.20623,8.634961,8.305275,8.101852,8.12991,7.947531,7.814254,10.40264,13.08221,14.3729,14.94809,15.08838,15.20763,15.75477,14.57632,12.79461,11.97391,10.97082,10.33249,9.701178,9.715208,9.083895,10.63412,12.07912,9.736251,7.638889,6.453423,5.983446,5.499439,5.099607,4.70679,6.972503,9.259259,9.981762,10.24832,10.17116,10.27637,10.27637,9.546857,7.568743,7.168911,6.867284,6.705948,6.916386,8.319304,8.424523,11.41274,13.52413,11.70034,9.532828,8.957632,9.07688,9.694164,9.301347,9.048822,12.28255,14.95511,15.22868,15.24972,15.12346,15.08838,15.17256,13.68547,12.18434,12.1633,12.13524,11.81257,11.58109,11.44781,11.27946,13.87486,15.92312,14.07828,11.90376,10.46577,9.518799,8.978676,8.803311,8.684063,11.65123,14.39394,15.69865,16.61756,16.828,16.83502,16.16863,14.23962,12.19837,12.09315,11.5881,11.20932,10.50786,10.59203,10.64815,13.51712,15.71268,13.92396,12.10718,12.2615,11.65123,11.05499,10.31846,9.834456,12.9349,15.41807,15.78283,15.8179,16.11953,15.95118,15.63552,13.1243,11.22334,10.21324,8.705107,7.526655,6.15881,5.30303,5.597643,8.599888,11.17424,9.631033,8.038721,7.638889,7.203984,7.161897,6.76908,6.888328,9.518799,12.40881,13.21549,14.28872,14.43603,14.8078,14.81481,13.60129,12.59119,11.86167,11.91779,11.73541,12.04405,11.51796,11.74242,13.7486,15.85999,14.84989,12.63328,10.68322,9.343434,8.592873,8.333333,8.445567,10.97783,13.82576,15.12346,16.58249,17.61364,18.30808,19.10774,17.97138,16.62458,15.867,16.07744,15.63552,16.0073,15.42508,15.01122,17.10157,18.94641,22.44669,18.94641,16.01431,14.55527,13.88889,12.77357,11.66526,12.46493,15.41807,16.75786,17.27694,17.03143,16.84905,16.828,16.02834,16.35802,16.04237,15.03928,14.00112,14.1344,13.86785,13.99411,15.30584,18.20286,19.49355,16.16162,14.05022,12.05107,12.27553,13.01207,12.5491,13.72054,16.91218,18.62374,18.79209,20.80527,19.50758,20.18799,20.63692,18.49747,17.25589,17.38215,18.40629,18.60269,19.12177,18.66582,21.09989,24.45286,26.71156,23.54798,20.01964,17.98541,14.83586,14.31678,15.15152,15.30584,17.95735,19.71801,20.30724,20.19501,20.2862,20.1459,20.10382,18.20988,16.54742,15.22868,13.96605,12.71044,11.61616,10.71829,12.12121,14.77273,14.04321,12.44388,10.94978,10.2413,9.708193,9.638047,9.322391,11.27245,14.24663,14.77273,14.75168,14.92705,15.47419,15.48822,14.73765,13.68547,12.65432,12.35269,12.34568,12.32464,12.7385,12.84371,14.16947,17.34007,17.09456,15.0954,13.40488,11.70735,10.8165,10.64815,12.01599,13.55219,16.7298,17.45932,17.61364,19.58474,20.02666,19.79517,19.38833,17.32604,16.11953,15.62851,15.01122,14.70258,14.5693,14.35887,16.28086,18.69388,18.92536,16.56846,15.97222,13.34877,12.81566,12.04405,13.23653,14.1835,16.75786,17.55752,17.98541,18.85522,18.8482,19.02357,18.96044,17.31201,15.42508,14.38692,13.57323,12.36672,12.03002,11.41274,13.15236,15.88103,14.66049,12.8858,11.67228,11.03395,9.399551,8.375421,8.073793,10.6271,13.57323,13.61532,14.31678,14.73765,15.08838,15.62149,16.6807,15.28479,14.07127,13.14534,12.61223,12.57015,12.02301,12.17031,14.33782,18.83418,20.45455,18.67985,18.40629,16.51235,14.45006,14.61841,15.20763,15.57941,18.06958,19.88636,20.51066,21.633,23.24635,24.28451,24.70539,24.19332,22.81145,21.97671,21.58389,21.3945,21.21212,20.89646,21.1069,23.86364)

insulation = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)

First off, the time series plot of the heat flux is this (the red line is when the insulation is removed):

Than this are the ACF and PACF plots of the same data:

For my data, an stl() decomposition, run as stl(ts(heat.flux, frequency = 24), 'period')
shows a strong 'seasonal' (i.e daily) component and a trend in the series.

Firs off I am trying to determine the best parameters for a SARIMA or ARIMAX model so that I can get an estimation of the effect removing the insulation. Despite the fact I can produce the ACF and PACF plots there is no way I can figure out the proper orders, so I load the library forecast and I run:
library(forecast)
auto.arima(ts(heat.flux, frequency = 24), xreg = insulation, max.p = 10, max.q = 10, max.P = 10, max.Q = 10, stationary = F)

The reason why I do not specify a stationary model is because of the trend I see with stl() and because I assume an effect of removing the insulation.
from auto.arima() I get:
Series: ts(heat.flux, frequency = 24)
ARIMA(2,0,2)(1,0,1)[24] with non-zero mean

Coefficients:
         ar1      ar2      ma1      ma2    sar1     sma1  intercept  carp.hour$interv
      1.9414  -0.9495  -0.7423  -0.1793  0.9717  -0.6009    11.2449            4.3338
s.e.  0.0231   0.0221   0.0570   0.0544  0.0104   0.0544     2.1075            0.5548

sigma^2 estimated as 0.4484:  log likelihood=-411.28
AIC=840.55   AICc=841.03   BIC=876.11

If I try to use the TSA package and use arimax() with those orders I get basically the same stuff:
library(TSA)
arimax(ts(heat.flux, frequency = 24), xreg = insulation, order = c(2,0,2), seasonal = list(order = c(1,0,1), frequency = 24))
Series: x
ARIMA(2,0,2)(1,0,1)[24] with non-zero mean

Coefficients:
         ar1      ar2      ma1      ma2    sar1     sma1  intercept    xreg
      1.9414  -0.9495  -0.7423  -0.1793  0.9717  -0.6009    11.2449  4.3338
s.e.  0.0231   0.0221   0.0570   0.0544  0.0104   0.0544     2.1075  0.5548

sigma^2 estimated as 0.4484:  log likelihood=-411.28
AIC=838.55   AICc=839.03   BIC=874.11

And all is apparently well (Irrespective of the function I choose I get an estimate of the effect of the removal of the insulation and a se with it with is what I want).  Unfortunately, when I test the fit of this model with the function sarima() from the astsapackage I get significant Ljung-Box p-values for all my sensors and for all the lags:
library(astsa)
sarima(ts(heat.flux, frequency = 24), p = 2, d = 0, q = 2, P =1, D = 0, Q = 1, S = 24, xreg = insulation)
$fit

Call:
stats::arima(x = xdata, order = c(p, d, q), seasonal = list(order = c(P, D,
Q), period = S), xreg = xreg, optim.control = list(trace = trc, REPORT = 1,
reltol = tol))

Coefficients:
         ar1      ar2      ma1      ma2    sar1     sma1  intercept    xreg
      1.9414  -0.9495  -0.7423  -0.1793  0.9717  -0.6009    11.2449  4.3338
s.e.  0.0231   0.0221   0.0570   0.0544  0.0104   0.0544     2.1075  0.5548

sigma^2 estimated as 0.4484:  log likelihood = -411.28,  aic = 840.55

but the plot that comes with is shows that at every single lag the Ljung-Box statistics is significant:

What is going on?  To sum it up:

which of these models is the most correct to estimate the effect of insulation?
why are the Ljung-Box p-values all significant?  I would have though that the ARIMA/ARIMAX/SARIMA would have sorted that issue
If the orders calculated by auto.arima() are the problem, how could I find them in a different way (which is computationally feasible and does not take days).

Finally, two notes.  I also have collected variables such as internal and external temperatures, windspeed, etc, but I would have though that integrating these in the model would be superfluous given the fact it is already an ARIMA model to start with.  Second, I am not at all wedded to this kind of analysis, but I am aware that a straightforward linear model would not be acceptable given the autocorrelation between the data points.
Comment: Looks like you have a cyclical pattern with a length of 69 in your data, do you know why this would be the case ?
Comment: That would be something happening every 2.875 days, which in my opinion is 100% spurious
Comment: Do you believe that there would be a second seasonal pattern?. Looking at the trend portion of stl, I do see a cyclical pattern.
Comment: With regards to your first question: all 3 models show the same effect of 4.3338, because you have used the same ARMA order in all 3 models. I'm not sure about your question. All 3 models are identical!
Comment: Concerning cyclical patterns, the cyclical temperature change during the day affects the heat flux, and so does th heating of the ouse that is on twice a day (morning and evening).  I am aware that the models are the same, but the issue is, `sarima` does give some diagnostics, and the Ljung-Box p-values are very worrying. Having said that is is difficult to figure out another way of finding the parameters for the model that does not use `auto.arima()`
Answer: All the functions you've used call stats:::arima() or something based on it, so they will return identical models given the same orders. You could get some of the same graphical output using tsdiag() applied to the object returned by auto.arima().
The model has correlated residuals, which will make the standard errors on the coefficients biased, and the forecast prediction intervals biased. It will not, however, bias the point forecasts themselves or the regression coefficient estimates. If your primary interest is in the coefficient for insulation, then what you have is ok although the standard error is incorrect.
You could ask auto.arima() to try harder by using stepwise=FALSE and approximation=FALSE. However, I suggest you reduce the values of max.P and max.Q to 2 (the defaults). The order selection will take a long time -- probably at least 20 minutes -- for a series that long with these settings.
Comment: Hi Rob, thanks for your answer.  I notice that the Ljung-Box statistics are substantially better when I use `tsdiag()` on the results on `auto.arima()` -- there is a discrepancy with the Ljung Box results from `sarima()`, something I think I should flag up.  Also, I am just interested in the effect of insulation, but it would be useful to have a reasonable standard error -- I am presenting these results to people who are desperate for 'p-values' and I think I should give them at least some reasonable estimate of the uncertainty around the parameter.


time series model with additional, time-independent regressors?

Question: How does one introduce time-independent regressors into a time-series model?
Let's say that you want to model house prices based on mortgage valuations from the past 5 years AND based on additional regressors such as house size (time-independent) and population density in the area (time-dependent), as well as years since construction (time-dependent).
Would such regressors be called external? Is this doable with AR/MA/etc models? If so, could you point me to the relevant approach? Thanks!
Comment: https://autobox.com/pdfs/regvsbox-old.pdf discusses the use of time-dpendent regressors . The method is referred to as Transfer-Function modelling and sometimes as dynamic regression . This will help you https://stats.stackexchange.com/questions/353491/how-to-use-dynamic-regression-models-in-r-to-forecast-future-sales/353906#353906 .
Answer: For time dependent regressors, it is pretty straightforward. Many classes of time series models can handle them, including from the ARIMA family (ex: ARIMAX and regression with ARIMA errors), BSTS, Facebook Prophet, and others.
The tricky part is time independent regressors: Most people don't realize that time independent regressors are of no use whatsoever unless you are modeling multiple time series at the same time.
Consider your housing example: If you are trying to model the price of a single house over time, which has a fixed size, then there is no way such a model can capture the effect of the size of the house on the price, since it hasn't "seen" the effect of any other sizes on the price in order to determine what the right coefficients/weights should be.
This means you will have to use an approach that allows you to model multiple time series together, while including the effect of the time-independent variables. Here are a couple of ways you might be able to pull that off (there might be more, but I am not familiar with them):

If your time independent variables are categorical or discrete valued, you can use a hierarchical/grouped time series forecasting approach, where you group your time series along the different possible values of your time independent variable. The advantage of this approach is that you can use most of the text book time series methods (ARIMA, Exponential Smoothing, etc...) in concert with a hierarchical forecasting scheme. The downside of this approach is that it doesn't allow for continuous time-independent variables, and you have to make some assumptions before hand on the importance and the effect of your time independent variables (e.g. should I aggregate my time series based on zip code first, then based on number of rooms, or the other way around?).
If your time independent variables are continuous, you can use a general machine learning based approach like XGBoost, or Deep Learning models. The advantage of this approach is that it can handle any type of additional variables because this type of ML model is usually very flexible. The downside of this approach is that ML models are much harder to implement (coding, Hyperparameter optimization, etc...) than regular time series models, and it is usually difficult to interpret their output, since they tend to highly non-linear and "black box" in nature.

In response to the comment about how to include size in a hierarchical model:
Simply transforming the sizes to a discrete value instead of continuous one won't help much, because you would still end up with a very large range of nodes in your hierarchy, and each one will only have a very small number of time series in it, thus defeating the purpose of hierarchical forecasting in the first place.
Instead I suggest one of the two following ways of dealing with size variable:

Plot the distribution and histograms of your sizes, and see if they have any distinct modes or clusters. Hopefully there would be only a small number of them. You can then assign each size to a bin that corresponds to the cluster it is in, and use that as your aggregation criteria.
Example: Your sizes are  $[1899 , 2023, 2200, 2300, 3500, 3570, 3995, 4012]$, you can see that there are two clusters. Assign $[1899 , 2023, 2200, 2300]$ to $group 1$, and assign $[3500, 3570, 3995, 4012]$ to $group 2$. Then uses those two groups to aggregate you data.
Note that this will only work if there are definite clusters in the data. It will not work if you had a size distribution that was more uniform like $[1899 , 2023, 2850, 3010, 3500, 3995, 4012, 4300]$.
A second approach (this is not really stats, just an example of using domain knowledge) is to just ignore the size, because the size will correlate strongly with other, more manageable, discrete variables like number of rooms, and number of stories in the house. You can just use those as proxies for the size of the house.
Comment: @user3050269 see additional edits to my answer.
Comment: Thank you for this helpful response! It seems that I would have to opt for DL models if size (m^2) is to be a predictor.
If I exclude size, or if I convert it to discrete values, would it make sense to add the model obtained for time-dependent regressors to the model obtained using hierarchical/grouped forecasting?
Comment: Both are excellent approaches, and the 2nd one really highlights the importance of domain knowledge in model construction!

Suppose I get `y(t) = y_AA(t) + y_AB(t) + y_AC(t) + y_BA(t) + y_BB(t)` , as in the hierarchical approach notes, and a different model using regression with ARIMA errors for time-dependent variables. Is there a way to bring the two together?


Sticky Navigation 8.x-1.1. Funny padding-top

Question: In in Drupal 8.5 Theme Bartik and using the Sticky Navigation 8.x-1.1.
When by any chance I reload a page of my site and at that moment I'm positioned in the middle of that page and the menu is "sticky",  the module add a padding-top equal to the height of the sticky menu bar to the tag Body (as an inline styling). If you go up to the top of the page, after reloading, there is a white strip at the very top of the page (originated by the padding top). Can some tell me how to fix it?
Answer: So far my solution was to apply CSS + jQuery to me theme:
CSS
body.js--padding-fix {
   padding-top:0 !important;
}

and JQUERY
jQuery(document).ready(function () {
    if (jQuery('div.primary-menu-container-global').hasClass('stickynav-active'))
    {
        jQuery('body').addClass('js--padding-fix');
    }
});

Note: if you apply the CSS directly to the body tag, it creates a problem with the Admin Menu, that covers the top of the site (minimized this way)
Is there a better solution?


Stochastic integration with non-caglad integrand

Question: In Oksendal's book on Malliavin calculus. The $\sigma$-algebra $\mathcal{F}_G$ is defined as the completed one generated by all random variables of the form
$$
F = \int_0^T\chi_A(t) \, dW(t),
$$
for all $A\subseteq G$, where $G$ can by any Borel set in $[0,T]$
Even the process $\chi_A(t)$ is deterministic, how does one justify such integration? As I know, integrands for stochastic integration is required to be caglad, i.e. is left continuous and has left limit. But $\chi_A(t)$ can be non-caglad, for example when $A=\{t\}$.
Comment: You sure that he is saying that $A$ is any subset of a Borel set $G$? Since $G=[0,\infty)$ is a Borel set, this would mean that we can take any set $A \subset [0,\infty)$.
Comment: G is a Borel set in [0,T]
Comment: My question was about $A$ (.. and not about $G$)
Comment: A is Borel subset of G, sorry
Answer: It's not true that stochastic integrals are only defined for caglad integrands. In order to make sense of the stochastic integral, we need that the integrand satisfies a certain "good" measurability property. In case of Brownian motion, the integrand has to be progressively measurable, see e.g. Section 15.5 in the book Brownian Motion by Schilling & Partzsch for details.  If you are dealing with deterministic integrands, then this progressive measurability boils down to Borel measurability.

Lemma: Let $f:[0,\infty) \to \mathbb{R}$ be a (deterministic) Borel measurable function such that $\int_0^T f(s)^2 \, ds < \infty$ for all $T>0$. Then the stochastic integral $$\int_0^T f(s) \, dW_s$$ exists for all $T>0$.
Comment: Thanks! Another question is, say f(s) = \chi_{s=t}. Then is this stochastic integral identically zero? in the almost surely sense.
Comment: By asking that I actually want to ask, according to the above definition of \mathcal{F}_G, are they the same sigma algebras when taking G = [0,t) and [0,t]?
Comment: @YuxuanLiu Re your first question: Yes, this follows from Itô's isometry. Re your 2nd question: I can't tell because I'm not sure about the definition, see my comment below your question.


Certificate address mismatch warning GPO cannot be Disabled

Question: I found the "Turn on certificate address mismatch warning" and I need to set it to Disabled. Seems like the Console is not accepting that option (I Can set it to enabled and it will work) and I'd like to know if it is like that by design or if there is somehow another setting which is overriding mine. Thank you.
Comment: Please explain "Seems like the Console is not accepting that option". Do you get an error prompt? Client-side execution failures? Just no effect?
Comment: Simply no effect at all, when you open it again it looks the same as before.
Answer: Looking through inetres.admx, the "Turn on certificate address mismatch warning" doesn't seem to have any value for the "Disabled" setting, but simply enforces it regardless local settings in IE when set to "Enabled".
To remove the setting on client computers, go for a Registry Group Policy Preference item, with the following properties:
Action: Update
Hive: HKEY_LOCAL_MACHINE
Key Path: Software\Policies\Microsoft\Windows\CurrentVersion\Internet Settings
Value name: WarnOnBadCertRecving
Value type: DWORD
Value data: 0x0
Be aware that it only works for IE 8+
Answer: You should also realise the danger in this. If you're using a self signed cert and don't like the error, it's much better to get the certificate installed onto the client machines. You're opening your users up to very simple MITM attacks, plus this setting is browser dependant so has limited reach.
Comment: Certificates from untrusted CA's will still result in warnings, but it *does* leave you vulnerable to MITM attacks through DNS poisoning etc
Comment: @MathiasR.Jessen Absolutely correct - I wasn't doing enough thinking!
Answer: Doesn't work on HKLM, has to be on the user's profile.  The check will go away, but it still doesn't work.  Try going to any banking site if you have the issue.  The below is the only way to get rid of the error.  Can be done in GP preferences is your users are a member of the forest.
Put it somewhere like all users startup or USRLOGIN.CMD
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /V "WarnonBadCertRecving" /t REG_DWORD /d 00000000 /f


Interaction with indicator function instead of dummy

Question: I am running a regression of Y on X (both are continuous variables). I'd like to measure how the effect differs between two groups of individuals, coded by a dummy variable Z. The traditional way of doing it is, I believe, to run:
<code> Y ~ X*Z + X + Z
</code>
However, I get much different results when I use an indicator function, meaning, I run:
<code>Y ~ X*1(Z==0) + X*1(Z==1) + Z
</code>
Where 1(Z==0) is 1 if Z=0, and 0 otherwise. But I've never seen any regression like that. What is wrong with that approach?
Comment: Welcome to Cross Validated! It seems like you are just switching which group is coded as $0$ and which is coded as $1$. Does that make your results make more sense?
Answer: Typically, the indicator variable, $Z$ in your terminology, is an indicator for $Z=1$. By using an indicator for $Z=0$, you are effectively switching which group is coded as $0$ and which is coded as $1$.
This is a strange way of coding your group labels and is likely to cause confusion. If you have a reason to consider group $1$ to be a "baseline" and group $0$ to be a group of interest (e.g., control and treatment groups, respectively), it might make more sense to stick with the convention where you code the baseline as $0$, though the math makes sense either way.


I will like to understand whether Case 1 or Case 2 will be applicable in this scenario

Question: Given that set A contains 10 distinguishable objects and set B contains 6 distinguishable objects.
I will like to choose 2 objects from set A (with replacement): ${10 \choose 1}^2$
I will also like to choose 4 objects from set B (with replacement): ${6 \choose 1}^4$
Now, the next step is where I am confused. The next step will be to take these 2 objects selected from set A and 4 objects selected from set B and arrange them in a single line where their position matters.
My confusion stems from whether this step will be equivalent to:

Case 1: 6!
Case 2: ${6 \choose 2} * 2! * {4 \choose 4} * 4!$

where in Case 2, E.g. ${6 \choose 2}$ refers to choosing 2 positions out of the 6 positions in a line and then permuting them afterwards with 2!
Comment: You have the right concern. The number of ways to do the arrangements will depend on whether any duplicates were selected in the first step. You should count a few different scenarios separately (four of them, of which your cases are two).
Comment: both cases give the same value. Did you mean some other expression for case 2?
Comment: this happens because case 2 is just another way to count case 1
Comment: Ah yeah, I missed that the two given expressions are the same.
Answer: Your description makes it sound as if at first order doesn't matter and then you start arranging things on a line and then order matters. But your original counts of $10^2$ and $6^4$ were already counts of ordered tuples. Assuming that that was indeed what you wanted, it's then not so complicated to combine these ordered tuples into an ordered arrangement. Just select $2$ spots in the ordered $6$-tuple for the $2$ objects from $A$ (thereby also selecting the other $4$ spots for the $4$ objects from $B$) and then fill the two ordered tuples into the combined ordered tuple in order. Thus, you have $10^2\cdot6^4\cdot\binom62$ different arrangements.
Comment: @DS: Yes, I think that was the question – my implicit answer was "neither".
Comment: hang on, what exactly are you calculating? Are you calculating the total no. of ways, or only the ways of arranging?
Comment: @DS: The former (if I understand correctly what you mean by that).
Comment: (+1) Yes, then I agree with your answer. I had interpreted the OP's question as "Which one to use, Case 1 or Case 2"?
Comment: See the Addendum that I have just added to the end of my answer.
Answer: As the comment of Karl indicates, neither Case 1 nor Case 2 is appropriate here.  Although I could be mistaken, I strongly suspect that (as Karl's comment also indicates), in order to complete the problem, you have to re-work the first part of the problem.  That is, you have to consider the mutually exclusive cases of how many distinct objects were taken from A and from B.
The (very tedious) work is shown below.  I emphasize that I may well be overlooking a more elegant approach to the problem.

For selecting items from A :

There are $~\displaystyle (10)~$ ways of selecting the same item twice.
I will use the syntax [A:2] to represent this possibility.

There are $~\displaystyle \binom{10}{2} = 45~$ ways of selecting two distinct items.
I will use the syntax [A:1-1] to represent this possibility.

Note
$45 + 10 \neq 10^2 = 100,~$ and $~100~$ was reported by the OP (i.e. original poster).  The discrepancy is explained by noting that when two distinct items are selected, the order of selection is irrelevant to the second part of the problem.

For selecting items from B :

There are $~\displaystyle \binom{6}{1} = 6~$ ways of selecting the same item, four times.
I will use the syntax [B:4] to represent this possibility.

There are $~\displaystyle (6 \times 5) = 30~$ ways of selecting one item three times, and then a second item one time.
I will use the syntax [B:3-1] to represent this possibility.

There are $~\displaystyle \binom{6}{2} = 15~$ ways of selecting one item twice, and then selecting a separate item twice.
I will use the syntax [B:2-2] to represent this possibility.

There are $~\displaystyle \binom{6}{2} \times 4 = 60~$ ways of selecting two distinct items, one time each, and then selecting a third item twice.
I will use the syntax [B:2-1-1] to represent this possibility.

There are $~\displaystyle \binom{6}{4} = 15~$ ways of selecting four distinct items.
I will use the syntax [B:1-1-1-1] to represent this possibility.

In effect, the above case work has partitioned the two positive integers $~4~$ and $~2.$
Now, in order to complete the problem, unfortunately, the $~2 \times 5 = 10~$ cases have to handled separately.  To keep this answer as short as possible, I will leave the reader to review Multinomials on their own.
The basic idea is that if you have $~k~$ distinct items, and each item is selected $~a_i~$ times, where $~i \in \{1,2,\cdots,k\},~$ and if $~\displaystyle \sum_{i=1}^k a_i = n$:
then the number of distinct ways of arranging the items in a row is
$$\frac{n!}{(a_1)! \times (a_2)! \times \cdots \times (a_k)!} \tag1 $$
For ease of syntax, I will use the expression $~\displaystyle \binom{n}{a_1,a_2,\cdots,a_k}~$ to represent the expression in (1) above.

Then, the number of distinct distributions of the items in a row is given by summing each of the $~10~$ cases separately.  This summation is detailed below:

[A:2] $~\times~$ [B:4]
$~:~~~~\displaystyle [10 \times 6] \times \binom{6}{2,4} ~$ ways.

[A:2] $~\times~$ [B:3-1]
$~:~~~~\displaystyle [10 \times 30] \times \binom{6}{2,3,1} ~$ ways.

[A:2] $~\times~$ [B:2-2]
$~:~~~~\displaystyle [10 \times 15] \times \binom{6}{2,2,2} ~$ ways.

[A:2] $~\times~$ [B:2-1-1]
$~:~~~~\displaystyle [10 \times 60] \times \binom{6}{2,2,1,1} ~$ ways.

[A:2] $~\times~$ [B:1-1-1-1]
$~:~~~~\displaystyle [10 \times 15] \times \binom{6}{2,1,1,1,1} ~$ ways.

[A:1-1] $~\times~$ [B:4]
$~:~~~~\displaystyle [45 \times 6] \times \binom{6}{1,1,4} ~$ ways.

[A:1-1] $~\times~$ [B:3-1]
$~:~~~~\displaystyle [45 \times 30] \times \binom{6}{1,1,3,1} ~$ ways.

[A:1-1] $~\times~$ [B:2-2]
$~:~~~~\displaystyle [45 \times 15] \times \binom{6}{1,1,2,2} ~$ ways.

[A:1-1] $~\times~$ [B:2-1-1]
$~:~~~~\displaystyle [45 \times 60] \times \binom{6}{1,1,2,1,1} ~$ ways.

[A:1-1] $~\times~$ [B:1-1-1-1]
$~:~~~~\displaystyle [45 \times 15] \times \binom{6}{1,1,1,1,1,1} ~$ ways.

Addendum
After reviewing Joriki's more elegant answer, I sanity-checked the two results.  My final computation exactly agrees with his.
Since I don't believe in coincidences, I decided to stretch my intuition to understand $~\color{red}{why}~$ the computations agree.
For simplicity, consider the situation where two distinct items are selected from A and one item is selected four times from B.
My enumeration of this particular possibility is:
$$\binom{10}{2} \times \binom{6}{1} \times \binom{6}{1,1,4} = 45 \times 6 \times 30 = 8100.$$
Joriki's enumeration of this particular possibility is:
$$[10 \times 9] \times [6] \times \binom{6}{2} = 90 \times 6 \times 15 = 8100.$$
Comment: I disagree with the note you added at the top of your answer. I'm only counting each such configuration once. If I understand your answer correctly (I'm not sure I do), we're counting the same thing, just with wildly different efficiency :-) Our answers differ only slightly, not by a large factor as would have to be the case if your note was correct. I suspect that the small discrepancy is due to a small mistake in one of your calculations.
Comment: @joriki Thanks for the heads up.  I could well have misinterpreted your analysis.  I will edit my answer accordingly.  Also, I did double-check my Math, which I will now triple-check.  If you happen to spot an error in my Math, please advise.
Comment: Actually, the error was just in my addition of your numbers :-) They do add up to my result.


"require" command not found when require 'nokogiri'

Question: Homebrew, ruby 2.0.0p648, nokogiri 220.127.116.11 are installed. When require 'nokogiri' there appears an error:
-bash: require: command not found

What's wrong?
Comment: How, exactly, are you trying to run the Ruby script? It looks like you're trying to interpret Ruby as a shell script.
Comment: Exactly! I was running require 'nokogiri'
Answer: Try running the script from the console/terminal shell like this:
ruby script_name.rb

You can also try adding this shebang line to the top of your .rb file:
#!/usr/bin/env ruby

This will auto-identify the script as Ruby when you try to run it directly in some shells.  Also see:

Why is it better to use "#!/usr/bin/env NAME" instead of "#!/path/to/NAME" as my shebang?
what is the use of "#!/usr/local/bin/ruby -w" at the start of a ruby program
Answer: You're running your command in bash -- this is a Ruby command.
Answer: You can't run a Ruby command directly in bash. If you want to use Ruby at command line, open the Ruby shell irb.
$ irb

and then you'll see the prompt
2.3.0 :001 >

The first number indicates the Ruby version you are using. In my case it is Ruby 2.3.0. The second number is the command number.
Then you may type
require 'nokogiri'

and it surely work, if you have this gem installed.
Comment: Thanks a lot! Yes, all the necessary gems have been installed. It works


if a single class can be performed concurrently by multiple thread. Why EJB pooled stateless bean in container?

Question: a single object in JVM can be run simultaneously by multiple threads.  same bytecode will run in different threads.
keeping thread count same if we increase object or pooled object in the container do you think performance will increase? if yes then how?
if no then why EJB use the stateless polled objects to serve concurrent requests?
Comment: Strange question. This strongly suggests that you didn't knew that EJB methods are by default transacitonal (which means that they absolutely need to stay threadsafe). In that case this is perhaps the real Q&A you're looking for: https://stackoverflow.com/q/18369356
Answer: Using the pool size you control how many threads can run the code of a bean in parallel. This can be important, e.g. if the maximum number of DBMS-Connections is limited.
On the other hand, if the poolsize would be greater than the available number of threads, then the pool will never get exhausted.


Fixed effects of independent variables highly correlated with the intercept. Is it an issue?

Question: In a linear mixed model run with lmer() I got this output for the correlation between fixed effects. My independent variable is almost perfectly correlated (negatively) with the intercept. Is this a problem?.
I am not sure what this actually means and if I need to actually drop this variable from the model.
Correlation of Fixed Effects:
          (Intr) Age  Status Tarsus Quality
Age       -0.061
Status2    0.115 -0.829
Tarsus    -0.991  0.041 -0.138
Quality   -0.049 -0.087  0.134 -0.033
GroupSize -0.067  0.024  0.145 -0.023  0.163

Answer: Correlation between the intercept and slope (more generally, the parameter estimate for the effect of a continuous predictor) is not specific to mixed models. It typically means that the mean of your predictor variable is far from zero (a classic example is when people use year as a continuous predictor variable).
It's probably not a problem.  If you mean-center your variables, though, you will make your intercept term more interpretable; rather than indicating the expected response of an individual with tarsus length equal to zero, it will be the expected response of an individual with the mean tarsus length (see Schielzeth 2010 Simple means to improve the interpretability of regression coefficients).


Probability of drawing exactly two aces and two kings or one ace and three kings?

Question: I've been trying to calculate the probability of drawing exactly two aces and two kings, or exactly one ace and three kings when the player already has an ace in hand. The player draws 24 more cards, and the deck is full aside from the ace in hand.
I've calculated the probability of getting exactly two aces and two kings like so:
$\dfrac{{3\choose2}.{4\choose2}.{44\choose20}}{{51\choose24}} \approx 13.81\%$
Which seems a little high to me. However, moving on with the same equation for drawing exactly one ace and three kings:
$\dfrac{{3\choose1}.{4\choose3}.{44\choose20}}{{51\choose24}} \approx 9.20\%$
And so, the probability of getting one or the other is $13.81\% + 9.20\% = 23.01\%$.
Can someone tell me where I'm going wrong? Because I have trouble believing there's a $23.01\%$ chance of the described scenario arising.
Answer: For exactly two more aces and exactly two kings in 24 draws from a
deck of 51 cards (missing an ace), I also get
$$ \frac{{3 \choose 2}{4 \choose 2}{44 \choose 20}}{{51 \choose 24}} = 0.138,$$
(to three places), computed in R as:
<code> 18*choose(44, 20)/choose(51,24)
 ## 0.1380654
</code>
Here is a simulation of a million such draws with probabilities
correct to 2 or 3 places.
<code> m = 10^6;  nr.ace = nr.kng = numeric(m)
 deck = 2:52 # aces are 1,2,3,4; kings 5,6.7,8
 for (i in 1:m) {
  draw = sample(deck, 24)
  nr.ace[i] = sum(match(2:4, draw, nomatch=0)>0)
  nr.kng[i] = sum(match(5:8, draw, nomatch=0)>0) }

 mean(nr.ace == 2)
 ## 0.357932
 mean(nr.kng == 2)
 ## 0.387775
 mean(nr.ace==2 & nr.kng==2)
 ## 0.137598  # approx 0.138 as in exact combinatorial result
 mean(nr.ace==1 & nr.kng==3)
 ## 0.092077

 AK = as.data.frame(cbind(nr.ace,nr.kng))
 table(AK)/m
           nr.kng
 ## nr.ace        0        1        2        3        4
 ##      0 0.007532 0.035196 0.055101 0.035380 0.007596
 ##      1 0.026295 0.109556 0.157987 0.092077 0.018387
 ##      2 0.027684 0.105594 0.137598 0.073657 0.013399
 ##      3 0.008706 0.030502 0.037089 0.017775 0.002889
</code>
The approximate probability of $P(A = 2, K = 2)$ is found in
cell $(2,2)$ of the table. The approximate probability $P(A = 1, K = 3)$ is in cell $(1, 3).$
Related probabilities can also be approximated from the table.
For example, the total probability
$P(A = 2) \approx 0.358$ is found separately in the printout
above and as the total of row 2 of the table.
<code> sum(c(0.027684, 0.105594, 0.137598, 0.073657, 0.013399))
 ## 0.357932
</code>
Its exact
probability (to three places) is
$$ \frac{{3 \choose 2}{48 \choose 23}}{{51 \choose 24}} = 0.358,$$
<code> 3*choose(48, 22)/choose(51, 24)
 ## 0.3578391
</code>
However, to get the probability of either 'two aces and two kings' OR
'one ace and three kings', you should add only two entries in
the table $(2,2)$ and $(1,3).$
Addendum: 'Expanded' R code, demonstrating method of counting aces (cards 2 through 4) in 24 draws:
<code> draw = sample(deck, 24);  draw  # list of 24 cards drawn w/o replacement
 ## 17 40 46 51 44 30 50 24  4  7 52 31 13 28 25 18 22 42  3  5 43 48 19  8
 ace.posn = match(2:4, draw, nomatch=0);  ace.posn
 ## 0 19  9  # card 2 not drawn, 19th was card 3, 9th was card 4
 tf.aces = (ace.posn > 0);  tf.aces
 ## FALSE  TRUE  TRUE  # TRUE for each ace found
 nr.aces = sum(tf.aces);  nr.aces  # counts TRUE's
 ## 2  # count of aces in 'draw' is stored in vector 'nr.ace'
</code>
The count of the number of aces in a 'draw' does not depend on which aces or their order. This is done a million times.
Comment: I rethought the issue, and find that even if we do not assume that a particular ace is missing, the result will be the same. I have revised my answer accordingly. (+1)
Comment: I'm not sure what all that test data means, but are you saying $23.01\%$ is correct, or incorrect?
Comment: Trying again to add my reply, browser lost the 1st attempt. Yes, 0.23 is correct. Add two cells from my table. (They agree with the first two combinatorial results in your question.) I don't see any double-counting in that. See the last sentence of my answer, added recently. – BruceET
Comment: I see. So it must be right, but it seems weird that there are such high odds for an "exact" scenario, doesn't it? I'm actually adding the odds for exactly one more ace and 2 of **any** other card (and I'm doing the same for exactly 2 more aces). The problem I'm running into is the massive amount of double-counting. Can you think of a more suitable algorithm for this?
Comment: I think that'll be messy. I think surprisingly high probabilities in your original problem are because you are drawing 24 cards. Intuition from 5-card poker and 13-card bridge does not carry over.
Comment: If you use the same formula as OP, obviously you will get a similar result by simulation.
Comment: @trublueanil: The simulation actually counts the outcomes in each draw of 24 cards without regard to order. Quite separately, my use of OPs formula was only for comparison.
Comment: How does your simulation distinguish between $(i)$ I have a **particular** ace in hand (say the ace of apades), and draw two more aces, etc. $(ii)$ I have an unknown ace in hand and draw two more aces, etc. My contention is that OP's answer is correct only for $(i)$
Comment: Nr. 1 in my list `2:52` is missing. (In a real situation I could look at it and know which one.) Denominator of OP's formula is also for 51-card deck. So, yes, I agree OP and I are both assuming a particular known ace is missing from the deck.Thanks for clarification. (+1, but the -1 wasn't mine).
Answer: Revised answer
Assuming you are respectively drawing $2$ or $1$ more aces, your answers are correct.
My suspicion that the first ace being unspecified would affect the result was unwarranted.
Here is a longer way for the first case (just to confirm the correctness).
The ace you have could be any of $4$, so numerator $= 4\times{3 \choose 2}{4 \choose 2}{44 \choose 20}$
But then you need to similarly structure the denominator as $4\times\binom{51}{24}$,
and the result will remain the same as what you got.
Comment: Hmm.. Would you mind elaborating? I believe you that I've overcounted, but I'm having trouble figuring out why I need to divide..
Comment: I have reconsidered the queries raised, and concluded that there is no overcounting.
Comment: I am easily confused by combinatorial problems, but I too am puzzled by this analysis of overcounting.
Comment: Denominator count is unordered. In numerator, C(3,2) = 3.


How to calculate the power modulo $990$ without a calculator?

Question: Stumbled upon this problem while studying for my exam in discrete mathematics and I can't figure out how to solve it:
The problem: What is $$73^{1567}\mod\ 990$$ ?
Comment: the result should be $127$
Comment: Yes, but how do you solve it without a calculator?
Comment: We need Euler's theorem and the chinese remainder theorem (See answer below)
Answer: We calculate the power modulo $9,10$ and $11$ and apply the chinese remainder theorem.
$n=9$ is easy because of $73\equiv 1\mod 9$ the result is $1$
$n=10$ leads to $3^3$ , if we reduce the base mod $10$ and the exponent mod $4$
The result is therefore $7$
$n=11$ leads to $7^7$ , if we reduce the base mod $11$ and the exponent mod $10$
It is easy to calculate $7^3$ mod $11$ (result $2$), so $7^6\equiv 4\mod 11$, hence $7^7\equiv 6\mod 11$
So, we have the residues $1,7,6$. The chinese remainder theorem gives $127$. To find this, first look at the numbers congruent $1$ modulo $9$ ; we have $1,10,19,28,37$ Here, we have residue $7$ mod $10$. So, we have residue $37$ modulo $90$. We are lucky that $37+90$ has already the correct residue mod $11$.
Answer: use that $$73^{20}\equiv 1\mod 990$$


Show if $a \equiv b \pmod{m}$ then $ac \equiv bc\pmod{mc}$ without restrictions?

Question: For this question here:
Show if $a \equiv b \pmod{m}$ then $ac \equiv bc\pmod{mc}$
Does $c$ need to be greater than $0$, for instance can c be negative?, what about $m$ being $2$ or greater? In the proof it does not appear …
Therefore, if these conditions are not given, is it invalid?
Comment: The definition of $a\equiv b\bmod m$ says $m\mid (b-a)$ for arbitrary integers $a,b,m$. But by convention we take $m$ positive. Therefore we want $m>0$ and $mc>0$, so $c>0$.
Answer: If $a\equiv b\pmod{m}$, it implies that $m\mid(a-b)$.
Since, $mc\mid(a-b)$ iff $m\mid(a-b)$, it must be true for all non-zero integer $c$. ($c$ cannot be $0$ since division by $0$ is absurd)
In conclusion, $c$ can be any non-zero integer.
Comment: For $c=0$: There are [some definitions for $\equiv \pmod 0$ as a relation](https://math.stackexchange.com/q/516251/89922). While division by $0$ is absurd, determining whether $ac-bc = 0$ is a multiple of $0$ is possible (and always true).
Answer: $a \equiv b \pmod m \implies m|(a - b) \implies mk = a - b$
$ac - bc = c(a - b) = cmk \implies cm|(ac - bc)$
$\implies ac \equiv bc \pmod {mc}$


Find $a$ and $b$ using the precise definition of limit

Question:
Let $f : \mathbb R \to \mathbb R$ be a function defined by
$$f(x) = \begin{cases} x^2+ax+1 &\text{if } x \in \mathbb Q\\ ax^2+2x+b &\text{if } x \in \mathbb R \setminus \mathbb Q\end{cases}$$
Knowing that $f$ is continuous at $1$ and $2$, find $a$ and $b$ using the precise definition of limit.

I have no idea how to start.
Answer: Let's say $\alpha(x)=x^2+ax+1$ and $\beta(x)=ax^2+2x+b$.
So $f(x)=\begin{cases}\alpha(x)&x\in\mathbb Q\\\beta(x)&x\in\mathbb R\setminus\mathbb Q.\end{cases}$
This function can only be continuous in $x=1$ and in $x=2$ if $\alpha(1)=\beta(1)$ and $\alpha(2)=\beta(2)$. The rest I leave to you.
Convince yourself of the above. It is the key argument.
Comment: But how you know that it is continuous at $x=1$ if $\alpha(1)=\beta(1)$.
Comment: Given $\epsilon$, find a $\delta$ that works for $\alpha(x)$ at $x=1$, and find a $\delta$ that works for $\beta(x)$ at $x=1$. The minimum of those two $\delta$ values will give you a $\delta$ that works for $f(x)$ at $x=1$.
Comment: @user677491 I don't understand your question. You're given that $f$ is continous at $x=1$, right?
Comment: I mean how you know that the function can only be continuous at $x=1$ if $\alpha(1)=\beta(1)$
Comment: @user677491 Lee Mosher answerd that above.


Proving or disproving planarity

Question: I'm looking through past exams and am having issues on this problem:

Call the graph $G$. My immediate thought is to use brute-force. That is, I want to apply Kuratowski's Theorem and find a subgraph of $G$ which happens to be an edge-subdivision of $K_5$ or $K_{3, 3}$ to prove that $G$ is not planar. The issue is, I've been at it for a bit with no success.
Is there a more directed approach I may take? Is there a hint that $G$ is planar or not hidden in plain sight? Thanks in advance!
Comment: Start by just dragging the vertices around (in your mind's eye) to try to untangle it. It's clearly drawn with unnecessary crossings.
Answer: Redraw our graph in five steps.
Note first that

all vertices of a planar graph and all its edges must lie inside (or
outside) any triangle face (except vertices and sides of this triangle).

Choose some triangle, say $136$.
We will make it all lie inside triangle $136$.

We move the vertices $3$ and $6$ so that the vertices $4$ and $5$ are inside triangle $136$.

We see that quadrangle $3546$ has intersecting sides. Rearrange the vertices $4$ and $5$ and raise them higher at the same time.

Now move the vertex $7$ inside triangle $136$ .

It remains to move the vertex $2$.
Comment: Completely agree with you.
Comment: Very interesting answer.
Comment: @JeanMarie thank you so much for your interest in my answers.
Comment: I am very visual, as visibly (!) you are too. I appreciate very much graphical illustrations that capture the underlying ideas. I try to convey the idea that many young people are visual and are left on the border of the road by a too-purely algebraic point of view.
Answer: You should use Kuratowski's theorem

a finite graph is planar if and only if it does not contain a subgraph that is a subdivision of $K_5$  or of $K_{3,3}$

You can use Mathematica to get the answer:
<code>g = Graph[{1 \[UndirectedEdge] 4, 1 \[UndirectedEdge] 5,
   2 \[UndirectedEdge] 4, 2 \[UndirectedEdge] 5,
   2 \[UndirectedEdge] 7, 3 \[UndirectedEdge] 5,
   3 \[UndirectedEdge] 7, 4 \[UndirectedEdge] 5,
   4 \[UndirectedEdge] 6, 4 \[UndirectedEdge] 7,
   5 \[UndirectedEdge] 7, 6 \[UndirectedEdge] 7},
  VertexLabels -> "Name", GraphLayout -> "PlanarLayout"]
PlanarGraphQ[g]  (*PlanarGraphQ[g]=True*)
</code>

Proving or disproving planarity


Prove uniform convergence of a Fourier series

Question: Suppose $f$ is continuous and $f \sim a_0 + \sum_{n=1}^{\infty}a_n \cos(nx) + b_n \sin(nx)$. Furthermore suppose the series $a_0 + \sum_{n=1}^{\infty}a_n \cos(nx) + b_n \sin(nx)$ converges uniformly. Show that $f$ is the uniform limit of this fourier series.
My attempt: Suppose $g$ is the uniform limit of $\sum_{n=1}^{\infty}a_n \cos(nx) + b_n \sin(nx)$, and it suffices to show that $f$ and $g$ has the same fourier coefficient, i.e. $a_n(f) = a_n(g)$ and $b_n(f) = b_n(g)$. If we define $T_N = a_0 + \sum_{n=1}^{N}a_n \cos(nx) + b_n\sin(nx)$, it is easy to verify that for any $n \le N$, the $n$-th Fourier coefficient of $T_N$ agrees with $a_n(f)$ and $b_n(f)$, but how to use the uniformly convergence condition to show that $a_n(g) = a_n(f), b_n(g) = b_n(f)$? Thanks!
Comment: Just pass to the limit in the integral corresponding to the definition of the $n$-th Fourier-coefficient: $ \int_0^{2\pi} e^{-\mathrm{i} tx} g(x) \mathop{dx} = \lim_{n \rightarrow \infty} \int_0^{2\pi} e^{-\mathrm{i} tx} \, T_n(x) \mathop{dx}$
Answer: The easy part is to show that $f$ and $g$ have the same Fourier coefficients. The hard part is to show that $f$ and $g$ are identically equal.
First show that $f$ and $g$ have the same Fourier series.
From periodicity of the series, we can consider any interval $[\alpha, \alpha+ 2\pi]$, and adopting standard notation replace $a_0$ with $a_0/2$.
We have
$$\tag{1}g(x) = a_0/2 + \sum_{n=1}^\infty (a_n \cos nx + b_n \sin nx)$$
where the series is uniformly convergent on the interval,  and, since each term in the series is continuous, it follows from uniform convergence that $g$ is continuous.
Multiplying by $\sin mx$ and integrating we get
$$\tag{2}\frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x) \sin mx \,dx \\= \frac{a_0}{2\pi}\int_{\alpha}^{\alpha + 2\pi}\sin mx \, dx +\frac{1}{\pi}\int_{\alpha}^{\alpha + 2\pi}\sum_{n=1}^\infty(a_n \cos nx \sin mx + b_n \sin nx \sin mx) \, dx.$$
Since (1) is uniformly convergent and $\sin mx$ is bounded, the series on the RHS of (2) is uniformly convergent and can be integrated term by term to obtain
$$\tag{3}\frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x) \sin mx \,dx \\= \frac{a_0}{2\pi}\int_{\alpha}^{\alpha + 2\pi}\sin mx \, dx +\sum_{n=1}^\infty\frac{a_n}{\pi}\left(\int_{\alpha}^{\alpha + 2\pi}\cos nx \sin mx \, dx \right) + \frac{b_n}{\pi} \left(\int_{\alpha}^{\alpha + 2\pi} \sin nx \sin mx \, dx \right)$$
All the integrals on the RHS of (3) vanish except the integral of $\sin nx \sin mx$ when $n = m$.
Hence,
$$\frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x) \sin mx \,dx = b_m = \frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}f(x) \sin mx \,dx $$.
Similarly we can show
$$\frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x)\,dx = a_0 = \frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}f(x)\,dx , \\ \frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x) \cos mx \,dx = a_m = \frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}f(x) \cos mx \,dx. $$
Thus $f$ and $g$ have the same Fourier series.
It still remains to prove that $f = g$.
This follows by showing that if two continuous functions differ at just one point, $f(c) \neq g(c)$, then they cannot have the same Fourier series.
Take $h = f -g$. If $f$ and $g$ have identical Fourier series, then all Fourier coefficients of $h$ vanish, and for any trigonometric polynomial $T_m(x) = A_0/2 + \sum_{n=1}^{m} (A_n \cos nx + B_n \sin nx)$ we have for any $\alpha \in \mathbb{R}$,
$$\tag{4}\int_{\alpha}^{\alpha + 2\pi} h(x) T_m(x) \, dx = 0.$$
We also have $h(c) = f(c) - g(c) \neq 0$ and WLOG can assume that $h(c) > 0$. Since $h$ is continuous , there exists $K > 0$ and $\delta > 0$ such that $h(x) \geqslant K > 0$ when $x \in [c - \delta,c + \delta]$.
It can be shown that $T_m(x) = [1 + \cos(x-c) - \cos \delta]^m$ is a trigonometric polynomial satisfying
$$T_m(x) \geqslant 1 \text{  for } x \in [c-\delta,c+\delta] \\ \lim_{m \to \infty} T_m(x) = \infty  \text{ uniformly on  } [c - \delta/2, c+\delta/2] \\ |T_m(x)| \leqslant 1  \text{ for } x \in [c + \delta , c - \delta + 2\pi]
$$
From these properties it follows that
$$\tag{5} \int_{c - \delta}^{c + \delta} h(x) T_m(x) \, dx \geqslant \int_{c - \delta/2}^{c + \delta/2} h(x) T_m(x) \, dx \geqslant \delta \, K \, \inf T_m(x) $$
and $\int_{c + \delta}^{c - \delta + 2\pi} h(x) T_m(x) \, dx$ is bounded.
Since the RHS of (5) tends to $\infty$ as $m \to \infty$ it follows for sufficiently large $m$
$$\int_{c - \delta}^{c - \delta + 2\pi} h(x) T_m(x) \, dx \neq 0,$$
contradicting (4) and leading to the conclusion that if $f$ and $g$  differ at one point, they cannot have the same Fourier series.


How to embed edit user profile page in a panel

Question: I am trying to embed the edit user profile page (ie what appears at the url domain.com/user/27/edit) into a panel. I have searched high and low on how to do this but I can't find any info on it. Is it possible to do this? There reason why I am asking is that I want to clean up the user's profile page so that it looks more professional and is easier to use.
Can anyone point me in the right direction on how to accomplish this?
Thanks
Answer: You need 1 context and 1 relationship to get the Form pane
Context: User => current user
Relationship:  User category edit form from user (default?)
and THEN you get the "Forms" category with "General form pane" under it


Manage multiple following positional argument with argparse

Question: I'm using this lib for parsing arguments in python : https://docs.python.org/2/library/argparse.html
So far I have this:
prog arg1 [-s arg2 [arg2 ...]] [-m arg3 [arg3 ...]]

And I want this:
prog arg1 -s arg2 [arg2 ...] -m arg3 [arg3 ...]

Here is my python code:
parser = argparse.ArgumentParser()
parser.add_argument('path', type=str,
                    help="path used for the generation of the rouge files")
parser.add_argument('-s', '--systems', type=str, nargs='+',
                    help="path to the systems generated summary files")
parser.add_argument('-m', '--models', type=str, nargs='+',
                    help="path to the reference summary files")
args = parser.parse_args()
print args

The problem is when you call the program without the optional arguments, it doesn't give an error (too few arguments). I want my optional arguments to be obligatory, but when you make the following call, the parser doesn't figure out which kind of args are involved...
For exemple with the following code:
parser = argparse.ArgumentParser()
parser.add_argument('arg1', type=str, nargs='+')
parser.add_argument('arg2', type=str, nargs='+')
parser.add_argument('arg3', type=str, nargs='+')
args = parser.parse_args()

And the following call:
python test.py arg1 arg1 arg1 arg2 arg2 arg3 arg3

I got this:
Namespace(arg1=['arg1', 'arg1', 'arg1', 'arg2', 'arg2'], arg2=['arg3'], arg3=['arg3'])

For sure here is the format of this prog:
prog arg1 [arg1 ...] arg2 [arg2 ...] arg3

Thanks for the help :)
Comment: What is your question? Does this code work?
Comment: This code works, but the arguments are optional. I don't figure out how to make them be kind of obligatory.
Comment: What do you mean by "kind of obligatory". The `nargs='+'` arguments are already required.
Comment: Yeap but the parser doesn't figure out which kind of arguments are involved in the call, that's why I use the flags (-a) but it make them optional, it means that you can make a call without them... :(
Answer: optionals can take a required=True parameter.  That may be all you need.
 p=argparse.ArgumentParser()
 p.add_argument('-m',nargs='+',required=True)
 p.add_argument('-n',nargs='+',required=True)
 p.print_usage()

producing
 usage: ipython3 [-h] -m M [M ...] -n N [N ...]

As to why:
 Namespace(arg1=['arg1', 'arg1', 'arg1', 'arg2', 'arg2'], arg2=['arg3'], arg3=['arg3'])

you specified that each of arg1, arg2, arg3 required 1 or more strings.  It split up the long list accordingly, giving arg2 and arg3 each one (which satisfies their requirement), and allocating the rest to arg1.  If you are familiar with regex, this is equivalent
In [96]: re.match('(A+)(A+)(A+)','AAAAAAAAA').groups()
Out[96]: ('AAAAAAA', 'A', 'A')

(The parser can't read your mind and allocate all the 'arg2's to args2 just because the names look similar.:)  )
So if you need to split lists of arguments in a specific way, then optionals (flags) is the way to go.  And between nargs and required you have quite a bit of control over the numbers.
Answer: What you want is not possible. Think about it: if you would implement your own argument parsing without argparse, how would you determine if a positional argument is the last one of a list of arg1 arguments, or the first of the arg2 arguments?
I think the solution you've got know (optional arguments) works fine and is even preferable.
Answer: I added require=True and it works, thanks to hpaulj
parser = argparse.ArgumentParser()
parser.add_argument('path', type=str,
                    help="path used for the generation of the rouge files")
parser.add_argument('-s', '--systems', type=str, nargs='+', required=True,
                    help="path to the systems generated summary files")
parser.add_argument('-m', '--models', type=str, nargs='+', required=True,
                    help="path to the reference summary files")
args = parser.parse_args()

python summary2rouge.py
usage: summary2rouge.py [-h] -s SYSTEMS [SYSTEMS ...] -m MODELS [MODELS ...]
                    path
summary2rouge.py: error: too few arguments


Installing mod_wsgi in addition to PHP

Question: I would like to use some python scripts with my PHP-based application. I don't want to install Django; just mod_wsgi, so Apache can execute my python scripts as well as the rest of my PHP site. How do I configure Apache to do this?
Comment: Agree with Jim.
Answer: Getting Apache to use wsgi is as simple as making sure you have mod_wsgi.so availible and using a LoadModule directive.
However, you have to realize that WSGI is not a framework, and using it to write a script will not be anywhere near as simple as using php. If you don't want to use Django, I would recommend using some framework. Perhaps Flask
Answer: By following the documentation. Start with:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6

Installing mod_wsgi in addition to PHP


Close linearly independent sequence

Question: X is an infinite-dimensional normed space. Show that there is a linearly independent sequence ${x_n}$ in X, such that for any sequence ${\epsilon_n} > 0 $ for all n, there is a sequence ${y_n}$ with $||y_n-x_n|| < \epsilon_n$ for all n, such that ${y_n}$ is not linearly independent.
Answer: Choose any linearly independent sequence $z_1$, $z_2$, $\dots$, and normalize it so that $||z_i||=1$ for all $i$.  Then, set
$$
x_1:=z_1, \ \ x_{j+1}:=z_1+\frac 1j z_{j+1} \ \ (j=1, 2, \dots)
$$
Since the $z_j$s are linearly independent, the $x_j$s are as well.  For any $j$, changing $x_1$ from $z_1$ to $z_1+\frac 1j z_{j+1}$ will make the sequence linearly dependent as its first element will then equal its $(j+1)$st element.  Since
$$
\lim_{j\to\infty} ||\frac 1j z_{j+1}|| = \lim_{j\to\infty} \frac 1j=0,
$$
the size of the perturbation can be made as small as desired by choosing $j$ sufficiently large.
Comment: Made it look a bit deceptively simple, eh?
Comment: Probably I should come up with this example. Anyway thank you for your help!

Close linearly independent sequence


Writing a linear function?? Precalculus

Question: I am suppose write a linear function for $h(x)$ and I am given $h(6) = -3$ and $h(2) = 7$
Iam not asking u to do the problem for me just a link or a little help thanks
Comment: Hint: what is the slope of the line that passes through the points $(6,-3)$ and $(2,7)$?  After that, solve for $b$ in $y=mx+b$ using one of those points and the $m$ (slope) you just found.
Answer: So, you are giving two points : $(6, -3)$ and $(2,7)$ living on your line. To find the equation of such a line, you need the main ingredient: the slope $m$
$$ m = \frac{7 - (-3)}{2 - 6} = \frac{10}{-4} = \frac{-5}{2}$$
$$ \therefore h(x) - 7 = \frac{-5}{2}(x -2) \implies h(x) = \frac{-5x}{2} + 5+ 7$$
$$ \therefore h(x) = - \frac{5x}{2} + 12 $$
is the required line
Comment: Thank you so much!! I completely forgot how to do an equation like that
Answer: Since the slope between any two points is constant you may write down an equation of the line immediately:
$$\frac{y+3}{x-6}=\frac{7+3}{2-6}.$$
Answer: There is another approach for this problem. Since $h(x)$ is a linear function, it assumes the form of $h(x)=mx+b$ which is in the slope-intercept form. It can be shown that the slope is $m=-5/2$. We are given that $h(2)=7$ and $h(6)=-3$, so we can use either of this given information to find the value of $b$. I will use in this case the given information $h(2)=7$. $h(2)=2(-5/2)+b$ which implies that $7=2(-5/2)+b=-5+b$. Solving algebraically for $b$, yields $b=12$. Therefore, the linear function that satisfies the initial conditions is $h(x)=-5x/2 + 12$

Writing a linear function?? Precalculus


Shap values on scaled dataset

Question: I am working on a binary classification problem for heart disease prediction.
I have scaled the dataset using Standard Scaler and I am trying to understand the model generated using SHAP values however is there a way to inverse transform the shap values so that I can see which columns affected the prediction?

I tried the below but it didn't work:

What I want is something  like this:
Comment: Do you want the plots to display column names?
Comment: yes, I have edited the question and attached a sample image
Answer: X_test_scaled probably is a numpy array or matrix.
You can transform it to a dataframe with column names by doing something like:
df = pd.DataFrame(data=X_test_scaled, columns=["colname1","colname2",...,"colnameX"])

This should be enough for shap.force_plot display the columns names after:
shap.force_plot(explainer.expected_value, shap_values[0,:], df[0,:])

Comment: this doesn't answer how to apply the inverse_transform
Answer: As univariate transformation applied to a model's inputs does not effect the Shapley values for the model, convert the explanation to the original feature space should just do the trick, see example here by set shap_values.data = X.values
Comment: We are trying to build a permanent repository of high-quality statistical information in the form of questions & answers. Thus, we're wary of link-only answers, due to linkrot. Can you post a full citation & a summary of the information at the link, in case it goes dead?

Shap values on scaled dataset


Using Bézout's Identity to prove that given $\gcd$ of two numbers is really true

Question: I need to prove that
$$
\gcd(n!+1,(n+1)!+1) = 1
$$
In class, the teacher advised us to use Bézout's Identity. So I wrote the following
$$
x(n!+1) + y[(n+1)! + 1] = 1
$$
But from there I'm at a loss.
To make the question more generic: I don't understand how Bézout's Identity can help me prove that the $\gcd$ of two numbers is really $n$.
Previous exercises I had to prove were much simpler; for example, I had to prove that $\gcd(2n+1, 3n+1) = 1$. In this case, I just tried to find $x$ and $y$ that make the statement $x(2n+1) + y(3n+1) = 1$ true. And by finding any two integers, I understood that I had provided enough proof. But I didn't do any math to find $x$ and $y$ in that simpler case... or I did, but I don't understand what I did... anyway, I could just "see", right away, that if $x=3$ and $y=-2$, then it would work out.
Can you help me understand how to use Bézout's Identity in proofs of any type? I think I'm not using it correctly.
Comment: If only everyone would post questions with as much context as you do... thank you.
Comment: @p and @andre-nicolas, what you did is really helping. I'm almost understanding it. I would keep trying today, but I must sleep. I'm taking notes of both your results to think more about it in the morning, after class, since I'll have access to internet only tomorrow afternoon. Thanks.
Answer: Hint:

$(n+1)\cdot(n!+1)-\left[(n+1)!+1\right]=\color{red}n$
$(n!+1)-(n-1)!\cdot \color{red}{n}=1$
Answer: I would not use "Bézout" directly. Let $d$ be a divisor of both. Then $d$ divides $(n+1)(n!+1)$ and $(n+1)!+1$. So it divides their difference, which is $n$.
But if $d$ divides $n!+1$ and $n$, it divides $1$.
Now if you wish you can work backwards, and find the appropriate multipliers. But we don't need them to prove relative primality.
Remark: In a sense, what we did is much like the procedure you described. You used $x$ and $y$ to get rid of the ugly part. We did the same thing in the first step, getting rid of the factorial stuff.
Comment: Well, I don't even think of the attempted process as Bezout. It is the trivial direction of Bezout, true almost anywhere there is a notion of relatively prime.  The hard direction is to show that **if** $a$ and $b$ are relatively prime, then there exist integers $x$ and $y$ such that $ax+by=1$.
Comment: Very true. I actually tried to hint at the misspelling of "Bézout" as "Bezout" but apparently I haven't been clear.
Comment: I'm afraid that if your keyboard does not support diacritics then there is no way around "insert symbol" or even copy-pasting.
Comment: @Lord_Farin: Thanks for the suggestion. I went to Wikipedia and stole Bézout.
Comment: Three days and several pages later, I can say I don't understand it. For example, why do you start the proof with a multiple of $(n!+1)$?
And, more importantly, I don't understand what seems to be the main argument: "if d divides n!+1 and n, it divides 1." Why?
Comment: If $d$ divides $n$, then $d$ divides $n!$. Since $d$ also divides $n!+1$, it follows that $d$ divides $(n!+1)-n!$, that is, $d$ divides $1$.
Comment: I'm still struggling to fully understand it, but I think you've answered my question, so I accepted your answer. Thanks a lot.
Comment: You are welcome. If there are any calculational gaps to be filled, just ask. When I have the time I will expand the answer.


winform TableLayoutPanel have some rows, but only one of them is visiable

Question: In a winform project, there is  a TableLayoutPanel(TLP), but something is wrong: this TLP has some rows, but onle one row is visiable, it look likes that this TLP has only one row.
To make a comparison, I create a new TLP, and this one works fine: add N rows, it shows N rows.
I compare these two TLPs, verify their properties, all the same.
Here are the images(I don't have enough reputation to post images, so put my blog(Chinese) link here):
https://blog.csdn.net/zhouyingge1104/article/details/91491476
Has anyone ever encountered the sample problem?
Comment: Please show the code that creates and displays the TLP
Comment: Maybe there's a docked Control inside the TLP (with the same background color) and the Control's `RowSpan` property has been set to `4` and `Margin.All = 0`.
Comment: I moved this TLP to another form, in that form, the bug disappeared, and then moved it back to the original form, it works fine.
Answer: I moved this TLP to another form, in that form, the bug disappeared, and then moved it back to the original form, it works fine. Seems like a bug of Visual Studio 2010 ?


Div Para Imprimir

Question: Estou utilizando um código em JS que funciona muito bem para imprimir:
function printdiv(divID) {
    var headstr = "<title></title>";
    var footstr = "";
    var newstr = document.all.item(divID).innerHTML;
    var oldstr = document.body.innerHTML;
    document.body.innerHTML = headstr + newstr + footstr;
    window.print();
    document.body.innerHTML = oldstr;
    return false;
}

Só que preciso imprimir alguns títulos e haverá vezes que terei que imprimir mais de um grid. Então criei no CSS o "print" e o "no print" e coloco tudo dentro da DIV divID.
O que acontece, é que quando o grid é populado com muitos dados aparecendo barra de rolagem ou a paginação ele não imprime tudo.
Com o grid todo populado, só que se eu coloco somente o grid dentro dessa div, ele imprime todos os dados.
Já tentei de várias formas e todas acontecem esse problema.
Answer: Consegui desta forma:

GridSuprimento.DataSource = gridCarregaSuprimento();
            GridSuprimento.AllowPaging = false;
            GridSuprimento.DataBind();
            GridRetirada.DataSource = gridCarregaRetirada();
            GridRetirada.AllowPaging = false;
            GridRetirada.DataBind();
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridSuprimento.RenderControl(hw);
            GridRetirada.RenderControl(hw);
            string gridHTML = sw.ToString().Replace("\"", "'").Replace(System.Environment.NewLine, "");
            StringBuilder sb = new StringBuilder();
            sb.Append("");
            ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());

Div Para Imprimir


How to measure cluster quality with distance matrix?

Question: When performing clustering with an algorithm such as K-means, it's possible to construct a plot that shows the intra cluster variability according to the number of clusters to see if there is an elbow that suggest an optimal number of clusters.
However, when working with a dissimilarity matrix (with all values in the range 0-1), it's not so obvious how to measure the quality of clusters obtained. Suppose I had a dataset with a mixture of numerical, categorical and ordinal variables, so I couldn't calculate the loss function with which K-means works, for example.
In this case, I can run K-medoids or hierarchical clustering, but how can I produce some metric that could suggest the number of clusters, analog to the inter/intra variability of algorithms that work with only numeric data?
Comment: `when working with a dissimilarity matrix... it's not so obvious how to measure the quality of clusters obtained` I would not concur. Generally, it makes no difference how was the input. Many _clustering criterions_ can be computed for either type of input. Search internet (starting with reading wikipedia article "Clustering") and this site for "clustering criterions", "cluster validity indices", "best number of clusters".
Comment: @Digio, why not write that up as an answer. It might be an interesting contribution. There seem to be a couple of posts about modularity in graph clustering, but none seem to start from non-graph data & circle through that route as a way to estimate the number of clusters.
Comment: Regarding your recent (deleted) question about clustering algorithms that can use a distance matrix, & this one, you might be interested in my answer here: [How to use both binary and continuous variables together in clustering?](http://stats.stackexchange.com/a/164694/7290) There, I demonstrate some ways of trying to determine the number of clusters.
Comment: There is a graph clustering metric called 'modularity'. It is used to find the optimal community structure of a graph, i.e. the number of clusters in the dataset represented by that graph. You can empirically set a threshold to your dissimilarity matrix in order to convert it to the adjacency matrix of a weighted graph and then use graph metrics to get what you want... Does that make sense?
Comment: @ttnphns, you have a bunch of good answers about clustering already. Are there any you might recommend the OP to read, in regards to this question?
Answer: If you read the section on internal cluster validation in Wikipedia, you will learn about a dozen measures for evaluation that require paiwise distances. E.g.

Silhouette index
Dunn's index
Davids-Bouldin

and many more.
On the other hand, none of them has me really convinced yet.
Comment: Well I thought the same - I mean they all look at different criteria that might not necessarily correspond each other. I guess a mixture of different metrics would be the ideal. Graph-based modularity also seems promising, although it would require finding yet another parameter.
Answer: I would suggest you to model your data as a graph and then use graph clustering algorithms and metrics to get what you want. A normalised (dis)similarity matrix is equivalent to the adjacency matrix of a complete, weighted, undirected graph. If you empirically set a threshold to that matrix (below which all values will become zero) you can also add a structure to that graph. For a given partition of the graph, the modularity metric will quantify the total strength of its clusters, therefore by maximising that metric you can get the optimal community structure (data clustering). An exact solution to modularity optimisation is a NP-hard problem but there are many (meta)heuristic packages that do the task. Once you've clustered your graph you can isolate clusters into subgraph and quantify their individual strength using graph metrics such as weighted degree centrality.
Unfortunately there is no package (that I know of) that can automate the adjacency matrix creation since finding the optimal threshold is a manual process. However, once you have that matrix, R and Mathematica have great packages to do the rest.
Comment: Thanks! could you answer this other question of mine about knn graphs? http://stats.stackexchange.com/questions/165047/how-are-graphs-of-k-nearest-neighbors-built-for-clustering
Answer: You can produce the metric using e.g. the cluster.stats function of fpc R package, and have a look at the metrics it offers.
The function computes several cluster quality statistics based on the distance matrix put as the function argument, e.g. silhouette width, G2 index (Baker & Hubert 1975), G3 index (Hubert & Levine 1976).
Example use case:
library(fpc)
data(data_ratio)
d <- dist.GDM(data_ratio)
p <- pam(d, 5, diss = TRUE)
c = cluster.stats(d = d,
                  p$clustering,
                  silhouette = TRUE, G2 = TRUE, G3 = TRUE)
c$avg.silwidth
c$g2
c$g3


Hotmail refuses connections?

Question: My server s sending out a lot of mail: account activation codes, notifications, pasword reset codes etc.
There is almost no problems with it. Users are receiving emails, including Hotmail users.
But from time to time in Exim logfile appears the following:
<code>2013-02-16 10:14:19 1U6emh-0001W6-AY <= www-data@myserver U=www-data P=local S=1456 email@example.com
2013-02-16 10:14:19 1U6emh-0001W6-AY mx3.hotmail.com [184.108.40.206] Connection refused
2013-02-16 10:14:20 1U6emh-0001W6-AY => email@address R=dnslookup T=remote_smtp H=mx3.hotmail.com [126.96.36.199]
2013-02-16 10:14:20 1U6emh-0001W6-AY Complete
</code>
Can me explain somebody what does it mean? Why 22.214.171.124 refuses connection?
Answer: Are you running from a dynamic IP or from a static IP that doesn't have a reverse DNS (PTR) record configured?
Larger mail houses like AOL and Yahoo will block such connections as they are often used by spammers.
Comment: I am running from a static IP that HAVE a reverse DNS (PTR) record configured + have SPF record. The problem is only with Hotmail and as I said 99,9% of emails Hotmail accepts without problems.

Hotmail refuses connections?


$G=\langle x,y\ |\ x^{-1}y^2x=y^{-2}, y^{-1}x^2y=x^{-2} \rangle$ is torsion-free.

Question: I have to prove that $G=\langle x,y\ |\ x^{-1}y^2x=y^{-2}, y^{-1}x^2y=x^{-2} \rangle$ is torsion-free.
Some things about this group that I understand are first show that $M=\langle (xy)^2,x^2,y^2 \rangle \unlhd G$, which is fine as $N=\langle x^2,y^2 \rangle \unlhd G$ and setting $z=xy$ and noticing $x^{-1}zx\equiv y^{-1}zy\equiv z^{-1}\ \text{mod}\ N $ and raising square power on both sides tells that $M=\langle z^2,x^2,y^2 \rangle \unlhd G$ and also $M$ is abelian and also torsion-free as it is freely generated by three elements.
Now $G/M$ is a Klein 4- group =$\{M,xM,yM,zM\}$ is also fine.
Now I want to check that if I pick any $g\in G=M\cup x M\cup yM\cup zM$ such that $1\neq g$ and $|g|=n$, then we get some contradiction.
If I let $g\in xM$, say $g=xm$, then I cannot seem to work my way out of here.
What else I see is as $g\in xM\in G/M$, definitely, $o(gM)\ |\ 4$, and thus $g$ can have even order only.
Comment: Why should *that* be the approach?
Comment: Any other approach is welcome, its just I was suggested this approach before by Mr. Derek in some other answer where group was the same.[see](http://math.stackexchange.com/questions/1307458/prove-g-cong-langle-x-y-x-1y2x-y-2-y-1x2y-x-2-rangle)
Answer: I am not sure how you proved that $M$ is free abelian of rank $3$ but I believe it.
In fact $x^{-1}z^2x=y^{-1}z^2y = z^{-2}$.
For $x^{-1}z^2x = yxyx$ and
$$(yxyx)(xyxy) = yxyx^2yxy = yxy^2x^{-2}xy = yxy^2x^{-1}y = yy^{-2}y=1,$$
and $y^{-1}z^2y=z^{-2}$ is proved similarly.
So, for $m = x^{2i}y^{2j}z^{2k} \in M$, we have
$(xm)^2 = x^{2+4i}$ which is a nontrivial element of the torsion-free subgroup $M$, so $xm$ is not a torison element. Similarly for $ym$ and $xym$.
Answer: Let $\Pi$ denote the group admitting $$ \langle x,y \mid x^{-1}y^2x=y^{-2}, y^{-1}x^2y=x^{-2} \rangle$$ as a presentation. Clearly, $$\Pi \simeq \langle x,y,a,b \mid x^{-1}ax=a^{-1} , y^{-1}by=b^{-1}, a=y^2,b=x^2 \rangle.$$ For convenience, we will modify slightly this presentation as $$\Pi'=\langle x,y,a_1, \ldots, a_n,b_1, \ldots, b_n \mid x^{-1}\bar{a} x=\bar{a}^{-1} , y^{-1}\bar{b}y=\bar{b}^{-1}, \bar{a}=y^2,\bar{b}=x^2 \rangle$$ where $\bar{a}$ and $\bar{b}$ denote respectively $a_1 \cdots a_n$ and $b_1 \cdots b_n$. Using Tietze transformations, it is not difficult to notice that $\Pi' \simeq \Pi \ast \mathbb{F}_{n-1} \ast \mathbb{F}_{n-1}$ where the two free groups correspond to $\langle a_2, \ldots, a_n \rangle$ and $\langle b_2, \ldots, b_n \rangle$ respectively. In particular, we deduce that $\Pi$ is torsion-free if and only if so is $\Pi'$. On the other hand, $\Pi'$ can be decomposed as
$$\left( \underset{:=\Pi_a}{\underbrace{\langle x,a_1,\ldots,a_n \mid x^{-1} \bar{a} x=\bar{a}^{-1} \rangle}} \ast \underset{:=\Pi_b}{\underbrace{ \langle y,b_1, \ldots, b_n \mid y^{-1} \bar{b} y = \bar{b}^{-1} \rangle}} \right) / \langle \langle \bar{a}=y^2,\bar{b}=x^2 \rangle \rangle.$$
As above, using Tietze transformations, we notice that $\Pi_a \simeq \Pi_b \simeq BS(1,-1) \ast \mathbb{F}_{n-1}$ where $BS(1,-1)$ is the Baumslag-Solitar group with presentation $\langle p,q \mid pqp^{-1}=q^{-1} \rangle$. In particular, $\Pi_a$ and $\Pi_b$ are torsion-free since so is $BS(1,-1)$: it is an HNN extension over a torsion-free group, namely $\mathbb{Z} \underset{\mathbb{Z}}{\ast}$. (We also have the isomorphism $BS(-1,1) \simeq \langle x,y \mid x^2=y^2 \rangle$, so that we may apply the arguments of this previous question.)
Now, according to Theorem 10.1 in Lyndon and Schupp's book Combinatorial group theory, if a family $R \subset F_1 \ast F_2$ satisfies the small cancellation property $C'(1/8)$, then the quotient $(F_1 \ast F_2) / \langle \langle R \rangle \rangle$ is torsion-free provided that $F_1$ and $F_2$ are torsion-free and $R$ does not contain a cyclic permutation of a proper power.
In our case, $R= \{ \bar{a}y^{-1}, \bar{b}x^{-1} \rangle$ satisfies $C'(1/n)$, so that we deduce from Lyndon and Schupp's theorem that $\Pi'$ is torsion-free whenever $n \geq 8$. A fortiori, $\Pi$ is torsion-free.
For more information on small cancellations for free products, see Section V.9 of Lyndon and Schupp's book.
Comment: Isn't this overkill for a problem that can be solved by elementary calculations?
Comment: For me, it seems very natural, because a motivation behind small cancellation is to determine whether or not an element belongs to the normal closure of some subgroup. Afther that, I agree that my answer is probably not the simplest solution to the problem. But I found interesting to give a "standard" approach to this kind of question.


Calculating Best Approximation of $f(x)=e^x$ on $P_0[-1,1],P_1[-1,1],P_2[-1,1]$ with L2-Norm

Question: I want to calculate the best approximation $f(x) = e^x$ on the function spaces $P_0[-1,1],P_1[-1,1],P_2[-1,1]$ with the L2 Norm. In the lecture we derived that given a orthonormal system of the function space of $P_n[-1,1]$, e.g. the Legendre polynomials in the case of the L2 inner product, we could determine the best approximation using a Fourier expansion:
$$ g_n = \sum_{k=0}^n(\int_{-1}^1f(x)q_j dx)q_j$$
For $P_0[-1,1]$ we have $q_0 = 1$ for which we would get $g_0 = e-1/e$, for $P_1[-1,1]$ I get $q_0 = 1, q_1 = \frac{\sqrt{3}}{\sqrt{2}}x$, so the Fourier expansion would yield: $e-1/3+\frac{3}{e}x$.
However, if I plot these functions, they don't look to be the best approximation of f(x):

Can someone explain what I'm doing wrong here?
Answer: What happens is that $q_0=1$ is not normalized, since $\int_{-1}^1q_0^2\,dx=2$. You should take $q_0=1/\sqrt2$.


Duvida sobre encadeamento simples em c

Question: Eu queria saber o porque dos processos de remoção em encadeamentos terem dois ponteiros setados para o next
como esse exemplo dado
void
remove (celula *p)
{
celula *lixo;
lixo = p->prox;
p->prox = lixo->prox;
free (lixo);
}

porque sempre tem algo desse tipo "p->prox = lixo->prox;"? poderiam me explicar obrigado
Answer: Escrever
p->prox = lixo->prox;

é a mesma coisa que
p->prox = p->prox->prox;

Você faz isso para poder remover o item do meio.
Ex: imagine a lista 4 5 6
O 4 é o p e o 5 é o lixo
O lixo->prox é o 6
Ao fazer p->prox = lixo->prox eu estou falando que 4->prox = 6, então eu posso remover o 5 agora que a lista não irá quebrar.
Comment: Obrigado irmão estava com dificuldades

Duvida sobre encadeamento simples em c


Finding the limit of an integral 4

Question: we were asked to complete this question as an exercise in my lecture.
$$
\lim_{x\to\infty} \left( \frac{1}{x^2} \int_{t=1}^x \frac{t^2}{t + |\sin t|} \, dt \right)
$$
(original image at https://i.stack.imgur.com/fvjsE.png)
Just wondering whether you could give some hints as to where to start?
I was thinking that it had something to do with the fundamental theorem of calculus. And then maybe using l'hopitals rule to determine the limit but I'm not too sure as to when to apply them and where. We haven't done anything like this in class.
Any help would be greatly appreciated.
Thanks in advance.
Answer: L\Hopital's Rule gives the limit easily. The answer is $\frac 1 2$.
Details: let $f(x)=\int_1^{x} \frac {t^{2}} {t+|\sin\, t|}dt$. Then $\lim \frac {f(x)} {x^{2}}=\lim  (\frac {x^{2}} {x+|\sin\, x|}) /{2x}=\lim \frac x {2(x+|\sin\, x|)} =\lim \frac 1 {2(1+|\sin\, x|/x)}=\frac 1 2$ because $\frac {|\sin\, x|} x \to 0$ as $ x \to \infty$.
Comment: @BrianTung Thank you. I stand corrected.
Comment: How did you get to that conclusion?

Finding the limit of an integral 4


Net beans 6.9 under 64 bit windows

Question: Will netbeans 6.9 (and whatever else I'll need for Java development - JVM, mysql, etc.) install under the 64 bit version of Windows 7 professional?  The netbeans website says (well, implies) it's untested. Need to know if I need to reinstall 32 bit Windows 7 before a Java class starting tomorrow. Thanks for any help.
Update:  went ahead under 64 bit and all is working fine.
Comment: Can you give info on the performance of NB under 64 bit windows? Do you also use a 64 bit JDK ?
Answer: I'm running Netbeans 6.9, Java 6 (64 bit) and MySQL under Windows 7 Pro 64 bit. Netbeans I'm using with Java, Ruby, Python and C/C++ (with Cygwin). All work fine.

Net beans 6.9 under 64 bit windows


Find the $\angle DBC$ in the quadrilateral below

Question: For reference: Given the quadrilateral ABCD such that $\angle CAD=25^\circ , \angle ACD=45^\circ$ and $\angle BAC=\angle BCA=20^\circ$ , what is the value of angle $\angle DBC$?
I made the drawing and distributed the angles.
I drew the perpendicular $CJ$ $\perp$ $JI$
I would need to demonstrate that $CJ$ is parallel to $BD$ and/or that $\angle CDB = \angle ICJ$ but I couldn't find the way
Answer: Here's an alternative short approach by slightly modifying the diagram you posted:

1.) Extend segment $BD$ to meet at point $E$ such that $AB=BC=BE$. Connect $E$ with $A$ and $C$. This gives $\triangle AEC$ and since $AB=BE=BC$, we can conclude that point $B$ is the circumcenter of $\triangle AEC$ and thus, via the inscribed angle theorem, $\angle AEC=\frac{\angle ABC}{2}=70$.
2.) We can see that $\angle AEC+\angle ADC=180$, therefore Quadrilateral $AECD$ is a cyclic quadrilateral. Using the properties of cyclic quadrilaterals, we can quickly establish that $\angle CED=\angle CAD=25$, this means that $\angle AED=45$. Since we know that $BC=BE$, this also means that $\angle CED=\angle BCE=25$, and thus, since $E$, $B$ and $D$ are collinear, $\angle DBC=25+25=50$.
Comment: Excellent. One suggestion: Once we have found $\angle BEC=25^o$, we can directly say that $\angle DBC=50^o$ because angle at center = $2 \times$ angle at circumference.
Comment: @LiKwokKeung Correct. However since that would've required me to explain why $BD$ is also equivalent to $BE$ I decided to choose the alternative instead
Comment: @ Goku  The solution can be even simpler. Since you have proved that $B$ is the circumcenter of $\Delta ACE$ and $AECD$ is a cyclic quadrilateral. Then $B$ is the center of circle $AECD$. By angle at center = $2 \times$ angle at circumference, $\angle DBC = 2 \times \angle DAC = 2 \times 25^o = 50^o$
Answer:
In the figure, $E$ is a point on $CD$ produced such that $\angle DAE=20^o$
$ \because \angle CAE= \angle ECA=45^o$
$\therefore \angle AEC=90^o$ and $EA=EC$
Note that $BA=BC$, $\angle EAB=\angle ECB=65^o$ and $EA=EC$
implies that $\Delta EBA \cong \Delta EBC$ (SAS)
Hence $\gamma + \delta = \frac{140^o}{2}=70^o$ ----- (1)
Also $\alpha = \beta =45^o$
Since $\angle BAD =45^o= \alpha$
$\therefore A, B, D, E$ are concyclic.
Thus $\gamma = \angle DAE=20^o $ ----- (2)
(1) and (2) implies that $\delta =50^o$
Hence $\angle DBC=50^o$
Comment: I think in the 2nd line you meant $\angle ECA$ instead of $\angle ECD$.
Comment: @Hersh Thank you! Answer amended.


Como usar o parâmetro data da função $.ajax

Question: É possível enviar dois JSON ao mesmo tempo como valor do parâmetro data de jQuery.ajax()?
Existe alguma forma de chamar esses dois argumentos, já que preciso chamar esses dois json e mostrar na tela?
Segue o código abaixo:
var token = "Xke;
var jsonTipo1 = "{ tipo: 1, numPagina: 1 }";
var jsonTipo2 = "{ tipo: 2, numPagina: 1 }";

$.ajax({

    type : "POST",
    url : "https://producao-ws.talcoisa.net/api/Produto/conteudo/",
    processData : false,

    data : json, jsonTipo2,
    success : sucesso,
    error : errar,

    beforeSend : function(xhrObj) {
        xhrObj.setRequestHeader("tokenApp", token);
        xhrObj.setRequestHeader("Content-Type", "application/json");

    },
});
//Ws

// Responsável por chamar metódos responsáveis pelos títulos e imagens  que vem do json

function sucesso(jsonTipo1 , jsonTipo2) {

    mostrarImagemNaTelaJsonTipo1(json);

    mostrarTituloNaTelaJsonTipo1(json);
    mostrarImagemNaTelaJsonTipo2(jsonTipo2);

}

function errar(json) {

    ToastMessage.showMessage("Fail!");
}

Comment: Para enviar dois JSON através da mesma requisição, você deve mesclá-los através do método [concat()](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/concat). Mas você está confundindo o que cada argumento de jQuery.ajax() representa. Leia novamente a documentação e veja que eles **não são** os seus JSON. O que você for "mostrar na tela" vai ser aquilo que a linguagem servidor enviou como saída (ex: um echo/print do PHP).
Comment: O que deveriam ser esses `jsonTipo1` e `jsonTipo2`? O segundo parâmetro do callback `success` é o `textStatus`.
Comment: tipo 1 se refere aquelas imagens e tipo 2 outras imagens, os dois fazem parte do mesmo Json. A ideia é atualizar essas imagens dentro do html.
Comment: No seu callback `sucesso` o parâmetro `jsonTipo2` vai conter o `textStatus` retornado da requisição ajax. Sua pergunta está realmente muito confusa. Tente reescrever e  dizer *exatamente* o que está dando errado e qual é o resultado esperado.
Answer: Envie uma array com os objetos:
var token = "Xke;
var jsonTipo1 = "{ tipo: 1, numPagina: 1 }";
var jsonTipo2 = "{ tipo: 2, numPagina: 1 }";
var dados = [jsonTipo1, jsonTipo2]; // colocando ambos numa array

$.ajax({

    type : "POST",
    url : "https://producao-ws.talcoisa.net/api/Produto/conteudo/",
    processData : false,

    data : dados, // passando a array
    success : sucesso,
    error : errar,

    beforeSend : function(xhrObj) {
        xhrObj.setRequestHeader("tokenApp", token);
        xhrObj.setRequestHeader("Content-Type", "application/json");

    },
});

Para retornar mais de um objeto, use a mesma lógica, e no callback os dados virão sempre como o primeiro argumento:
function sucesso(arrayDeDados) {

}

Comment: Algo do tipo: function sucesso(dados) {algo.dados.jsonTipo1.Produto[1].imagemDoProduto}
Comment: Não entendi seu comentário acima
Comment: Não entendi a função sucesso(arrayDeDados);  quero chamar uma das posições do array e mostrar na tela, é possível? tentei aqui mas acredito ter feito errado.
Comment: Botei um link no Gist com o código, veja por favor. https://gist.github.com/anonymous/1f5e6796758375eb57d0
Answer: Substitua por:
data : { json, jsonTipo2 },

Comment: Poderia pq essa alteração funciona, isso facilita para outras pessoas o entendimento, se tiver alguma referência adicione na resposta. O stackoverflow funciona diferente de um forum, veja as diferenças na [tour](http://pt.stackoverflow.com/tour) a explicação é bem rápida.


Creating specific front pages for departments

Question: The Drupal 7 site I am working on has its own company front page, and there are a couple of branches of the company in different location. I want to add specific front pages with "about / contact us / other menus" for each of those departments/branches of the company that will be displayed when each of the branches is accessed.
How can I achieve this?
Answer: If you don't want to code, and you are familar with context module you can use this Context Reaction Menus.
Add new context with a URL as a condition, for example "department1/*" and as a reaction change the main menu, this will change in all pages that start with "deparmente1"
Answer: So basically you need different menu on different pages?
First create different menus on Drupal backoffice, then check your template files on your theme folder and find where it prints the menu (usually page.tpl.php).
Get the nid (node ID, in Drupal 7 the easier way is with args) and place and if/else condition, then print the menu following this


shell pipelines using subprocess.Popen

Question: I would like to use command containing multiple pipes with subprocess.Popen. Here's my short script
#!/usr/bin/env python

import subprocess
import datetime
import shlex

todayyearnumber = str(datetime.datetime.now().strftime('%Y'))

command = 'git log --grep "' + todayyearnumber + '.*commit" --oneline'
command2 = 'cut -d " " -f4'

argsplit=shlex.split(command)
argsplit2=shlex.split(command2)

process1=subprocess.Popen(argsplit, cwd=ebb_path, stdout=subprocess.PIPE)

process2=subprocess.Popen(argsplit2, stdin=process1.PIPE, stdout=subprocess.PIPE)

print(process2.stdout.read().decode('utf-8'))

However, Im receiving an error
Traceback (most recent call last):
  File "./proces.py", line 35, in
    process2=subprocess.Popen(argsplit2, stdin=process1.PIPE, stdout=subprocess.PIPE)
AttributeError: 'Popen' object has no attribute 'PIPE'
Could you lend me a hand where I make a mistake?
Answer: That's because PIPE is a constant defined as subprocess.PIPE.
The complete program would be like below, if I understand you correctly:
#!/usr/bin/env python

import subprocess
import shlex

command = 'echo a b c'
command2 = "awk '{print $2}'"

argsplit=shlex.split(command)
argsplit2=shlex.split(command2)

ebb_path="/tmp/"
process1=subprocess.Popen(argsplit, cwd=ebb_path, stdout=subprocess.PIPE)
stdout_data, stderr_data = process1.communicate(timeout=1)

process2=subprocess.Popen(argsplit2, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdout_data2, _ = process2.communicate(input=stdout_data,
                                    timeout=1)

print(stdout_data2.decode('utf-8'))

shell pipelines using subprocess.Popen


Moving postgres data folder on NFS drive. Is it better to symlink, reinit cluster, or modify init.d script?

Question: I want to move my postgres data folder to an NFS drive but I'm not sure what would be the best way to do it. I've got three options in mind:

According to Postgres Documentation, one method would be to use the initdb command with the -D option.

initdb will attempt to create the directory you specify if it does not already exist.

Another method listed on LinuxQuestions.org is to update the postgressql init script to point to the new directory, which in this case would be the NFS drive.

Lastly, I was thinking I would just copy the pgsql/data folder to the NFS drive and simply symlink the folder.
i.e., pgsql/data -> nfs/data

Symlinking or updating the init script seem like the simplest approach to me, but I'm not sure if they would be best or the safest way. This is where I hope someone can help me out. Any suggestions, concerns, and pros/cons would be appreciated.
Environment Information

Red Hat Enterprise Linux Server 5.7
PostgreSQL 8.3.6

Assume that the NFS drive is mounted with -maproot=root option and that the NFS drive would be accessed by the root user.
Comment: Why do you wish to move your database to an NFS mount?
Comment: I'd like to amplify @ewwhite's comment with a whole lot of bad language.  This is a spectacularly bad idea.
Comment: @womble Perhaps circumstances have changed in the 4 years since this comment, but these days with cloud systems one often has little choice in the matter: NFS is often the only way to get persistent storage.
Comment: If your cloud provider's *only* persistent storage option is NFS, find a better cloud provider.  Every provider I can think of supports at least block storage, too.
Answer: You can simply shut down Postgres, move the folder over and change the init scripts to point to the correct location for the data directory.  Double-check the configuration files under data/ for references to the old path before restarting the server.

You probably don't want to do this.  Really. It's a BAD idea.
NFS's other name is the Network Failure System.  It is not known for its reliability, and having the underlying filesystem go away at an inopportune time (e.g. when appending to the WAL) could really ruin your day, not to mention your database.  Remember that Postgres does nothing special for NFS, and will freak out if something unexpected happens (see 17.2.1 in the Postgres manual).
Perhaps if you describe the underlying problem you're trying to solve (ask a new question) we can help you do so in a less risky way?
Comment: This is NFS FUD. NFS can be stable. Oracle and VMWare (both doing highly intensive I/O) run well on NFS exports.
Comment: @embobo: That it *can* be stable is irrelevant.  Why would you even want to take the risk for no benefit?
Comment: Thanks embobo for sharing. I am inclined to agree with you and fairly confident in the underlying systems. The organization here uses VMWare vSphere and have a full-time team of administrators monitoring the systems with redundancy and backups to the 9s. Admittedly, still not a 100% guarantee, but nothing really is. With that said, voretaq7, if I were to follow the recommendations in the documentation, specifically "mount NFS file systems synchronously (without caching)", would you still be concerned? Also, thanks for your help again, voretaq7. I really appreciate it.
Comment: @John - I'd be concerned running anything critical like a database server over NFS, AFS, or any remote-mounted filesystem (NFS in particular - while it **CAN** be stable, it often is not, and the list of potential failure modes is rather long).  Following the recommendations in the postgres docs & designing a robust NFS environment is a good start, but I'd smoke-test the ever-loving bejeebus out of it in a lab before trusting it in production :-)
Comment: tbh Postgres should be able to cope with a tablespace dissapearing or reappearing without it effecting others whether it does is another question.  As long as you sync writes with nfs the data will always be consistent if it is there.


UPDATE table values without knowing column names PHP

Question: Here is the situation. I just know total number of columns the table test_table has but don't know their names(sounds strange but its true). Is there any way I can write UPDATE Query for all column values on basis of some ID(auto-increment primary key)?
To add row in this table, I did following which is working but don't have idea how to do it for UPDATE:
$newCols = $_POST['newRowCols'];
$query = "INSERT INTO test_table VALUES "."("."NULL";
foreach($newCols as $col)
{
$query .= ",'$col'";
}
$query.=")";
mysqli_query($con,$query);

Thanks.
Comment: You may want to use mysqli_fetch_fields() on a select to get the fields

http://php.net/manual/en/mysqli-result.fetch-fields.php
Answer: No this is not possible. But you can get the column names using the information_schema database:
SELECT
  `ORDINAL_POSITION`,
  `COLUMN_NAME`
FROM `information_schema`.COLUMNS
WHERE
  `TABLE_SCHEMA` = $dbname
AND
  `TABLE_NAME` = $tablename
ORDER BY `ORDINAL_POSITION`