Coldfusion and SVNKit Log

Question: I am trying to use SVNKit to get a Log of the SVN Entries in Coldfusion.  I downloaded the latest SVNKit jar files and threw them in the lib folder under WEB-INF/lib.
Here is my code that should return an Array Of Log Entries but this code is returning a Null Pointer exception in Coldfusion 9.0.2.
SVNURL = createObject('java','org.tmatesoft.svn.core.SVNURL').parseURIEncoded(svnurl);
drf = createObject("java","org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory");
drf.setup();

rf = drf.create(SVNURL);
SVNWCUtil = createObject("java","org.tmatesoft.svn.core.wc.SVNWCUtil");
authManager = SVNWCUtil.createDefaultAuthenticationManager(user,pass);

rf.setAuthenticationManager(authManager);

log = rf.log(JavaCast("String[]",[]),JavaCast("null",""),JavaCast("long",10),JavaCast("long",15),true,true);

rf.closeSession();

When running this code, I receive the following Error.
The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code.
Null Pointers are another name for undefined values.
Which points to this line..
log = rf.log(JavaCast("String[]",[]),JavaCast("null",""),JavaCast("long",10),JavaCast("long",15),true,true);

I moved this same code over to Railo, and everything is running fine.  I just cannot see why ACF is choking on the log() method.
I was using the Printing Out Repository History example on the SVNKit Wiki to start me off.
Any suggestions on getting it to work in Adobe Coldfusion would be greatly appreciated.  I did not test on CF10.
Comment: If you dump `rf`, does it show the method signature you are attempting to use?
Comment: Might be a JVM issue. Check the SVNKit JVM requirements against what CF9.0.2 is running on.
Comment: I haven't found where it lists the SVNKit JVM requirements, but I have swapped out the JRE CF is using and still get the error.
Comment: Okay... looks like I needed to add a JavaCast("boolean",true)  to the last two arguments to make it work.  Yes, the rf contains the method sig...
Answer: I wasn't using the JavaCast("boolean",true) for the last two arguments in the log() function.  After that, everything worked fine.
Got to remember to check and use JavaCast()!
log = rf.log(JavaCast("String[]",[]),JavaCast("null",""),JavaCast("long",10),JavaCast("long",15),JavaCast("boolean",true),JavaCast("boolean",true));

Coldfusion and SVNKit Log


Diff module shows 'No visible changes' for 'Geolocation' and 'International phone' fields

Question: I have "No visible changes" message for 'Geolocation' and 'International phone' fields change and have only one option "Don't compare" in Diff field configuration page /admin/config/content/diff/fields.
Can you help me fix this issue?
Answer: The Diff module can only compare fields for which a @FieldDiffBuilder class is implemented for that field and that class offers options for comparing that field.
For example, for a comment field, the Diff module implements the CommentFieldBuilder class, for which the options are given by  CommentFieldBuilder::buildConfigurationForm().
$form['compare_key'] = array(
  '#type' => 'checkbox',
  '#title' => $this->t('Compare comment status key'),
  '#default_value' => $this->configuration['compare_key'],
);
$form['compare_string'] = array(
  '#type' => 'checkbox',
  '#title' => $this->t('Compare comment status string'),
  '#default_value' => $this->configuration['compare_string'],
);

return parent::buildConfigurationForm($form, $form_state);

There isn't any issue in the module. A module should change the @FieldDiffBuilder class associated with the Geolocation and International phone fields, to make the Diff module able to compare their values.


Angular4 error message shows code which differs from the code that's supposed to be serving

Question: I'm writing an app to go into a website, which is intended to calculate simplex algorithms. At the moment I am attempting to create functionality whereby the user can enter the number of coefficients and constraints, name these whatever they wish, and have the app spawn the relevant number and type of UI elements relative to the user's input. Here's what appears to be the relevant portion of the code (app.component.ts):
import { Component } from '@angular/core';

[...]

export class UIComponent {
  id: 1;
  name: string;
  value: number;
  type: string;
}

//* Mock data */
const UICOMPONENTS: UIComponent[] = [
  { id: 1, name: 'coefficient1', value: 4, type: '1dslide' },
  { id: 2, name: 'constraint1', value: 2, type: '2dslide' },
  { id: 3, name: 'min_max', value: 0, type: 'switch' },
  { id: 4, name: 'profit', value: 100, type: 'num_output' }
];

[...]

export class AppComponent {
  title = 'SimutronX';
  uicomponents = UICOMPONENTS;
  [...]
}

This produces an error on screen saying:
Failed to compile.

/root/simutronx/simutron-app/src/app/app.component.ts (18,49): ',' expected.

Which relates to this line:
{ id: 2, name: 'constraint1', value: 2, type: '2dslide' },

Specifically the digit 2 in 2dslide. The error message (it's extremely long so I won't reproduce it all) also includes:
./src/app/app.component.ts
Module parse failed: /root/simutronx/simutron-app/node_modules/@ngtools/webpack/src/index.js!/root/simutronx/simutron-app/src/app/app.component.ts Unexpected token (22:85)
You may need an appropriate loader to handle this file type.
| var UICOMPONENTS = [
|     { id: 1, name: 'coefficient1', value: 4, type: '1dslide' },
|     { id: 2, name: 'constraint1, value: 2, type: ', 2: dslide, ' },: { id: 3, name: 'min_max', value: 0, type: 'switch' }, },
|     { id: 4, name: 'profit', value: 100, type: 'num_output' }
| ];

Which is particularly confusing since, as you can see, that's not how I wrote the code. What's going on here?
Comment: `type` is a contextual keyword in Typescript. Maybe you could try with another property name ? https://github.com/Microsoft/TypeScript/issues/2536
Comment: Ah. I did wonder if type might be a reserved word, but then became confused because the code listed didn't seem to match what I wrote. I'll try to work out another appropriate name and see if that fixes the problem...
Comment: it works as expected with `tsc` against all targets. Probably a bug in @ngtools/webpack which does some very dangerous code transformations.
Comment: @hiper2d both are valid in that position.
Comment: I changed `type` to `widget` but it's still doing basically the same thing (exact reference has changed because of the additional letters in `widget` but everything else is the same).
Answer: You have an error in UIComponent type :
export class UIComponent {
  id: number; //HERE
  name: string;
  value: number;
  type: string;
}

Here a plunker :http://plnkr.co/edit/e6GrylSWznwbYD9VpK2C


Why is a simulation of a probability experiment off by a factor of 10?

Question: From a university homework assignment:
There are $8$ numbered cells and $12$ indistinct balls. All $12$ balls are randomly divided between all of the $8$ cells. What is the probability that there is not a single empty cell ($i.e.$ each cell has at least $1$ ball)?
The answer is $\large\frac{\binom{11}{7}}{\binom{19}{7}}$ which is about $0.0065$. I reached this result independently, and it was confirmed by the official homework solution of the university.
A friend of mine and I independently wrote Python simulations that run the experiment many times (tested up to $1,000,000$). We used both Pythons' random generator and several randomly generated lists from www.random.org. Results were similar and consistently hovering around $0.09$ which is a factor of $10$ or even a bit more off from the expected theoretical result.
Have we made some wrong assumptions?
Any ideas for this discrepancy?
P.S.: Here is the Python code that I wrote, and maybe there is some faulty logic there.
def run_test():
    global count, N

    def run_experiment(n_balls, n_cells, offset):
        cells = [0] * n_cells
        # toss balls randomly to cells:
        for j in range(n_balls):
            cells[random.randrange(0, n_cells)] += 1
            # cells[int(lines[offset + j])] += 1
        cells = sorted(cells)
        # print(cells)

        # check if there is an empty cell. if so return 0, otherwise 1:
        if cells[0] == 0:
            return 0
        return 1

    count = 0
    N = 1000000
    offset = 0
    N_CELLS = 8
    N_BALLS = 12
    # iterate experiment
    for i in range(N):
        result = run_experiment(N_BALLS, N_CELLS, offset=offset)
        count += result
        offset += N_CELLS

    print("probability:", count, "/", N, "(~", count / N, ")")

Comment: It seems the book solution assumes that all the ways to distribute the balls into the cells are equally likely--for example a distribution of (12,0,0,0,0,0,0) is just as likely as (2,2,2,2,2,2,0,0).  This is not consistent with a model that says each ball is dropped into a cell chosen independently and randomly, with each cell equally likely to be chosen, which I think is more realistic.
Comment: "Have we made some wrong assumptions?" Hard to tell, since you have shown neither the code that you have written nor specified the assumptions that you have made. Without mind-reading, this question is impossible to answer. If your question involves your code, you should show the relevant code in the question itself.
Comment: I suppose the issue must be in "randomly divided." What does it mean exactly? What is the distribution of probabilities between different outcomes? Was the same distribution simulated in the experiment and used in the formula?
Comment: Besides the distinguishability of the balls is how they are distributed between the cells. You can either assign a cell to each ball, uniformly at random, independently of all the other balls, or you can look at all the different distinguishable ball distributions and you pick one of those uniformly at random. That's the difference between your two approaches.
Comment: If you suppose that all possible distributions of *the numbers of balls* (not of balls themselves) between cells have the same probability, I wonder how you could simulate this in an experiment...
Comment: @Alexey I think this approach would work, but I don't have time to check the math: Instead of assigning a cell to each ball, you sample the amount of balls per cell. So, choose a # of balls for cell 1, uniformly. Then choose for cell 2, for less availbale balls, and so on. I think that should give a uniform distribution over the #balls/cell.
Comment: @JohnColeman It looks like the code was mistakenly removed by an edit conflict with another user, a few minutes after the question was asked. I've edited the question just now to restore the link.
Comment: @ChrisCulter I see, If the code is relevant (and it is) -- please put it in the question itself rather than link to it (since links decay over time).
Comment: @JohnColeman the code originally appeared in the post but dissappear for a while for some reason. It is now there. The code is commented to describe the method which we simulate. Regardless I've figured out the flaw in the design I'd the simulation. Thanks
Comment: @JohnColeman Sure, done!
Comment: I find it fascinating that such "simple" problems in statistics can be so tricky to unravel.
Answer: In reality, you will find it very difficult to put the balls in the cells without distinguishing between the balls, especially if you want equal probabilities so as to use counting methods for simulation.  Suppose you wanted to consider the probability all the balls went into the first cell: with distinguishable balls this probability is $\frac1{8^{12}}$ and is easily simulated though a rare occurrence;  with indistinguishable balls it is $\frac1{19 \choose 7}$ over a million times more likely but difficult to simulate
If the balls are distinguishable, the probability all eight boxes are full is $$\frac{8! \, S_2(12,8)}{8^{12}}$$ where $S_2(n,k)$ is a Stirling number of the second kind and $S_2(12,8)=159027$.  That gives a probability that each cell has at least one ball of about $0.0933$.  Is this similar to your simulation?
If you really want to simulate the indistinguishable balls case, despite it not being realistic physically outside Bose–Einstein condensate at temperatures close to absolute zero, you could use a stars and bars analogy.  Choose $7$ distinct positions for the cells walls from possible positions $\{0,1,2,3,\ldots,18\}$ for the balls and cell walls; a success is when none of the cell walls are at positions $0$ or $18$ and no pair of them are consecutive
Comment: Nit picking from a physicist:  any collection of Bosons will show this effect.  It's just that B-E condensates are one of the simplest for us to demonstrate.  Messing with , say, photons, is more difficult
Comment: @JimmyJames You *could* argue that the question is vague. It says the balls "are randomly divided" but doesn't describe how. Depending on the procedure, one gets different distributions. And the procedures you've described *are* plausible. Despite all that, I believe it's the convention for textbook problems like this one that all possible patterns are equally probable unless stated otherwise. And the textbook problem specifies "indistinct balls" for the precise purpose of constraining what those possible patterns are. We're meant to follow that, even if we think it's unmotivated and silly.
Comment: @JimmyJames: that is way it is physically difficult to get the indistinguishable case. Try a simpler thought experiment: take two indistinguishable balls and two distinguishable cells; what are the possible patterns and their probabilities?
Comment: I'm clearly missing something here.  Why would the probability of them all ending up in the same cell have anything to do with whether you can distinguish between them?  Why would being able to tell which ball is which change a ball's chance of ending up in the first cell?
Comment: It's your assertion that this is relevant which I'm not understanding.  There's nothing in the question that states or implies that the being able to tell one ball from another changes the probability of landing in the first cell which would seem to be 1/8 assuming each event is independent.  Your thought experiment has the same distribution as flipping a fair coin twice.  1/2 one head one tail, 1/4 two heads, 1/4 two tails.  If I flip a fair penny and then a fair dime, it has no effect on the distribution of head and tails.
Comment: This is indeed similar to my simulation. Thanks for the detailed answer!
Comment: I have a backgammon set with a set of blue dice and a set of white dice.  Each die is (for practical purposes) indistinguishable from it's partner i.e. I can't tell which one is which.  Are you saying that when I roll with one blue and one white, the distribution is different than when I roll with matched dice?
Comment: @JimmyJames Think of two photons that can go through a half reflecting mirror or bounce. If they were distinguishable you would get 4 results both go through, neither goes through, first goes through second doesn't and second goes through first doesn't. This gives a sample space of (T,T),(B,B),(T,B),(B,T) with each outcome equally likely. And so seeing one photon at each detector should be twice as likely as seeing both at either one. If they are indistinguishable though those two (T,B),(B,T) states collapse into one and you get 1/3 probability for each.
Comment: @davidK There will be no physical difference if you call them indistinguishable. But if you model them as indistinguishable there will be a difference.
Comment: @DavidK The word "indistinguishable" means you are not supposed to choose a classical model. The OP uses "indistinct" even in that case I would assume as part of any math assignment in probability that we are not using a classical model. To be perfectly honest I don't quite see why QM is important. The goal is to choose the correct model and that is the one where the permutations of the balls are not distinct states, and the probability is just a counting probability on the set of all states.
Comment: @ChrisCulter I'm with you.  The original question is vague.  What I'm trying to understand is the simpler problem stated in this answer that suggests that if the balls are distinguishable the probability is "over a million times more likely" to all end up in the same cell.  Unless identity of each ball that changes how the cell is selected, it doesn't matter whether they are distinguishable or not.  It's just counting.  No such mechanism is described here or in the original question.
Comment: @DRF I'm really not sure what quantum mechanics has to do with this.  It's not mentioned anywhere in the question.  But your example is wrong.  There are 4 possible outcomes.  2 go through, 0 go through, or 1 goes through.  The case that one goes through has two ways of happening  So it's chance is 50%.  The other two possibilities are 25%.  Whether the photons are distinguishable or not doesn't change anything.  The idea that the three outcomes are equally likely is incorrect based on how you have stated this.
Comment: @ChrisCulter "I believe it's the convention for textbook problems like this one that all possible patterns are equally probable unless stated otherwise."  Maybe I haven't done enough textbook problems (not recently anyway) but if that's really the case, we need different textbooks and/or textbook writers.  That's a terrible way to train people to think about probability.
Comment: @JimmyJames Consider asking a separate question of your own, either here or even better, on https://physics.stackexchange.com/ .
Comment: @JimmyJames That's exactly the point. If the photons are indistinguishable it doesn't have 4 outcomes, it only has three. I'm not a physicist but from what I remember this is exactly what actually happens and how you show that indistinguishability is a thing. If you perform the experiment and measure the probabilities you get thirds instead of 1/4,1/4 and 1/2.I agree that it's worth writing a new question here for the math side; physics for why we would care about indistinguishable items.
Comment: @DRF No.  You are describing both the physics and the probability incorrectly.  There are now three outcomes but the distribution between them is not even.
Comment: @JimmyJames I'm certainly describing the mathematics correctly. As to the physics I won't quibble since as I said I'm not a physicist. You keep insisting that the fact that the items are indistinguishable is of no consequence. That is just not true for the way we do the mathematical modelling. If we say there are 2 slots and 2 balls and the balls are indistinguishable and are assigned to the slots randomly with equal probability what we mean is that the probability space consists of three outcomes which are equally likely.
Comment: @JimmyJames As to the physics side behind it the one example that's easy and I could find are bosons and states. See the table at the bottom of the statistical properties of bosons and fermions on https://en.wikipedia.org/wiki/Identical_particles .
Comment: @DRF "That is just not true for the way we do the mathematical modelling. If we say there are 2 slots and 2 balls and the balls are indistinguishable and are assigned to the slots randomly with equal probability what we mean is that the probability space consists of three outcomes which are equally likely."  Maybe that's the way it's done but it's silly.  Why mention 2 balls then?  Just say there are three outcomes that are equally likely.  Maybe this is what it means when people talk about statistics not being mathematics.
Comment: @DRF "As to the physics side behind it the one example that's easy and I could find are bosons and states."  As far as I can tell, the experiment you described did not result in any sort of entanglement.  Maybe a more precise explanation of the actual procedure or reference to some sort of actual experiment would resolve that.
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/85149/discussion-between-drf-and-jimmyjames).
Comment: @ChrisCulter Regarding "the convention for textbook problems like this," if I roll two fair six-sided dice simultaneously after shaking them together in a box, what is the probability the sum is $3,$ and does the answer to that question change if I insert the word "indistinguishable" before the word "dice"?
Comment: I don't think the equiprobable distribution over the states of "indistinguishable balls" is at all difficult to simulate; I can even design a machine that literally sorts balls into bins with this distribution. On the other hand, I do not consider this to be the most "natural" interpretation of the homework question, which I think is ill-posed.
Comment: @DRF While QM is interesting, my comment concerned how one ought to interpret the word "indistinguishable" in the main question, in the context of a word problem in a math course at a university. I think the homework was ill-phrased and one should not write questions that way, but if forced to choose a model for the question I would choose a classical model; in your terms, the balls are _called_ indistinguishable but are not truly indistinguishable in physics. This particular homework is so badly worded that it is still ambiguous even then, but I think OP's interpretation is as good as any.
Answer: Consider the set $D$ of ways to distribute $12$ balls labelled [abcdefghijkl] among $8$ cells numbered [01234567]. This set has $8^{12}\approx7\times10^{10}$ elements.
Now consider the set $I$ of distinguishable ways to populate those same $8$ cells [01234567] with $12$ indistinct balls. This set has ${19\choose7}\approx 5\times10^4$ elements.
The assignment asks you to compute a probability of an event over the uniform distribution on $I$, if not in so many words. In principle, you could approximate this probability by sampling from the uniform distribution on $I$. But your strategy is to sample from the uniform distribution on $D$, and then map each sample to $I$! That's not the same.
Instead of taking the average of all the results, you need to take a weighted average, such that the weight compensates for the number of elements in $D$ that map to the same element of $I$. Hint, it's something like this:
weight = 1
for cell_population in cells:
  weight *= math.factorial(cell_population)

At least, that gets the right answer. Rigorously justifying that formula as a consequence of the mapping between $D$ and $I$ is left as an exercise to the reader.
Answer: The original problem is posed, so far as I can tell, to show the difference between combinations and permutations.  In nature, there is no such thing as indistinguishable balls.   Semi-infinite tests (e.g. Las Vegas) have shown this to be true.
Now, if the problem really wants you to use "indistinguishable" balls for the purposes of solving the problem, then yes, you need to use combinations and not permutations when calculating all the ways the indistinguishable balls are placed into the containers.
And of course, you need to use permutations for the numbered balls, as they are distinguishable from each other and from the collection of indistinguishable balls.
Now, I believe that Chris Culter's calculations reflect this difference.  Whether your Python code does this correctly we can't say until we see the code.
Comment: https://pastebin.com/5mKBxfbM
Comment: If we want to show the difference between combinations and permutations, we can ask for the number of ways to distribute $12$ indistinct balls among $8$ numbered cells; then ask for the number of ways to distribute the same balls in the same cells so that no cell is empty. This has the solver do all the calculations in the "solved" problem except for the final division, without requiring any assumptions about how the word "indistinct" affects probabilities.


Clarification on the derivation of variance confidence interval

Question: I'm trying to analyse the derivation of the confidence interval in a normally distributed sample.
To be specific, I have some problems understanding why we use certain quantiles.

In the picture above, why is $a$ equal to $\chi_{1-\frac{\alpha}{2}}^2$ and not $\chi_{\frac{\alpha}{2}}^2$?
I thought the quantile is related to the area to the left of a given point (due to the cdf being defined as $P(X \leq t)$), which in this case is $\frac{\alpha}{2}$. In my opinion, $a$ and $b$ should be switched. I'm even more confused since I've both ways of choosing the point, e.g. in my textbook there is:

which is the same as my reasoning.
What am I missing?
Comment: If $\alpha =0.05$ then you should have $a=\chi^2_{0.025}$ as the lower critical value and $b=\chi^2_{0.975}$ as the higher critical value, so I think you are correct
Answer: A 95% confidence interval is based on $Q = (n-1)S^2/\sigma^2 \sim \mathsf{Chisq}(df=n-1).$
Thus we can find numbers $L$ and $U$ so that
$$.95 = P\left(L \le Q = \frac{(n-1)S^2}{\sigma^2} \le U\right)
= P\left(\frac{1}{U} \le \frac{\sigma^2}{(n-1)S^2} \le \frac{1}{L}\right)\\
P\left(\frac{(n-1)S^2}{U} \le \sigma^2 \le \frac{(n-1)S^2}{L}\right),$$
so that a 95% CI for $\sigma^2$ is of the form
$$ \left(\frac{(n-1)S^2}{U},\:\frac{(n-1)S^2}{L}\right).$$
From a simpler point of view, as mentioned by @Henry, if you were to use $L$ for the denominator of the left-hand confidence limit and $U$ in the right-hand limit then you would have
$$ \frac{(n-1)S^2}{L} > \frac{(n-1)S^2}{U}.$$
Notes: (a) This kind of "reversal" of probability limits occurs frequently in making
confidence limits.
(b) For example, in the simple CI for normal $\mu$ of the form
$\bar X \pm 1.96\sigma/\sqrt{n}.$ the limits are really $\bar X - U\sigma/\sqrt{n}$ and $\bar X - L\sigma/\sqrt{n},$ where $U = 1.96$ and
$L = -1.96.$ But this is seldom noticed because of the symmetry of
the normal distribution.
(c) In making an unbiassed bootstrap CI, it is especially important to
be aware of this "reversal."


How to set up a IRC server that logs all messages?

Question: I want to set up a corporate IRC server to use for project discussions.
How can I make the IRC server keep a archive of all messages that are sent through the server? I want the messages available for browsing (also preferably searchable) over HTTP (using Apache).
How can I set up such a service?
Also, it would be a plus if a user connecting to a channel on the server could execute some command in the IRC client to (say) get the server to return the last 24 hours worth of messages on that channel.
(I am an IRC n00b)
Comment: If you use an IRCd that's compatible with [atheme](http://atheme.net/) you could use a raw output module. Alternatively, connecting a pseudo-server could log all traffic (including private messages).
Comment: There's also [a patch for ircd-hybrid](https://soulsphere.org/hacks/ircd-logging/) which adds logging.
Answer: Not sure about the server side, but it's not hard to make an IRC client that connects to rooms and logs everything said in them.
Edit: Try googling "irc logging bot", there are several available, including some that produce html/xhtml logs.
Comment: Thanks. I downloaded supybot (http://sourceforge.net/projects/supybot/). Will attemt to configure it to do what I need.
Comment: This is going to be a lot easier than having the server do the logging, and the same bot can respond to commands to return the transcript.
Answer: Inspire IRCd supports logging everything.


Does this song have a tempo or time signature?

Question:

Does this song have a tempo or time signature ?
How do you write and play this kind of music ?
Comment: this is aleatoric music: a maximization of randomness among several musical parameter like tempo and time sig.
Answer: It's tough to know how this was notated without seeing a score of some sort. With that said, you do ask a very good question: how do you notate and play music like this?
Some modern music does not have rhythm or meter in the way that we expect from music by someone like Mozart. Some scores have a listing of various musical gestures separated by durations of time. Consider, for instance, this excerpt from Penderecki's "Threnody for the Victims of Hiroshima" (the video includes the score where you can see more instances of this):

Notice that's there's no meter or rhythm per se, but there is a listing on the bottom showing that the first unit should last 15 seconds and the latter unit should last only 11. In this sense, I guess we could say that the tempo of the piece is 60bpm, but since we don't sense this as a listener, that's seems like a trivial claim to make.
Comment: Very interesting..So we could say this type of song may not have time signature or some rhythm like traditional songs ?
And it's kind of hard to tell from just listening the piece ?
Answer: While this piece probably has many fermatas in its notation, and it's probably in mixed meter (if not in free time), I'd say this piece has a tempo, and it's quite slow.
I'd generally notate much of the faster piano runs as if the first note of the run is at the start of one beat and the last note of the run is at the start of the next beat. Accelerandos may sometimes need to be notated as a result.
Answer: Often these kinds of incidental textures are written in a very fast meter conducted in a "one" pattern.  My guess in this work is 3/4 MM=184.
Answer: I'll see where I can get to over the next day or two when I have time. It's an interesting challenge!

The first stage of the analysis is to note that there is a repeat at 1.11 on the video. This means that they are not just improvising in free rhythm.
Having noticed the repeat, with a bit of fiddling, you can start at 0.00 in one instance of YouTube at the same time as starting at 1.11 in another.
You will find that it is an exact repeat except for slight differences in overtones on the wind instrument (What the heck is that? It's not a flute and the notes are very 'dirty'). In fact the timing of the repeat is so precise that I suspect they are playing in time with a click track.

Conclusions so far. It's a composed piece with a straight repeat, played in metronomic rhythm.
I'll have another go tomorrow and add to this answer.
Comment: Yea I don't know why but I kind of feel this song has some rhythm and it ain't just playing things randomly. But the space between them makes it hard to recognize..
Answer: No, this song does not have a tempo
Update: This song may or may not have a tempo.
And you can safely argue that there is no time signature either or that it is irrelevant.
Playing it:
In a performance or rehearsal setting, you'd need a band leader, or conductor to visually/physically cue entrances or beginnings sections.
Writing it:
TBD.
Comment: It may well have a tempo & time sig. I've written similar ambient stuff for TV/film & whilst there is an internal map, it's just not apparent to the casual listener.
Comment: Fair enough, you have my upvote!


QQ plot looks normal but Shapiro-Wilk test says otherwise

Question: In R, I have a sample of 348 measures, and want to know if I can assume it is normally distributed for future tests.
Essentially following another Stack answer, I am looking at the density plot and the QQ plot with:
plot(density(Clinical$cancer_age))

qqnorm(Clinical$cancer_age);qqline(Clinical$cancer_age, col = 2)

I do not have a strong experience in Statistics, but they look like examples of normal distributions I have seen.
Then I am running the Shapiro-Wilk test:
shapiro.test(Clinical$cancer_age)

> Shapiro-Wilk normality test

data:  Clinical$cancer_age
W = 0.98775, p-value = 0.004952

If I interpret it correctly, it tells me it is safe to reject the null hypothesis, which is that the distribution is normal.
However, I have encountered two Stack posts (here, and here), which strongly undermine the usefulness of this test. Looks like if the sample is big (is 348 considered as big?), it will always say that the distribution is not normal.
How should I interpret all that? Should I stick with the QQ plot and assume my distribution is normal?
Comment: Just to add to Roland's comments- many tests that formally assume a normal distribution are actually fairly robust under slight departures from normality (e.g. because the test statistic's distribution is asymptotically correct).  If you can elaborate about what you intend to do you may get more helpful answers.
Comment: The q-q plot seems to show a departure from normal in the tails. Also any useful test of goodness of fit will reject in very large samples simply because there will be small departures from normality that are detected.. It is not a criticism of the Shapiro - Wilk test but rather a feature of testing for goodness of fit.
Comment: Why is assuming a normal distribution important to you? What do you intend to do based on that assumption?
Comment: I think it would be worth examining the small number of extreme observations just to check if they are measurement errors.
Comment: @mdewey, sharp observation! It is not age at incidence, but the tumor's "age" measured by DNA methylation.
Comment: The variable is labelled cancer_age. Is it really age at incidence? It must be a fairly unusual cancer.
Comment: @Roland, I mainly want to compare these data with categorical variables, essentially testing for significant differences between the averages of each category (if I'm understanding well how it works, not super familiar with this). So I'm essentially looking if I can safely assume it is normally distributed so I can choose which tests I should use.
Comment: @mdewey perhaps the negative values are for cancer detected in utero! :D
Comment: Is it this: https://dnamage.genetics.ucla.edu regression model?  (Not really relevant to your question, just curious)
Comment: @P.Windridge, I did not compute the DNAm ages myself and not sure how my prof did it (this is a uni project). But this is right on topic, and I've seen somewhere seqs were originally from Illumina, so I wouldn't be surprised this is the method he used (or at least something close)...
Answer: You do not have a problem here. Your data my be slightly non-normal, but it is normal enough that it shouldn't pose any problems. Many researchers do statistical tests assuming normality with far less normal data than those that you have.
I would trust your eyes. The density and Q-Q plots look reasonable, despite some slight positive skew on the tails. In my opinion, you do not need to worry about non-normality for these data.
You have an N of about 350, and p-values are very dependent on sample sizes. With a large sample, almost anything can be significant. This has been discussed here.
There are some incredible answers on this very popular post that basically comes to the conclusion that conducting a null-hypothesis significance test for non-normality is "essentially useless." The accepted answer on that post is a fabulous demonstration that, even when data were generated from a nearly Gaussian process, a high enough sample size makes the non-normal test significant.

Sorry, I realized that I linked to a post you had mentioned in your original question. My conclusion still stands, though: Your data are not so non-normal that it should pose problems.
Comment: "Just because some.researchers are very sloppy doesn't mean you can be a bit sloppy :)" Fair point; that was a bad argument on my part. "However I agree with that many statistical tests that formally assume normality are actually fairly tolerant of what you feed them." Yes, indeed. Any quant professor I've had has looked at Q-Q plots like this and said, "Yeah, that's OK."
Comment: Just because some.researchers are very sloppy doesn't mean you can be a bit sloppy :). However I agree with that many statistical tests that formally assume normality are actually fairly tolerant of what you feed the
Answer: Your distribution is not normal.  Look at the tails (or lack thereof).  Below is what you would expect from a normal QQ plot.

Refer to this post on how to interpret various QQ plots.
Keep in mind that while a distribution may not technically be normal, it may be normal enough to qualify for algorithms which require normalcy.
Comment: @Josh, the middle of the distribution hardly matters for hypothesis tests; it's the tails that matter. You have that backwards.
Comment: What are you talking about, I ran 9 normal qq plots form samples directly form a normal distribution using the code

set.seed(100)

par(mfrow = c(3,3))

for(i in 1:9){

x <- rnorm(350)

qqnorm(x)

qqline(x)

}

and plot (3,2) look very similar to OP's situation.
Comment: Typically, you don't want to focus on the tails because they will often be weird, although extremely bad tails will give you poor results. You really want to focus on the middle.
Comment: you are incorrect Josh. please appeal to a normal test to check if the null hypothesis of normalcy is rejected.
Comment: @Josh it is one thing to say that the distribution is "normal enough", it is another thing entirely to say that the distribution is normal.  try Scikit-Learn's `stats.normaltest(x)`
Comment: You're right. I initially read your post as the qq plots were not normal enough, and I apologize.


React App Gives Error At Serving Bundled Files

Question: I am building a react app that takes data from user and save it to a MongoDB database and list the data back via Node-Express backend Server.
The app works fine on dev server and it doesn't give any error at building but when Node server serving the files browser gives errors. The errors coming from Context API's state variables.
There is twelve components (almost same components) using twelve different state and all of them gives same error. To keep it simple I posted just one of them.
I tried using different bundler(Parcel.js), nothing changed.
I make a fresh create-react-app and copied my code then builded there. It didn't work either.
The Error on Browser Console
(https://drive.google.com/file/d/1lo9FKImrT-SoxulHa3vxPgRriu0laAkO/view?usp=sharing)
(https://drive.google.com/file/d/10e3zHW-a60p461y10gxPjaMHjO4E8xWt/view?usp=sharing)
This is Line 35671
/*#__PURE__*/react_default.a.createElement("thead", null, /*#__PURE__*/react_default.a.createElement("tr", null, /*#__PURE__*/react_default.a.createElement("th", null, "Kamp\xFCs Ad\u0131"), /*#__PURE__*/react_default.a.createElement("th", null, "Adresi"))), /*#__PURE__*/react_default.a.createElement("tbody", null, kampus.map(function (data) {
    return /*#__PURE__*/react_default.a.createElement(DataRow, {
      key: data._id,
      data: data
    });

This is the Component That Error Occurred:
import React, { useContext, useState, useEffect } from 'react';
import { GlobalContext } from "../../../context/GlobalContext"
import Form from "react-bootstrap/Form";
import Button from "react-bootstrap/Button";
import Table from 'react-bootstrap/Table';
import Accordion from 'react-bootstrap/Accordion';
import Card from 'react-bootstrap/Card';
import Modal from 'react-bootstrap/Modal';
import InputGroup from 'react-bootstrap/InputGroup';

export default function Campus() {

    const { addData, kampus, getData, delData } = useContext(GlobalContext);

    const [name, setName] = useState("");
    const [address, setAddress] = useState("");

    useEffect( () => {
        getData();
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);

    const onSubmit = async (e) => {

        e.preventDefault();

        const newCampus = {
            dataType: "kampus",
            name: name,
            address: address
        }

        // let form = new FormData(newCampus)
        await addData(newCampus);
        setName("");
        setAddress("");
    }

    function DataRow({data}) {
        return (

                {data.name}
                {data.address}
                <Button style={{position: "absolute"}} variant="danger" onClick={() => delData(data._id)}>Sil</Button>
                <Button style={{position: "absolute"}} variant="info" onClick={() => updateData(data._id)}>Düzenle</Button>

        )
    }

    return (
        <>
        <Accordion className="mt-5">
        <Card>
            <Card.Header>
                <Accordion.Toggle as={Button} variant="secondary" eventKey="0" >
                    Kampüs Ekle
                </Accordion.Toggle>
            </Card.Header>
            <Accordion.Collapse eventKey="0">
                <Form className="mt-4" onSubmit={onSubmit}>
                    <Form.Group className="mr-4 ml-4">
                        <Form.Control
                            className="mb-3"
                            type="text"
                            placeholder="Please Add Name"
                            value={name} onChange={ (e) =>setName(e.target.value) }
                            />
                        <Form.Control
                            type="text"
                            placeholder="Please Add Address"
                            value={address} onChange={ (e) =>setAddress(e.target.value) }
                            />
                    </Form.Group>
                        <Button className="mb-4 mr-4 ml-4" variant="primary" type="submit">
                           Save
                        </Button>
                </Form>
            </Accordion.Collapse>
        </Card>
        </Accordion>

// This Piece is Where the Line 35671 is correspond

                        Name
                        Address

                    {kampus.map( data => ( <DataRow key={data._id} data={data}/> ))}

        </>
    )
}

Request Activity
I use Morgan to keep track of requests and this is the list of it.
Server is Listeing on 3010
MongoDB Connected: testcluster1-shard-00-02-bigu6.mongodb.net
GET /data-control 304 12.811 ms - -
GET /bundle.js 304 0.667 ms - -
GET /data-control 304 1.258 ms - -
GET /data-control 304 1.168 ms - -
GET /data-control 200 7.051 ms - 232
GET /data-control 304 7.551 ms - -
GET /data-control 200 7.380 ms - 232
GET /data-control 200 7.723 ms - 232
GET /data-control 200 6.813 ms - 232
GET /data-control 200 14.077 ms - 232
GET /index.js.map 200 2.149 ms - 232
GET /index.js.map 304 0.798 ms - -

This is the Code of Serving Files
// SERVE STATIC BUILD FILE
app.use(express.static("client/build"));

app.get("*", (req, res) => {
    res.sendFile(path.join(__dirname, "client", "build", "index.html" ))
})

This is How Server Response the GET Request:
// IMPORT ALL MODALS
const Kampus = require("../models/Kampus");
const Bolum = require("../models/Bolum");
const Derslik = require("../models/Derslik");
const Fakulte = require("../models/Fakulte");
const OgrEleman = require("../models/OgrEleman");
const MekanKati = require("../models/MekanKati");
const MekanTuru = require("../models/MekanTuru");
const MekanOzellik = require("../models/MekanOzellik");
const CalismaTuru = require("../models/CalismaTuru");
const AkadPoz = require("../models/AkadPoz");
const IdaPoz = require("../models/IdaPoz");
const DersSuresi = require("../models/DersSuresi");

exports.getData = async (req, res, next) => {
    try {
        const kampus = await Kampus.find();
        const bolum = await Bolum.find();
        const derslik = await Derslik.find();
        const fakulte = await Fakulte.find();
        const ogrEleman = await OgrEleman.find();
        const mekanKati = await MekanKati.find();
        const mekanTuru = await MekanTuru.find();
        const mekanOzellik = await MekanOzellik.find();
        const calismaTuru = await CalismaTuru.find();
        const akadPoz = await AkadPoz.find();
        const idaPoz = await IdaPoz.find();
        const dersSuresi = await DersSuresi.find();

      return res.status(200).json({
          success: true,
          kampus: kampus,
          bolum: bolum,
          derslik: derslik,
          fakulte: fakulte,
          ogrEleman: ogrEleman,
          mekanKati: mekanKati,
          mekanTuru: mekanTuru,
          mekanOzellik: mekanOzellik,
          calismaTuru: calismaTuru,
          akadPoz: akadPoz,
          idaPoz: idaPoz,
          dersSuresi: dersSuresi
      });
    }
    catch (err) {
        return res.status(500).json({
            success: false,
            error: "Server Error"
        });
    }
}

This is Global Context:
import React, {createContext, useReducer} from 'react';
import AppReducer from './AppReducer';
import initalState from "./State";
import axios from "axios";

export const GlobalContext = createContext(initalState);

export function GlobalProvider({ children }) {

    const [state, dispatch] = useReducer(AppReducer, initalState);

    // ACTIONS

    // GET DATA

    async function getData () {
        try {
            const res = await axios.get("http://localhost:3010/data-control");

            dispatch({
                type: "get-data",
                payload: res.data
            });
        }
        catch (err) {
            console.log(err)
        }
    }

    // ADD DATA

    async function addData (data) {
        try {
            const res = await fetch('http://localhost:3010/data-control', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(data),
            });

            let newRes = await res.json()

            dispatch({
            type: "add-data",
            payload: newRes.data,
            dataType: newRes.case
            })

        }
        catch (err) {
            console.log(err.message)
        }
    }

    // DELETE DATA

    async function delData (id) {
        try {
            await axios.delete(`http://localhost:3010/data-control/${id}`);

            dispatch({
                type: "del-data",
                payload: id
            })
        }
        catch (err) {
            console.log(err.message)
        }
    }

   return(
        <GlobalContext.Provider value={{
            kampus: state.kampus,
            fakulte: state.fakulte,
            bolum: state.bolum,
            ogrEleman: state.ogrEleman,
            derslik: state.derslik,
            ders: state.ders,
            mekanKati: state.mekanKati,
            mekanTuru: state.mekanTuru,
            mekanOzellik: state.mekanOzellik,
            calismaTuru: state.calismaTuru,
            akadPoz: state.akadPoz,
            idaPoz: state.idaPoz,
            dersSuresi: state.dersSuresi,
            delData,
            addData,
            getData,
        }}>
            {children}
        </GlobalContext.Provider>
    )
}

My State File:
const state = {
    kampus:[],
    bolum:[],
    derslik:[],
    fakulte:[],
    ogrEleman:[],
    ders: [],
    mekanKati: [],
    mekanTuru: [],
    mekanOzellik: [],
    calismaTuru: [],
    akadPoz: [],
    idaPoz: [],
    dersSuresi: []
}

export default state;

This is How App Reducer Handles the State:
export default (state, action) => {
    switch (action.type) {

        case "get-data":

            return {
                ...state,
                kampus: action.payload.kampus,
                bolum: action.payload.bolum,
                derslik: action.payload.derslik,
                fakulte: action.payload.fakulte,
                ogrEleman: action.payload.ogrEleman,
                akadPoz: action.payload.akadPoz,
                idaPoz: action.payload.idaPoz,
                calismaTuru: action.payload.calismaTuru,
                mekanKati: action.payload.mekanKati,
                mekanTuru: action.payload.mekanTuru,
                mekanOzellik: action.payload.mekanOzellik,
                dersSuresi: action.payload.dersSuresi,
            }
    }
}

Webpack Config:
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

const rules = [
    {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
            loader: "babel-loader"
        }
    },

    {
        test: /\.css$/,
        // exclude: /node_modules/,
        use: ["style-loader", "css-loader"]
    },

    {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader"
          }
        ]
      }
]

module.exports = {
    entry: path.join(__dirname, "src", "index.js"),
    output: {
        filename: "bundle.js",
        path: path.resolve(__dirname, "./build")
    },

    devServer: {
        historyApiFallback: true,
    },

    optimization: {
        minimize: false
    },

    module: {rules},
    plugins: [
        new HtmlWebpackPlugin({
            template: "./public/index.html",
            filename: "./index.html"
        })
    ]
}

Babel:
{
    "presets": ["@babel/preset-env", "@babel/preset-react"],
    "plugins": [
        ["@babel/transform-runtime"]
    ]
}

Comment: Hi Bugra :) So you get an 200 response right ? I am not sure but I think the server is returning an empty json. One more thing, are you able to insert the data in the database ?
Comment: For the server response I suggest you to hold the json in a variable and check if it's not empty or check you have at least one variable (kampus), you may want to return an 404 then. When the server respond 200 (success) you may not need to have it in your json.
Answer: Maybe this will do:
  //I removed the success: true
  let jobj = {
      kampus: kampus,
      bolum: bolum,
      derslik: derslik,
      fakulte: fakulte,
      ogrEleman: ogrEleman,
      mekanKati: mekanKati,
      mekanTuru: mekanTuru,
      mekanOzellik: mekanOzellik,
      calismaTuru: calismaTuru,
      akadPoz: akadPoz,
      idaPoz: idaPoz,
      dersSuresi: dersSuresi
  };

  JSON.stringify(jobj);

  //some check up here (maybe you will send a 404 response)
  ...

  //then you send the json
  return res.status(200).json(jobj);


Is there an explicit maximal simple group?

Question: It is not hard to prove the following lemma:
LEMMA: Let $(G_i)_{i \in I}$ be a chain of simple groups.
Then $G = \bigcup_{i \in I} G_i$ is a simple group.
Let $N$ be a normal subgroup of $G$ and define $N_i = N \cap G_i$ (all $i \in I$).
$(N_i)_{i \in I}$ is a chain such that $N = \bigcup_{i \in I} N_i$. Let $n \in N \trianglelefteq G$, then $n \in G_i$, some $i \in I$; then $n \in N \cap G_i = N_i$.
Observe that $N_i \trianglelefteq G_i$, a simple group (all $i \in I$). Thus, $N_i = 1$ or $G_i$ (all $i \in I$). Now we have two cases:

$N_i = 1$ (all $i \in I$). Then $N = \bigcup N_i = 1$
$N_i = G_i > 1$, some $i \in I$. If $1 < N_i \leq N_j$, we have $N_j \neq 1$ and so $N_j = G_j$ (all $j \in J$). It follows that $N = \bigcup N_i = G$.

QED.
Zorn's lemma now implies the existence of "maximal simple groups." These would be simple groups which cannot be imbedded in any other simple groups. Can we explicitly construct such a group? Or would such a group be purely nonconstructive (if we can even prove such a thing)?
Comment: You can use Cayley's Theorem to embed any simple group to a simple group with larger cardinality.
Answer: You cannot invoke the Zorn-Kuratowski-Lemma here: The collection of all simple groups is not a partially ordered set; it is a proper class. Therefore, at least your argument for why there must exist a maximal simple group does not work (although such a group might exist by different reasoning, which I do not know).
If Zorn's Lemma would work for partially ordered classes as well, then you would also be able to prove the existence of a maximal group – or even a maximal set – which clearly does not exist.  To illustrate the failure, one proof of Zorn's Lemma uses a well-ordering of your poset; this of course  requires that you have a set and not a proper class.


Simplicial complexes of linear independencies

Question: Let us call a simplicial complex a complex of linear independencies if its vertices can be mapped to (non-zero elements of) a linear (vector) space so that a finite set of vertices span a simplex if and only if their images are linearly independent.
Do such simplicial complexes have an official name?  Do they have special properties or interesting applications? Have they been studied?
Note that not every simplicial complex is a complex of linear independencies.  For example, a simplicial complex with three $0$-dimensional simplices (vertices) and a single $1$-dimensional simplex (edge) is not.
P.S.  I suppose one can also define and study simplicial complexes of algebraic independencies, etc.
Comment: I'm outside my area of expertise here, but I think  this might be connected to the idea of a Matroid: https://en.wikipedia.org/wiki/Matroid
Comment: It seems like this might be the answer.
Comment: Oscar is correct I think, since sets of linearly independent vectors satisfy the exchange property and are independence systems (also called abstract simplicial complexes), which is what the definition of a matroid is (I think).
Comment: @Alexey Thanks!
Answer: These are examples of Matroids (although not every matroid arises in this way).


Non-isomorphic locally ringed spaces which represent isomorphic functors $\mathsf{CommRing} \to \mathsf{Set}$.

Question: It's well known that the restricted Yoneda functor $よ : \mathsf{Schemes} \to \operatorname{Fun}(\mathsf{CommRing},\mathsf{Set})$ is an embedding, so that (in particular) if $X$ and $Y$ are schemes such that $よ(X) \cong よ(Y)$, then $X \cong Y$. This is the key idea of the "functor of points approach" to algebraic geometry (which then proceeds to classify precisely which co-presheaves on commutative rings are in the essential image of $よ$).
It's my understanding that the restricted Yoneda $よ : \mathsf{LRS} \to \operatorname{Fun}(\mathsf{CommRing},\mathsf{Set})$ is no longer an embedding, where $\mathsf{LRS}$ is the category of locally ringed spaces. Moreover, I expect there to exist non-isomorphic locally ringed spaces $X$ and $Y$ such that $よ(X) \cong よ(Y)$.
Does anyone know a simple example of this failure of essential injectivity?
Edit: Just realized I messed up the variance at first, hopefully I got it right now.
Comment: Why does it feel like people are using よ now for the Yoneda embedding? I've seen Barwick and his collaborators use this, but I'm not sure why it's been popularized.
Comment: (I deleted my comment because I realize I had misread what you were asking for; I thought you were implicitly actually asking about conservativity.)
Comment: As for why I use it, it's fun and cool-looking :)

(For anyone reading who's unaware, I should mention that よ is a Japanese character which represents the sound "yo", as in "Yoneda")
Comment: Isn't conservativity the condition that "$F(f)$ is an iso" implies "$f$ is an iso"? Conservativity clearly implies essential injectivity if $F$ is full, but that's the only obvious relationship I see between these conditions.
Comment: (For context: a now-deleted comment claimed that essential injectivity is usually called conservativity, but my understanding is that these are different conditions)
Comment: Cheers, no worries there -- I just prefer to keep my comment up with context in case others have the same question :)
Comment: It is not a word -- it is a character in the hiragana syllabary. Similarly to a letter like "y" in the english alphabet, it is used to compose words, but has no meaning on its own. For example, the word "ようこそ" (which would be romanized as "youkoso") means something like "welcome!" Hiragana is just one of three aspects to japanese writing -- there are also characters (called kanji) that have intrinsic meaning and can form entire words (or just parts of them), and another syllabary called katakana which is used to write loanwords from other languages (among other things).
Comment: If your question was about the word "Yoneda", this is the surname of the Japanese mathematician [Nobuo Yoneda](https://en.wikipedia.org/wiki/Nobuo_Yoneda).
Comment: +1 for using よ. (Fun Fact: My advisor in my undergrad was one of the two who first introduced よ for the Yoneda Embedding.)
Comment: What is that Japanese word ?
Comment: @diracdeltafunk, wow, I think it's the most creative math symbol.
Answer: If $A$ is a local ring, let $X_A$ denote the locally ringed space with one point with $\mathcal{O}_{X_A}(X_A)=A$.  If $B$ is a ring, then a morphism of ringed spaces $\operatorname{Spec} B\to X$ is just given by a homomorphism $f:A\to B$.  In order for this to be a morphism of locally ringed spaces, $f(m)$ must be contained in every prime ideal of $B$, where $m$ is the maximal ideal of $A$.  That is, $f(m)$ must be contained in the nilradical of $B$.  If $m$ is finitely generated, this means $f$ must factor through the quotient $A/m^n$ for sufficiently large $n$.
In particular, this means that morphisms of locally ringed spaces $\operatorname{Spec} B\to X$ actually depend only on the completion $\hat{A}$ of $A$ with respect to $m$, since $\hat{A}/(m\hat{A})^n\cong A/m^n$ for all $n$.  So, the morphism $X_{\hat{A}}\to X_A$ becomes an isomorphism after applying the functor $よ : \mathsf{LRS} \to \operatorname{Fun}(\mathsf{CommRing},\mathsf{Set})$.
Or, let $A$ be a valuation ring whose value group $\Gamma$ is strongly nonarchimedean in the sense that for each positive $x\in\Gamma$, there is a positive $y\in\Gamma$ such that $ny<x$ for all $n\in\mathbb{N}$.  (For instance, $\Gamma$ could be the ordered ring $\mathbb{Z}[x]$ where $x$ is infinitesimal.)  Note that then if $I\subset A$ is any ideal whose radical is the maximal ideal $m$, then $I$ must be equal to $m$, since $I$ must contain elements of arbitrarily small positive valuation.  This means that if $f:A\to B$ is any homomorphism such that $f(m)$ is nilpotent, $f(m)$ must actually be $0$.  By the first paragraph above, this means that morphisms $\operatorname{Spec} B\to X$ are just in bijection with homomorphisms $A/m\to B$.  In other words, the natural morphism $\operatorname{Spec} A/m\to X_A$ becomes an isomorphism after applying $よ$.

Here is a rather different sort of example, inspired by a now-deleted answer by Aragogh.  Let $X$ be a $T_1$ locally ringed space with the following property: for each $x\in X$, there is a neighborhood $U$ of $x$ and a section $a\in \mathcal{O}_X(U)$ that vanishes at $x$ but at no other point of $U$ (where by "vanishing at a point" I mean its image in the stalk at that point is in the maximal ideal).  For instance, $X$ could be a nice (say, metrizable) topological space equipped with the sheaf of continuous real-valued functions.  I claim that if $Y$ is an affine scheme and $f:Y\to X$ is a morphism of locally ringed spaces, then the underling map of topological spaces is locally constant.
To prove this, suppose $y\in Y$ and $f$ is not locally constant at $y$. We know that $f$ induces a local homomorphism $\mathcal{O}_{X,f(y)}\to\mathcal{O}_{Y,y}$.  Moreover, each prime ideal $p$ of $\mathcal{O}_{Y,y}$ corresponds to a generization of $y$ which $f$ must map to the same point (since $X$ is $T_1$), and the corresponding homomorphism $\mathcal{O}_{X,f(y)}\to\mathcal{O}_{Y,p}$ is just obtained by composing with the localization map $\mathcal{O}_{Y,y}\to \mathcal{O}_{Y,p}$.  Since all of these compositions with localizations are local homomorphisms, our homomorphism $\mathcal{O}_{X,f(y)}\to\mathcal{O}_{Y,y}$ must actually map the maximal ideal of $\mathcal{O}_{X,f(y)}$ into the nilradical of $\mathcal{O}_{Y,y}$ (since its image must be contained in every prime ideal).
Now take a neighborhood $U$ of $f(y)$ and a section $a\in \mathcal{O}_X(U)$ that vanishes at $f(y)$ and nowhere else.  Since the image of $a$ in $\mathcal{O}_{Y,y}$ is nilpotent, we may replace $a$ with a power of itself and assume there is some neighborhood $V\subseteq f^{-1}(U)$ of $y$ such that the image of $a$ in $\mathcal{O}_Y(V)$ is $0$.  Since $f$ is not locally constant at $y$, there exists some $z\in V$ such that $f(z)\neq f(y)$.  But then $a$ is invertible in a neighborhood of $f(z)$, so the image of $a$ in $\mathcal{O}_{Y,z}$ is invertible.  This is a contradiction, since the map $\mathcal{O}_X(U)\to\mathcal{O}_{Y,z}$ factors through the map $\mathcal{O}_X(U)\to\mathcal{O}_Y(V)$ that maps $a$ to $0$.
So, every morphism from an affine scheme to $X$ is locally constant.  Now let $D(X)$ be $X$ with the discrete topology, equipped with the sheaf of local rings that has the same stalks as $X$.  The identity function $i:D(X)\to X$ has an obvious structure of a morphism of locally ringed spaces, and a locally constant morphism to $X$ is just one that factors (uniquely) through $i$.  So, $よ(i)$ is an isomorphism.
This gives rise to a bunch of other related examples.  For instance, if $M$ and $N$ are two nonempty manifolds of the same dimension $d>0$, equipped with the sheaves of continuous (or smooth) real-valued functions, note that $D(M)$ and $D(N)$ are isomorphic: they are each just a disjoint union of $2^{\aleph_0}$ singletons whose local ring is the ring of germs of real-valued functions at a point of $\mathbb{R}^d$.  It follows that $よ(M)$ and $よ(N)$ are isomorphic (though this isomorphism does not come from a map between $M$ and $N$).
In fact, we can go further.  If $X$ is a topological space, $x\in X$, and $(A,m)$ is the local ring of germs of real-valued continuous functions at $x$, then $A$ has the following property.  For each nonzero $a\in m$, there exists a nonzero $b\in m$ such that $a$ is divisible by $b^n$ for all $n\in\mathbb{N}$.  Indeed, you can take $b=g(a)$ where $g:\mathbb{R}\to\mathbb{R}$ is a continuous function such that $g(0)=0$ and as $t\to 0$, $g(t)$ approaches $0$ more slowly than $|t|^{1/n}$ for each $n$.  This property means that the only ideal of $A$ whose radical is $m$ is $m$ itself.  As in the third paragraph above, this means the canonical morphism $\operatorname{Spec} \mathbb{R}\to X_A$ becomes an isomorphism after applying $よ$.  It follows that if $X$ is a nice space as above equipped with its sheaf of continuous real-valued functions, then actually the canonical morphism $\coprod_{x\in X}\operatorname{Spec}\mathbb{R}\to X$ becomes an isomorphism after applying $よ$, since $よ$ can't see the difference between the points of $D(X)$ and copies of $\operatorname{Spec}\mathbb{R}$.  In particular, this means that if $X$ and $Y$ are two metrizable spaces of the spaces of the same cardinality equipped with their sheaves of continuous real-valued functions, then $よ(X)\cong よ(Y)$.
(In fact, you can generalize this a bit further: all of this applies to spaces on which real-valued continuous functions separate points, not just metrizable spaces.  To sketch the proof, the argument above shows that if $Y$ is an affine scheme and $f:Y\to X$ is a morphism of locally ringed spaces, then every continuous real-valued function on $X$ actually pulls back to a locally constant real-valued function on $Y$.  If $f$ were not locally constant, then its image would be infinite, and then since functions separate points on $X$, you can conclude that the functions on $X$ pull back to an infinite-dimensional algebra of locally constant functions on $Y$, which must come from an infinite subalgebra of the Boolean algebra of clopen subsets of $Y$.  But then you can construct a uniformly convergent infinite sum of such functions which is not locally constant, and this sum will still come from a continuous function on $X$, giving a contradiction.)
Comment: @diracdeltafunk: I've now added an example where one of the spaces is a scheme (in fact, Spec of a field)!
Comment: The overall moral that I seem to take from all of these examples is that because schemes are so full of generic points, it is very hard to map them to $T_1$ locally ringed spaces.  The locality condition on morphisms at generic points becomes *really* restrictive when mapping to a $T_1$ space.
Comment: What I was about to write (surprisingly with the notation $X_A$ too !), +1. This is actually better than the question asked for, because it shows that it's not even conservative. Do you know an example where one of the two is a scheme ?
Comment: I knew there was a counterexample based on $X_A,$ but I was too hasty! +1
Comment: Thank you! I'll take a careful look at this in a few hours.
Comment: @MaximeRamzi: Not off the top of my head.  My vague intuition is that it shouldn't be possible if one of the spaces is a scheme but I wouldn't be very surprised if I'm wrong.
Comment: I have an idea where one of the spaces is a scheme! I'm not currently in an environment where I can work out the details and verify it, but I'll update in a few hours.
Comment: Thank you for these fascinating examples! My idea didn't quite work on the nose, but I'll think about some modifications. Anyway, I really appreciate all the effort you put into this answer.


Create two nodes with url aliases on one submission

Question: I have a content type "News". With URL aliases pattern and token the URL is like this: news/[node:title].
Is it possible to create two nodes on one submission with different URL aliases? Let's say on submitting on the news node, it will create two nodes with two URLs like this: The first one is news/[node:title] and the second will be news2/[node:title].
The whole point is not to create a two different content types, but one and the clone node will have a different URL aliases, so I can filter a new menu block with visible path news2/* and make other logic too.
Answer: Use hook_node_insert() where you can additionally create another node. I am not sure that the url alias will already be available.
If not use the following code, found at Programmatically create alias using pathauto for node, to get the original URL alias and then edit it to match your criteria:
module_load_include('inc', 'pathauto'); // include the inc file for Pathauto module
/*
pathauto_create_alias($module, $op, $source, $data, $type, $language)
@param $module: Your module name
@param $op: The operation (insert, update, return, bulkupdate)
@param $source: Internal Drupal path (i.e.: node/1)
@param $data: Addition data used to generate a pathalias, in this case the node object
@param $type: Type of content that will be used to match a pattern, defined in the backend url alias patterns
@param $language: If you have a multlingual website, you need to pass the language for which you want to generate the url alias
*/

pathauto_create_alias('your_module_name', 'insert', 'node/1', array('node' => $node), $node->type, $language->language); // Language is optional

Set the node alias and create a node with node_save().
Comment: I don't see any way to fetch the URL alias and change it programmatically with hook_form_alter(). Can you please expand your answer?
Answer: You can use hook_node_presave copy the $node entity, change its URL and then save it with node_save or even better use entity_metadata_wrapper. I do not know if its recommended but i think it is a solution.
You can check if the node is new or not with $node->is_new i think
Comment: Hi, Gianni, Thank you for answer. OK, I've copied the $node with copy PHP function like this $node2 = copy $node; but now how can I set a different URL alias in $node2?
Comment: $clone_node = clone $node as seeing here [clone PHP](http://stackoverflow.com/questions/4123571/how-to-make-a-copy-of-an-object-without-reference) looks like; Are u using devel module? you can use dpm($node); or dpm($node_clone); to see its fields, properties and stuff and then cheing like $node->url = 'urlnew';
Comment: I've managed to copy and change the url like this: $node2 = clone $node;  and $node2->path['alias'] = 'news2/' . $node->nid; now left to see how can I save the clone node with node_save().
Comment: Hmmm wait! i see a problem; original $node already has a nid? watch out for nids!
Comment: Yes, 'cos I've already created that node and I'm checking devel with updating the node. Yeah, good point I cannot use nid here, but how do I set a new url alias like this news2/[node:title] ? btw I don't see any $node->url in presave function.
Comment: $node entity sure has a title property, but what worries me is the nids, you do not want to node_save the same node and changin its nid manually hell no! better go with Potney Switters answers and build the $node from scrach and let  drupal do the rest like nid, timestamps and stuff
Comment: Wait a minute. When I create a new node, I'm trying to save two nodes simultaneously, but with different path and id's of course. So far on presave function I've managed to create a copy with: $clone_node = clone $node; create a new alias with: $clone_node->path['alias'] = 'news2/' . $node->nid;, but node_save($clone_node); doesn't save the content, it keeps loading and after awhile it returns to the create form page without saving anything. So basically with this method I cannot create new id automatically as you said, unfortunately. Right?
Comment: node_save creates a nid automatically when the $node nid is omitted or $node->is_new = TRUE; unfortunately what i expected from hook_node_presave it is not what is think it was (i was expecting a $node entity like when you get it from node_load())  so passing that $node from hook node presave to node_save not sure about that. you can still get the data fields, title, uid, name and stuff, build a new node and then saving it with node_save
Comment: Yes, I can still get the data. Well in that case I can set if statement for $node->is_new = TRUE, that's OK, but why node_save($clone_node); doesn't save the node, I'm missing something...?
Comment: Or using node_save() in presave function is not possible?
Comment: Hmmm i do not really know, maybe because node_save expects a $node entity only and not like a $node entity form? in the dpm($origina node) there are some form buld id form tokens and sutff, so maybe it cant be done this way :( sorry
Comment: Thank you anyway. I've learned some very useful stuff today. I'll keep searching for a solution... I'll dig more deeply. :) The Potney Switters's answer it seems to me very abroad.
Answer: Multiple aliases in Drupal
[To put this in something more resembling English, we're talking about creating multiple URLs, more than one web address, to one page or piece of content on a Drupal site.]
It's actually very easy. Go to admin/path/add and add another alias for the node which you want multiply aliased.
(Look up the node/## first by going to the node, and checking the node/##/edit path– you'll have to be logged in to see the edit link.)
So if it's that simple, why would this need an explanatory page on Agaric Design?
Well, if you try to add your alias by editing an existing path, it doesn't work. (For instance if you first tried to redirect from a new path alias to an existing alias, which really doesn't work, and then edited it to point to a system path, any existing alias to that system path gets replaced.)
And seeing the fact that changing foo/bar to foo path alias to foo/bar to node/7 made foo to node/7 disappear-- well, you might logically assume that Drupal isn't letting you have multiple aliases to node 7.
Not true. Adding an alias, instead of editing an existing one to point to the system path, will give you multiple path aliases to the same system path
Answer: When you need to create a duplicate node on submission of one node. That means new node needs to be created after creation of first node. Drupal by default do not provide any hook which works for post node action. Even if you do something with node_presave() or node_insert() or node_update() that would always be buggy because all are working before db transaction ends. I have figured out a quick trick for you to overcome issues. And solving this question was also interesting. Thank you for such a question.

Download a contrib module hook_post_action
Install it and create a new custom module with following code, don't forget to add dependency of hook_post_action in .info file.

I have checked below code with both conditions when pathauto module is enabled and disabled. Any suggestions are welcome.
    /**
     * Implements hook_node_postinsert().
     */
    function MYMODULE_node_postinsert($node) {
      // We need to keep in mind that newly created duplicate node will also invoke this hook so use $_SESSION to avoid infinite looping.
      if (isset($_SESSION['nid_to_duplicate'])) {
        $path = path_load(array(
          'source' => 'node/' . $node->nid,
        ));
        if (!$path) {
          $path = array(
            'source' => 'node/' . $node->nid,
            'language' => $node->language,
          );
        }
        $previous_node_path = path_load(array(
          'source' => 'node/' . $_SESSION['nid_to_duplicate'],
        ));
        if (!$previous_node_path) {
          $alias_prefix = 'node/' . $_SESSION['nid_to_duplicate'];
        } else {
          $alias_prefix = $previous_node_path['alias'];
        }
        $alias_suffix = '-duplicate'; // IN YOUR CASE change it to '2' or whatever you want.
        $path['alias'] = $alias_prefix . $alias_suffix;
        path_save($path);
        unset($_SESSION['nid_to_duplicate']);
      }
      else {
        $_SESSION['nid_to_duplicate'] = $node->nid;
        $new_node = clone $node;
        $new_node->nid = NULL;
        $new_node->vid = NULL;
        if (isset($new_node->path)) {
          unset($new_node->path);
        }
        node_save($new_node);
      }
    }

And when you have pathauto module enabled, to match your scenario here is another set of code:
/**
 * Implements hook_node_postinsert().
 */
function MYMODULE_node_postinsert($node) {
  if (isset($_SESSION['nid_to_duplicate'])) {
    $path = path_load(array(
      'source' => 'node/' . $node->nid,
    ));
    // We are assuming that auto alias would be [node:content-type]/[node:title] and that is automatically created for the new node as well. Now change it.
    $alias_array = explode('/', $path['alias']);
    $path_suffix = '2'; // You can of course change it according to your need.
    // Change news to news2
    $alias_array[0] .= 2;
    // [node:title] token will be changed by pathauto, recreate it.
    $data = array(
      'node' => $node,
    );
    module_load_include('inc', 'pathauto');
    $alias_array[1] = token_replace('[node:title]', $data, array(
      'sanitize' => FALSE,
      'clear' => TRUE,
      'callback' => 'pathauto_clean_token_values',
      'language' => (object) array('language' => $node->language),
      'pathauto' => TRUE,
    ));
    $path['alias'] = implode('/', $alias_array);
    path_save($path);
    unset($_SESSION['nid_to_duplicate']);

  }
  else {
    $_SESSION['nid_to_duplicate'] = $node->nid;
    $new_node = clone $node;
    $new_node->nid = NULL;
    $new_node->vid = NULL;
    if (isset($new_node->path)) {
      unset($new_node->path);
    }
    node_save($new_node);
  }
}


php - somar a quantidade + preço em tabelas separadas

Question: Boas.
Eu tenho a tabela Produtos + a tabela Cart
Quando eu faço Adicionar ao Cart.. a função adiciona 1 record na tabela Cart dizendo o Nome do User, ID do Produto e a Quantidade de produtos pedidos.
Agora eu quero somar a quantidade desse produtos + o preço.
function total_price($con) {

    if(isset($_SESSION['u_email'])) {

        $clientID = $_SESSION['u_id'];

        $total = 0;

        $getPriceTotal = "SELECT quantity, product_id FROM public_cart WHERE user_id='$clientID'";
        $run_total = mysqli_query($con, $getPriceTotal);
        $savedItems = mysqli_fetch_assoc($run_total);

        $quantity = $savedItems['quantity'];
        $productID = $savedItems['product_id'];

        $productQuery = "SELECT product_price FROM public_products WHERE product_id='$productID'";
        $run_product = mysqli_query($con, $productQuery);
        $product_search_price = mysqli_fetch_assoc($run_product);

        while($product_search_price = mysqli_fetch_assoc($run_product)) {

            $product_price = $product_search_price['product_price'];

            $sum = $product_price * $quantity;
            $total += $sum;

        }

         echo number_format($total, 2, '.', '');

    } else {

        echo "0";
    }

}
Mas pelo que vejo... não estou nem conseguindo, pois aparece valores diferentes ou super maiores...
O codigo simplesmente só esta contando de um produto. Mesmo fazendo um while.
Answer: Aparentemente o seu while está posicionado incorretamente, considerando que você possui n registros na tabela public_cart mas cada registro possui apenas um produto.
Desta forma faz mais sentido:
function total_price($con) {

    if(isset($_SESSION['u_email'])) {

        $clientID = $_SESSION['u_id'];

        $total = 0;

        $getPriceTotal = "SELECT quantity, product_id FROM public_cart WHERE user_id='$clientID'";
        $run_total = mysqli_query($con, $getPriceTotal);

        while ($savedItems = mysqli_fetch_assoc($run_total)) {

            $quantity = $savedItems['quantity'];
            $productID = $savedItems['product_id'];

            $productQuery = "SELECT product_price FROM public_products WHERE product_id='$productID'";
            $run_product = mysqli_query($con, $productQuery);
            $product_search_price = mysqli_fetch_assoc($run_product);

            $product_price = $product_search_price['product_price'];

            $sum = $product_price * $quantity;
            $total += $sum;

        }

        echo number_format($total, 2, '.', '');

    } else {

        echo "0";

    }
}


$\sigma$-Algebras $\mathcal{F}(X)$ independent of both $\mathcal{F}(Y)$, $\mathcal{F}(Z) \implies \mathcal{F}(X)$ independent of $\mathcal{F}(Y,Z)$

Question: $\sigma$-Algebras $\mathcal{F}(X)$ independent of both $\mathcal{F}(Y)$, $\mathcal{F}(Z) \implies \mathcal{F}(X)$ independent of $\mathcal{F}(Y,Z)$
Am I right? It seems to follow more or less from definition, but I am suspicious if/why I dont need $\mathcal{F}(Y)$ independent of $\mathcal{F}(Z)$.
Comment: Do you think it would be possible to guess what $\mathcal F(X)$ and "independent" might signify without looking at the tag?
Comment: Ah, I hate being trapped by intuition. My intuition get's screwed up, when thinking about independence of random variables. Intuitively it is just, $X$ has nothing to do with $Y$ nor with $Z$ so it can not have anything to do with $Y,Z$. Any intuitive counterexample on the basis of random variables?
Answer: Consider the probability space
$$\Omega := \{1,\ldots,6\} \times \{1,\ldots,6\}, \qquad \mathbb{P}(\{i,j\}) = \frac{1}{36}$$
and define events $A,B,C$ by
$$\begin{align*}
A &:= \{1,3,5\} \times \{1,\ldots,6\}\\
B &:= \{1,\ldots,6\} \times \{1,3,5\}\\
C &:= \{(i,j) \in \Omega; i+j \mod 2 = 1\}. \end{align*}$$
Then it is not difficult to check that
$$\mathbb{P}(A \cap B) = \mathbb{P}(A) \cdot \mathbb{P}(B) \quad \mathbb{P}(A \cap C) = \mathbb{P}(A) \cdot \mathbb{P}(C).$$
If we set $X := 1_A$, $Y := 1_B$ and $Z:=1_C$, then this shows that $\mathcal{F}(X)$ is independent of $\mathcal{F}(Y)$ and $\mathcal{F}(Z)$. On the other hand, it is not difficult to see that
$$0 = \mathbb{P}(A \cap (B \cap C)) \neq \mathbb{P}(A) \cdot \mathbb{P}(B) \cdot \mathbb{P}(C).$$
As $B \cap C \in \mathcal{F}(Y,Z)$, this means that $\mathcal{F}(X)$ and $\mathcal{F}(Y,Z)$ are not independent. Intuitively, this is due to the fact that if we know that $B$ and $C$ happen (i.e. we throw an odd number with the second dice and the sum of both dice is odd), then $A$ cannot occur (the throw of the dice has to be an even number).
Let me finally remark that even if the $\sigma$-algebras are pairwise independent, they are not necessarily independent. In fact, in the given example one can show that $\mathcal{F}(Y)$ and $\mathcal{F}(Z)$ are indepndent as well.


Spark - remove special characters from rows Dataframe with different column types

Question: Assuming I've a Dataframe with many columns, some are type string others type int and others type map.
e.g.
field/columns types: stringType|intType|mapType<string,int>|...
|--------------------------------------------------------------------------
|  myString1      |myInt1|  myMap1                                              |...
|--------------------------------------------------------------------------
|"this_is_#string"| 123 |{"str11_in#map":1,"str21_in#map":2, "str31_in#map": 31}|...
|"this_is_#string"| 456 |{"str12_in#map":1,"str22_in#map":2, "str32_in#map": 32}|...
|"this_is_#string"| 789 |{"str13_in#map":1,"str23_in#map":2, "str33_in#map": 33}|...
|--------------------------------------------------------------------------

I want to remove some characters like '_' and '#' from all columns of String and Map type
so the result Dataframe/RDD will be:
|------------------------------------------------------------------------
|myString1     |myInt1|     myMap1|...                                 |
|------------------------------------------------------------------------
|"thisisstring"| 123 |{"str11inmap":1,"str21inmap":2, "str31inmap": 31}|...
|"thisisstring"| 456 |{"str12inmap":1,"str22inmap":2, "str32inmap": 32}|...
|"thisisstring"| 789 |{"str13inmap":1,"str23inmap":2, "str33inmap": 33}|...
|-------------------------------------------------------------------------

I am not sure if it's better to convert the Dataframe into an RDD and work with it or perform the work in the Dataframe.
Also, not sure how to handle the regexp with different column types in the best way (I am sing scala).
And I would like to perform this action for all column of these two types (string and map), trying to avoid using the column names like:
def cleanRows(mytabledata: DataFrame): RDD[String] = {

//this will do the work for a specific column (myString1) of type string
val oneColumn_clean = mytabledata.withColumn("myString1", regexp_replace(col("myString1"),"[_#]",""))

       ...
//return type can be RDD or Dataframe...
}

Is there any simple solution to perform this?
Thanks
Answer: One option is to define two udfs to handle string type column and Map type column separately:
import org.apache.spark.sql.functions.udf
val df = Seq(("this_is#string", 3, Map("str1_in#map" -> 3))).toDF("myString", "myInt", "myMap")
df.show
+--------------+-----+--------------------+
|      myString|myInt|               myMap|
+--------------+-----+--------------------+
|this_is#string|    3|Map(str1_in#map -...|
+--------------+-----+--------------------+

1) Udf to handle string type columns:
def remove_string: String => String = _.replaceAll("[_#]", "")
def remove_string_udf = udf(remove_string)

2) Udf to handle Map type columns:
def remove_map: Map[String, Int] => Map[String, Int] = _.map{ case (k, v) => k.replaceAll("[_#]", "") -> v }
def remove_map_udf = udf(remove_map)

3) Apply udfs to corresponding columns to clean it up:
df.withColumn("myString", remove_string_udf($"myString")).
   withColumn("myMap", remove_map_udf($"myMap")).show

+------------+-----+-------------------+
|    myString|myInt|              myMap|
+------------+-----+-------------------+
|thisisstring|    3|Map(str1inmap -> 3)|
+------------+-----+-------------------+

Comment: Hi @Psidom, may thanks for the hint. This seems to work fine, however this way, one needs to map all the columns in the Dataframe. Was looking more for a generic usage. Perhaps it's not that straight forward.. anyway Vote up, tx
Comment: Hi @Psidom, by any change is there a way to create a template function of `def remove_map:..` something like: `def remove_map[T]: Map[String, T] => Map[String, T] =` I have tried several approaches but any of them work. This wuld avoid having multiple functions, one for each combination of `Map`
Comment: I am not sure if that is possible. It might be worthwhile to ask a separate question to see if you can draw any informative answer.
Comment: Thanks, I did, but no response.. http://stackoverflow.com/questions/42856601/scala-define-template-generic-function-to-accept-multiple-parameters


What is the geometrical definition of the $\sec\theta$

Question: This is the geometrical definition of the $\sec\theta$:

My problem with this definition is when the angle $\theta$ is in the forth quadrant. The $\sec \theta$ is positive but the geometrical representation of the $\sec \theta$ is below the $x$ axis.
Comment: X axis isn't relevent for sec =1/cos. It positive iff it is to the left of the y axis; just like cos is.
Answer: Think of the line that is tangent to the unit circle. The $x-$intercept of that tangent line (that is, the point where the line cuts the $x-$axis) is the secant of that angle. It should be more clear why the secant is positive on the $1$st and the $4$th quadrant.
I found this picture on the internet:
Comment: Quite a wonderful picture.
Answer: The secant is positive when the cosine is positive,
that is, when the geometric representations of these functions
are to the right of the $y$-axis.
The position of the geometric representations relative to the $x$-axis
do not determine whether these functions are positive or negative.


Does the entropy of a random variable change under a linear transformation?

Question: Let $X$ be a random variable. If $Y=aX+b$, where $a,b \in \mathbb{R}$, is the entropy of $Y$ the same as the entropy of $X$?
Comment: The answer for continuous variables is at https://stats.stackexchange.com/questions/415435.
Answer: This depends on whether $X$ is discrete or continuous.
If $X$ is discrete
Let $R_X$ be the range of $X$ such that:
$$
R_X = \{x_1,x_2,...,x_N\}
$$
And let $P(X=x_i)$ be the probability mass function of $X$. The entropy of $X$ is:
$$
H(X) = -\sum_{i=1}^N P(X=x_i) \log{P(X=x_i)}
$$
Next, let:
$$
Y = aX+b
$$
Where $a,b \in \mathbb{R}$. This means that the range of $Y$ is:
$$
R_Y = \{y_1,y_2,...,y_N\} = \{ax_1+b,ax_2+b,...,ax_N+b\}
$$
And the probability mass function of $Y$ is:
$$
\begin{align}
P(Y = y_i) &= P(aX+b = y_i) \\
&= P\left(X = \frac{y_i-b}{a}\right) \quad i=1,2,...,N
\end{align}
$$
So the entropy of $Y$ is:
$$
\begin{align}
H(Y) &= -\sum_{i=1}^N P(Y=y_i) \log{P(Y=y_i)} \\
&= -\sum_{i=1}^N P\left(X = \frac{y_i-b}{a}\right) \log{P\left(X = \frac{y_i-b}{a}\right)} \\
&= -\sum_{i=1}^N P(X=x_i) \log{P(X=x_i)} \\
&= H(X)
\end{align}
$$
The entropy of $Y$ is the same as the entropy of $X$ in the case that $X$ is discrete.
If $X$ is continuous
Let $X$ be a continuous random variable with probability density function $p_X(x)$. Also, let $h(X)$ be the differential entropy of $X$ such that:
$$
h(X) = -\int_{x\in\mathcal{X}} p_X(x) \log{p_X(x)} \ dx
$$
Where $\mathcal{X}$ is the support of $X$. Next, let:
$$
Y = aX + b
$$
Such that:
$$
x = \frac{y-b}{a}
$$
And the probability density function of $Y$ is:
$$
\begin{align}
p_Y(y) &= p_X\left(\frac{y-b}{a}\right) \cdot \left|\frac{dx}{dy}\right| \\
&= \frac{1}{|a|} p_X\left(\frac{y-b}{a}\right)
\end{align}
$$
The differential entropy of $Y$ is:
$$
\begin{align}
h(Y) &= -\int_{y\in\mathcal{Y}} p_Y(y) \log{p_Y(y)} \ dy \\
&= -\int_{y\in\mathcal{Y}} \frac{1}{|a|} p_X\left(\frac{y-b}{a}\right) \log{\frac{1}{|a|} p_X\left(\frac{y-b}{a}\right)} \ dy
\end{align}
$$
Substituting $y=ax+b$ yields:
$$
h(Y) = h(X) + \log{|a|}
$$
This equation is only valid for $a \neq 0$. So, in the case that $X$ is continuous, then the differential entropy of $Y$ is not the same as the differential entropy of $X$.
Answer: In general, if $X$ takes at most countable many values, then for any function $f$, the entropy $H(f(X))$ of the random variable $f(X)$ cannot be greater than the entropy $H(X)$ of $X$. In short: $H(X) \geq H(f(X))$ for any $f$.
This is due to the monotonicity of the logarithm, implying
$$(a+b)\log(\frac{1}{a+b})=a\log(\frac{1}{a+b})+b\log(\frac{1}{a+b})\leq a\log(\frac{1}{a})+b\log(\frac{1}{a})$$
for any $a, b >0$. Now consider $A = \{x\in X(\Omega): \exists x'\in X(\Omega)\text{ with } x \neq x'\text{ and } f(x)=f(x')\}$ and notice that
$$H(X) - H(f(X)) = \sum_{x\in A}P(X=x)\log\Big(\frac{1}{P(X=x)}\Big)-\sum_{y\in f(A)}P(f(X)=y)\log\Big(\frac{1}{P(f(X)=y)}\Big).$$


Evaluate the Limit of : $\lim_{n \to \infty}\frac{2^{2n}}{n^{\log_{2}n}}$

Question: I am trying to evaluate the limit of the following:
$$\lim_{n \to \infty}\frac{2^{2n}}{n^{\log_{2}n}}$$
what I did so far is:
$$\dots \lim_{n \to \infty}\frac{n\ln{4}}{\log_{2}n\ln{n}}$$
every step from here like: using L'Hôpital's rule or keep simplify the expression did not success.

any suggestions?
Answer: Log the expression base 2. You will immediately see the leading term and conclude that it diverges.
Comment: Ok, I will get $2n$ now what about to log $n^{\log_{2}n}$? what I will get?
Comment: No, if you log the expression base 2 you get $n \log 2 - (\log n)^2$ which is $O(n)$, hence...
Answer: Hint:
$$2^{2n}=e^{2n\ln{2}}, \;\;
n^{\log_{2}n}=e^{\frac{\ln^2{n}}{\ln{2}}},$$thus
$$\frac{2^{2n}}{n^{\log_{2}n}}=e^{2n\ln{2}-\frac{\ln^2{n}}{\ln{2}}}.$$


Download image from webpage using python

Question: I am trying to write a python script that download an image from a webpage.on the webpage (I am using NASA's picture of the day page), a new picture is posted everyday, with different file names.
so my solutions was to parse the html using HTMLParser, looking for "jpg", and write the path and file name of the image to an attribute (named as "output", see code below) of the HTML parser object.
I am new to python and OOP (this is my first real python script ever), so I am not sure if this is how it is generally done. any advice and pointer is welcome.
here is my code:
# Grab image url
response = urllib2.urlopen('http://apod.nasa.gov/apod/astropix.html')
html = response.read()

class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
    # Only parse the 'anchor' tag.
    if tag == "a":
       # Check the list of defined attributes.
       for name, value in attrs:
           # If href is defined, print it.
           if name == "href":
               if value[len(value)-3:len(value)]=="jpg":
                   #print value
                   self.output=value #return the path+file name of the image

parser = MyHTMLParser()
parser.feed(html)
imgurl='http://apod.nasa.gov/apod/'+parser.output

Comment: If your code is working and you just want comments on possibly ways to improve it you may wish to consult the good people of Code Review: http://codereview.stackexchange.com/
Comment: ...I didn't know codereview exist...Thanks
Comment: Also, once you have the URL, if you're looking to download the images, you can do `os.system('wget ' + imgurl)`. You will need to `import os`, and this will probably only work on Linux systems.
Comment: @xbonez: `subprocess` should be used instead of `os.system()` e.g., `subprocess.check_call(['curl', '-O', imgurl])`
Comment: @xbonez: or without external processes: `urllib.urlretrieve(imgurl, 'output.jpg')`
Answer: To check whether a string ends with "jpg" you could use .endswith() instead of len() and slicing:
if name == "href" and value.endswith("jpg"):
   self.output = value

If the search inside web page is more complex, you could use lxml.html or BeautifulSoup instead of HTMLParser e.g.:
from lxml import html

# download & parse web page
doc = html.parse('http://apod.nasa.gov/apod/astropix.html').getroot()

# find <a href that ends with ".jpg" and
# that has  0 and elem[0].tag == 'img' and
        elem[0].get('src', '').endswith('.jpg')):
        print(link)


Interchanging Limit and Integration, Fourier series

Question: I am wondering if it is allowed to interchange the limit and integral sign in the following expression:
$$\lim\limits_{N\rightarrow\infty}\int\limits_{-\infty}^{\infty} \frac{1}{2\pi}\sum_{k=-N}^{N} b_ke^{ikx} \varphi(x) dx.$$
Here, $\varphi$ denotes a Schwartz function in $\mathbb{R}$ and $\frac{1}{2\pi}\sum\limits_{k=-\infty}^{\infty} b_ke^{ikx}$ denotes the Fourier transform of a periodic continuous function $f:\mathbb{R}\rightarrow\mathbb{R}$ with period $2\pi.$ By definition $b_k:=\int_0^{2\pi}f(y)e^{iky}dy.$
Unfortunately, the usual theorems like dominated or monotone convergence can't be applied here. But my feeling is that the limit above should equal to
$$\int\limits_{-\infty}^{\infty} \frac{1}{2\pi}\sum_{k=-\infty}^{\infty} b_ke^{ikx} \varphi(x) dx$$
How can this be justified? Thank you for your support.
Comment: Thanks for your comment. I think that the Fourier series is not differentiable in the classical sense. The function $f$ is continuous and periodic, thus the series converges only almost everywhere to $f$.
Comment: Maybe try to show that the integrand is smooth enough.
Answer: The integral and the limit can indeed be interchanged.
To see this, first note that if $g \in L^2_{\mathrm{loc}}(\Bbb{R})$ is $2\pi$-periodic, then
\begin{align*}
  \int_{\Bbb{R}}
    g(x) \, \varphi(x)
  \, d x
  & = \sum_{k \in \Bbb{Z}}
        \int_{2\pi k}^{2\pi k+2\pi}
          g(x) \, \varphi(x)
        \, d x \\
  & = \sum_{k \in \Bbb{Z}}
        \int_{0}^{2\pi}
          g(x) \, \varphi(x + 2\pi k)
        \, d x \\
  & = \int_0^{2\pi}
        g(x) \, P \varphi (x)
      \, d x,
\end{align*}
where $P \varphi(x) = \sum_{k \in \Bbb{Z}} \varphi(x + 2\pi k)$ is bounded
(since $\varphi$ is a Schwartz function) and $2\pi$-periodic.
The interchange of the series and the integral above can be easily justified using the dominated
convergence theorem.
Now, define $f_N := \frac{1}{2\pi} \sum_{k=-N}^N b_k e^{i k x}$, and note that
$f_N \to f$ in $L^2([0,2\pi])$.
Since $P \varphi \in L^\infty([0,2\pi]) \subset L^2 ([0,2\pi])$, we see
\begin{align*}
  \int_{\Bbb{R}}
    f_N (x) \, \varphi(x)
  \, d x
  & = \int_0^{2\pi}
        f_N (x) \, P \varphi (x)
      \, d x \\
  & \xrightarrow[N\to\infty]{} \int_0^{2\pi} f(x) \, P \varphi (x) \, d x \\
  & = \int_{\Bbb{R}}
        f(x) \, \varphi(x)
      \, d x ,
\end{align*}
which is what you wanted to show.
Comment: Phenomenal! Thank you so much.


Limit: Quotient of two functions

Question: Suppose that we know that the following limit is defined:
$$\lim_{n\to \infty} \frac{f(n)}{g(n)}=l$$
Where $g,f : \mathbb{N} \to\mathbb{R}$.
And, also, we are aware of the following:
$\exists \:  c \in \mathbb{R},\: n_0 \in \mathbb{N}:
f(n)\le c\cdot g(n) \ \forall \ n \ge n_0  $
$\exists \:  c' \in \mathbb{R},\: n_0' \in \mathbb{N}:
f(n) \ge c'\cdot g(n) \ \forall \ n \ge n_0'  $
I have to prove that: $ 0 < l < \infty$
Mi first approach was to try and use the inequalities above to reach an expression like $|\frac{f(n)}{g(n)}-l|<\epsilon$ and thus proving the exercise with the definition of a limit. But that got me nowhere, and then I realized the following:
$c'\cdot g(n) \le f(n)\le c\cdot g(n) \iff c' \le \frac{f(n)}{g(n)}\le c$
Now, when $n \to \infty$, then: $c' \le l \le c \implies 0 < l < \infty $.
That's where my question enters:
Is this proof correct, would I need to add something else? Is there another way to do it?
Maybe using the definition of a limit?
Thanks! :)
Edit: $c,c' \in \mathbb{R_{>0}}$
Edit (2) : $g,f:\mathbb{N} \to \mathbb{R_{>0}}$
Comment: Note that $g(n)$ can be negative...So the inequality is reversed in this case. Since $f,g: \Bbb{N} \to \Bbb {R}$
Comment: Sorry! They're supposed to be from N to positive R, my bad. I added a edit, thanks for pointing it out :) !
Comment: Ok no problem .......
Answer: If $c'>0$, not only $c' \in \mathbb{R}$, then proof is correct: you know limit exists for $a_n=\frac{f(n)}{g(n)}$ and $c' \leqslant a_n \leqslant c$, so $c' \leqslant \lim a_n \leqslant c$.
Comment: Thanks! Indeed, c and c' are real positive numbers, I forgot to add that in the original post, there's and edit now.

Limit: Quotient of two functions


Can $7n + 13$ ever equal a square?

Question: If not, why not? Can it be proved? And if it can be proved that it does equal a square (which I doubt), what is the smallest value for which this occurs?
Comment: Above and beyond the answers you've gotten, the question of 'is $a$ a square mod $b$?' (and note that this is equivalent to the question you've posed; can you see why?) is a surprisingly deep one touching several areas of number theory; the magic phrase to look for is _quadratic residue_. (https://en.wikipedia.org/wiki/Quadratic_residue)
Answer: A square can only be $0,1,4,2 \mod(7)$. But $7n+13 \equiv 6 \mod(7)$ which is never possible. So $7n+13$ can never be a square.
Comment: Literally just figured that out myself about 10 seconds ago. Never thought to look at the answers modulo 7. But this notwithstanding, is there a deeper reason even beyond this, or an alternative explanation.
Comment: @Dolphin well, it depends on what you mean by "deeper reason". When you are given things like $7n+13$, it's usually meant to be solved the modulo way, which is satisfactory for me. I'll edit my post if anything else comes to mind
Answer: \begin{align}
1^2 &\equiv 1\pmod 7 \\
2^2 &\equiv 4\pmod 7 \\
3^2 &\equiv 2\pmod 7 \\
4^2 &\equiv 2\pmod 7 \\
5^2 &\equiv 4\pmod 7 \\
6^2 &\equiv 1\pmod 7 \\
7^2 &\equiv 0\pmod 7 \\
8^2 &\equiv 1\pmod 7 \\
9^2 &\equiv 4\pmod 7 \\
10^2 &\equiv 2\pmod 7 \\
11^2 &\equiv 2\pmod7\\
12^2 &\equiv 4\pmod7 \\
& \space\space\space\space\space\space\space\vdots
\end{align}
It repeats, so a perfect square can only be 0,1,2,4 mod 7
$7n+13 \equiv 6 \mod 7$  which is clearly not a perfect square.
Answer: The answer by Prathyush Poduval is entirely correct, but the following perhaps goes a little deeper.
There can be at most $3$ non-zero quadratic residues $\pmod 7$. To see this, note that if $k$ is any non-negative integer and $n$ is any of the $6$ integers such that $0<n<7$, and $n^2 \equiv m \pmod 7$ then:
$$(7k+n)^2 \equiv 7(7k^2+2kn)+n^2 \equiv n^2 \equiv m \pmod 7$$
$$(7-n)^2 \equiv 7(7-2n)+n^2 \equiv n^2 \equiv m \pmod 7$$
Hence the number of non-zero quadratic residues is at most $6/2 = 3$.  To find all the non-zero quadratic residues it is therefore only necessary to consider:
$$1^2 \equiv 1 \pmod 7$$
$$2^2 \equiv 4 \pmod 7$$
$$3^2 \equiv 2 \pmod 7$$

Can $7n + 13$ ever equal a square?


Epimorphisms are surjective in the category of actions over a monoid

Question: Let $M$ be a monoid and consider the category of $M$-acts. The morphisms of this category are mappings that preserve the action of $M$. Let $f : X \rightarrow Y$ be an epimorphism in this category, i.e. a right-cancellable morphism. I am trying to prove that actually $f$ is a surjective mapping, but i am having difficulty. Thanks for your help.
Comment: Why not try proving a stronger statement? For any category $\mathcal{C}$, a morphism (i.e. natural transformation) in the functor category $[\mathcal{C}, \textbf{Set}]$ is an epimorphism if and only if it is a componentwise surjection. Hint: Yoneda lemma.
Comment: The category of all functors $\mathcal{C} \to \textbf{Set}$. A $M$-set is a special case of a functor, when you take $\mathcal{C}$ to be a one-object category.
Comment: @ZhenLin: What do you mean by "functor category"?
Answer: Let's assume that $f:X\to Y$ is not surjective, and let's show that $f$ is not an epimorphism.
It is straightforward to check that the equivalence relation $\sim$ defined on $Y$ by
$$
y\sim y'\iff y,y'\in f(X)
$$
is a congruence.
Let $z\in Y/\!\!\sim$ be the equivalence class $f(X)$, and let $c:Y\to Y/\!\!\sim$ be the constant map equal to the equivalence class $f(X)$.
Then we have $p\circ f=c\circ f$ but $p\neq c$.
Comment: This is great. Thanks Pierre!
Comment: Dear @Manos: You're welcome!