If $f: \mathbb{R} \rightarrow \mathbb{R}$ is a differentiable function, $f(0)=0$ and $f' = f^2$, then $f = 0$.

Question: If $f: \mathbb{R} \rightarrow \mathbb{R}$ is a differentiable function, $f(0)=0$ and $f' = f^2$, then $f = 0$. Any help?
Comment: Don't worry, if this is your first time going through an analysis sequence it will be rough absorbing all the theorems and methods of solving problems. Keep going!
Comment: Thanks! Yeah, it's my first time. I can understand the book, but coming up with my own proofs for the exercises is really challenging and it's screwing with my self esteem!
Answer: Note that your function is increasing due to $f' = f^2 \geq 0$. So if you have such a function which is not identically zero, the set of $x$ for which $f(x) = 0$ is some closed interval $I$ (possibly unbounded) which is not all of ${\mathbb R}$. Let $x_0$ be an endpoint of $I$. Replacing $f(x)$ by $-f(-x)$ if necessary, we can assume $x_0$ is the right endpoint of $I$.
On $(x_0,\infty)$ the equation $f' = f^2$ is separable, and standard calculus techniques give that $f(x) = -{1 \over x + c}$ for $x > x_0$ for some constant $c$. But then taking limits as $x \rightarrow x_0$ gives $f(x) = -{1 \over x_0 + c}$, contradicting that $f(x_0) = 0$ since $x_0 \in I$.
This contradiction shows that $f = 0$ is the only solution.
By the way, solving $f' = f^2$ here only uses basic real analysis techniques... it's the same as ${d \over dx} ({1 \over f(x)} + x) = 0$, which by the mean value theorem for example says that ${1 \over f(x)} + x = c$ for some constant $c$. This implies that $f(x) = -{1 \over x + c}$.
Comment: Nice! I really like this one, it's very pretty. Thanks everyone else for the answers anyways!
Answer: Here's a proof just from basic theorems of real analysis and a little topology.
Since $f'=f^2\ge0$, $f$ is nonnegative for $x\ge0$. We have $f(x)=0$ for all $x\in[0,x^*]$; by shifting the function $x\mapsto x-x^*$ we can assume $x^*=0$, and then if $f\ne0$ we have arbitrarily small $x>0$ with $f(x)>0$. Now assume for a contradiction that $f(x)>0$ for some $x\in(0,1)$, and let $M=\min(1,f(x)/x)$. Since the set $[M,\infty)$ is closed and $f(x)/x$ is continuous with limit $0$ at $0$ (since $f'(0)=0$), there is a least $y\in(0,1)$ such that $f(y)/y\ge M$.
By the Mean Value Theorem, $f^2(z)=f'(z)=f(y)/y$ for some $0<z<y$. But if $f(y)/y\ge 1$ then $f(z)=\sqrt{f(y)/y}\ge1$, and if $1\ge f(y)/y\ge f(x)/x$ then $f(z)\ge f(y)/y$. In either case $z<y$ also has $f(z)/z\ge f(z)\ge M$, a contradiction. Thus $f=0$ on $[0,\infty)$, and by applying this to $g(x)=-f(-x)$, we have $f=0$ on $\Bbb R$.
Comment: I think you left out that $y$ is to be the infimum of the set $f^{-1}([M, \infty)) \cup [0, \infty)$.
Comment: @nayrb (It's possible that your comment is from an old version since I made many edits, but) I wrote that "there is a least $y>0$ such that $f(y)\ge M$", which is intended to be interpreted as "Let $y$ be the infimum of $f^{-1}([M,\infty))\cap(0,\infty)$, which is in the set since it is closed".
Comment: Oh! I read it quickly as "there is at least $y > 0$... Got it!
Comment: By the Mean Value Theorem, shouldn't it be $(y - 0)f'(z) = f(y)$?
Comment: @raffa Wow, don't know how I messed that up. Well the argument still works with a little modification.
Comment: Yeah, so odd that two people made the same simple mistake. Thanks for the answer, didn't expect this many people to help me!
Answer: $f' = f^2$ is a differential equation.  What do you know about differential equations?  If you know the Existence and Uniqueness Theorem, this question is easy.
Comment: Nothing! The question is from an introductory real analysis book. It's actually on the section about Riemann integrals.
Answer: Here's an idea that doesn't "use" differential equations:
Assume $f \geq 0$ for $x \geq 0$ and consider the interval $(0, \epsilon)$, $\epsilon<1$ where $0 \leq f < 1/2$, which exists by continuity of $f$.
First, pick an $x_0 \in (0, \epsilon)$. By the mean value theorem,
$$f(x_0) = f(x_0)-f(0) = x_0 f'(x_1) \leq f(x_1)^2$$
for some $0 < x_1 < x_0$. Define $x_2$ and in general $x_n$ in a similar manner so that $f(x_n) \leq f(x_{n+1})^2$. Then
$$f(x_0) \leq f(x_n)^{2^n} \leq (1/2)^{2^n}.$$
Taking the limit we get $f(x_0) = 0$.
Now fill in the gaps and deal with the other cases (or combine them) and figure out a way to show $f = 0$ beyond $(0, \epsilon)$. If you use this idea in your homework just write down you got the idea here, no biggie.
Comment: I find it interesting how our answers both use essentially the same method but in different ways.
Comment: I think raffa's point that MVT gives $f(x_0)=x_0f'(x_1)$, not $f(x_0)=f'(x_1)$, also applies to this answer.
Comment: @MarioCarneiro Good point, what a silly error! It's corrected now.
Comment: Probably should put in the assumption that $\epsilon<1$, or else your inequality doesn't hold.
Comment: Fixed it, thanks!
Answer: If $f$ is differentiable it is continuous.
In particular, $Z=f^{-1}(\{0\})$ is closed and $0 \in Z$.
Choose some $t_0 \in Z$.
Define $M(\delta)= \sup_{x \in [t_0-\delta,t_0+\delta]} |f(x)|$.
It is straightforward to check that $M$ is continuous and non decreasing.
Then the function $\delta \mapsto |\delta| M(\delta)$ is continuous and zero at zero.
Now choose some $\delta>0$ such that $\delta M(\delta) <1$.
Then for $t \in [t_0-\delta,t_0+\delta]$, $|f(t)| \le | \int_{t_0}^t f^2(s) ds | \le |\delta| M(\delta)^2 $. Taking the $\sup$ of the left hand side over $[0, \delta]$ gives
$M(\delta) \le \delta M(\delta)^2 $, which implies $M(\delta) = 0$, and in particular, $f(t) = 0 $ for all $t \in [t_0-\delta,t_0+\delta]$.
This shows that $Z$ is open.
Since $Z$ is a non-empty open and closed subset of $\mathbb{R}$, we must have
$Z= \mathbb{R}$.
Alternative approach:
The key here is that $f$ is defined for all of $\mathbb{R}$.
Suppose $f(t_0) >0$ for some $t_0$. A quick computation shows that
if $\phi(t) = {1 \over f(t)}$, then $\phi'(t) = -1$ and so
$\phi(t) = \phi(t_0) + t_0 - t$. However, this would give that
$\lim_{t \uparrow (t_0+\phi(t_0) )} f(t) = \infty$, which contradicts
the fact that $f$ is defined for all of $\mathbb{R}$.
A similar approach works for $f(t_0) <0$. Hence $f$ is identically zero.


Is the terminal velocity in air independent of the direction of the movement?

Question: For example, a body in free fall on earth and the same body experiencing the same acceleration ($ g $ in this case) but horizontally,  would have the same terminal velocity? (considering that the contact area is the same in both cases)
Answer: Not necessarily.  The atmospheric density has to be considered. If the object is falling downward, the atmospheric dehsity increases and that will increase the drag,  If the object is going horizontally the atmospheric density is basically constant so drag will be constant.
If this is for a baseball, for example, the atmospheric pressure may be a constant throughout its flight due to the short distances involved.
It this is for a much faster object the atmospheric pressure is not constant. Also, the drag dependance on velocity is not a constant so that must be taken into account as well.
Answer: It depends on what you mean by "direction of movement".
If you mean the direction that an object is moving at any given moment, no, because terminal velocity is a hypothetical value that doesn't care for current circumstance.
If you mean the direction of movement for the object when it's at terminal velocity, then, yes.  For example, a rocket with an engine going can have a terminal velocity in the upward direction or the downward direction, but its terminal velocity downward would tend to be faster than upward due to gravity.
Comment: Sorry to comment on the post here, but can you please be more careful in reviewing suggested edits? For instance, [this edit you approved](https://physics.stackexchange.com/review/suggested-edits/220965) does not fully address the issues & actually incorrectly edits a word.
Comment: @KyleKanos It's all good, though that edit does look like an improvement to me, albeit not a complete or perfect one.  By the way, why'd you convert $\frac{x}{y} \to x/y$ for two of the fractions?
Comment: well the suggested edit changes the meaning of the sentence, which should be rejected in that grounds alone. I used x/y because \frac should never be used for inline equations.
Comment: @KyleKanos That's probably a difference in perception; I didn't see the changed word as changing the sentence because the sentence already looked like gibberish, such that I saw that particular modification as lateral.  This is, I wasn't sure what "_aftec_" was supposed to be, but since "_after_" looked like a reasonable enough guess (plus, it was an actual word), I overlooked it for what I saw to be the main improvement of the suggested edit, which would be the typos just before that.
Comment: I think then if it doesn't make sense one way or the other, it's better to reject it & leave a comment to the poster asking for clarification.
Comment: @KyleKanos Definitely; I'd likely have rejected the edit if that were the only part of it.  Still, the typos just before that were a little much, so their correction seemed constructive.  My perception was that the edit suggestion was primarily done to remove the term "_small ass_", and that the attempt at making "_aftec_" into an actual word was incidental.
Answer: Yes. Air resistance is independent of direction of motion. It is always opposite to the direction of motion, it increases with speed and air density, and depends on the cross-sectional area and longitudinal shape of the object.
Terminal velocity occurs when air resistance balances resultant driving force (eg thrust or weight) in both direction and magnitude. If the resultant driving force acting on the body is the same, and all other conditions are the same,  then the terminal velocity will be the same also.
Answer: Normally not. Below are measurements on an average human in the wind tunnel at different orientations. The values given are the drag force divided by the dynamic pressure; that's why they have the dimension of an area.

This figure is copied from chapter 5 of Sighardt Hoerner's book "Fluid Dynamic Drag", 1965 edition.
Now consider that terminal velocity changes with the square root of the dynamic pressure and air density, so the speed differences between the different postures are as large as 1 : 2.74.
If the frontal area is the same, just consider a semisphere: With the closed side facing forward, its drag coefficient is 0.38 while the same sphere, now facing forward with the open side, will have a drag coefficient of 1.42. Consequently, the terminal speed difference between both orientations will be 1 : 1.93.
This does not consider dynamic stability, because such a semisphere will tumble while in free fall.
Answer: $$\vec{F}_\text{resistance}=-b\vec{v}$$ (assuming linear relationship between resistance and velocity)
$$\vec{v}=\vec{v_x}+\vec{v_y}$$
$$v=\sqrt{v_x^2+v_y^2}$$
$$\frac{dv_x}{dt}=-\frac{b}{m}v_x$$
$$\frac{dv_y}{dt}=-g-\frac{b}{m}v_y$$
These differential equations do not have analytical solutions. They have to be integrated numerically. In the first case you have to set $v_x(t=0)=0$. In the second one you have to set $v_x(t=0)=u$.
Comment: The equations you wrote down seem to be linear and uncoupled. So I think that they can be integrated analytically.


Merge drive c: and d: whilst drive D: has program files

Question: I have two partitions on my laptop and would like to merge drive D: to C: but, drive D: has program files in it and drive C: has the OS. I am running out of space on drive C: and would eventually like to merge the two drives. Please help. I'm running an XP professional.
Answer: Merging the drives will always be a problem with anything but data on one of them. That said, if you have partitioning software that would merge partitions, you probably have software that will allow you to resize them, and I recommend that you only rsize them.
If you do not have such software, go here and try the free version:
http://www.partition-tool.com/download.htm
Comment: +1 QFT - merging the two drives is just asking for headache. Just steal space from one to give to the other.
Comment: +1 Many applications put path data in the registry in arbitrary locations. After the merge, you may find that most of your programs stop working or begin behaving strangely.


Can "In a sense" be used as "On the one hand"?

Question: Is it okay if I start a sentence with the phrase "In a (or one) sense" instead of "On one hand" while comparing two things? If so, what about usage of "On the other hand" in starting the counterpoint?
Answer: In a sense means "partly true, or true in one way". You could say "in one sense, my brother is a wicked man; in another sense he is not".
Comment: Does it mean I can use it interchangeably with "On the one hand"? Because I think "On the one hand" also means "true in one way" as you mentioned.
Answer: You use "in a sense" with meanings. As in:

I say (this). In a sense, it is true. In the other is not.

In this particular case, IF there are ONLY two possible senses, you can use "on one hand".
But there can be more senses to a statement. In that case, "on one hand" is not suitable, unless you are willing to get to the part with: "On the fifth hand...".

Additionally, "On one hand" can be used with anything, not only meanings of statements.

On one hand, I want to enjoy the hot sun. On the other hand, I do not want the ice cream to melt, considering I do not have a freezer.

As you can see, "on one hand" is a lot more generic, but applicable when there are only two options to be compared.


Difference of georeferenced and ungeoreferenced map in AutoCAD?

Question: Can somebody please explain the difference of an ungeoreferenced scanned map and a georeferenced one in AutoCAD?
Answer: There are couple of differences that are coming to my mind. Shortest and simplest answer would be:

Coordinates:

ungeoreferenced scanned map do not have coordinates in a coordinate reference system that the software can understand. They will be pixel values relative to a local 0,0. That
means the program cannot locate the map in real world. You can think about it like a photo you have on the wall. It looks familiar but you have no idea where it was taken.
georeferenced scanned map has coordinates relative to a known coordinate reference system. When you load the map, the program can identify where it is in the real world.

Scaling:

ungeoreferenced scanned map is not using meters or a other unit of measure (besides pixel size), which means you cannot measure anything on it and your map is misshapen. Without correct scale and coordinates, measuring distance or area is not possible.
georeferenced scanned map has coordinates assigned including a unit of measure. When you load the map, the program can measure things like distance, area, etc. What is more, objects on the map are located where they are in the real world.

So in general you cannot do GIS analysis on ungeoreferenced map as digitization, distance measurements or spatial functions will not work on them.
Probably there are more differences but these are the most obvious ones.


How can we trust supply won't be increased in 2140 by just a few lines of code?

Question: How can we trust supply won't be increased by just a few lines of code?
Comment: I'd say a bigger worry in 2140 would be the size of the block chain ledger and whether or not there is enough bandwidth to efficiently pass it around the internet. It's already up to 350 GB...
Comment: Relying on Moore's Law to solve the issue with large chain size is unrealistic, especially given that Moore's Law has slowed significantly in recent years.  I like the argument of having lighter nodes for the average user, and have seen plenty of blockchains take this approach.
Comment: There are several arguments that would help quelm this. For starters, not every user on the network has to have a copy of the entire blockchain. They may only require the last $n$ blocks to sync with the network. Not every user must be a full node. The full nodes would store the entire blockchain. Additionally, Moores law states that size should not be an issue in 2140.
Comment: @HamishGibson Moore's law has both been shown to be incorrect in recent years and has nothing to do with internet transfer speeds or the cost of storage space
Answer: The bitcoin network is composed of 'bitcoin full nodes', which are computers located all around the world, each one running independently to verify the state of the network.
Part of that verification includes making sure that the right number of coins are being created with each passing block, such that the total number of coins in existence is known, and predictable.
To change this 'coin issuance schedule', you would have to change the code running on all of those computers, so that they would all independently agree on some new issuance schedule, and could all continue to verify which blocks are valid (or not), in independent consensus. If you could only change the code on some of those computers, then those computers would start to follow blocks which the remaining bitcoin network nodes would consider invalid, effectively creating an altcoin-fork of the network (similar to what happened with 'bitcoin cash').
Anybody, at any point in time, could create some software that changes the issuance schedule. Thats easy. The hard part is convincing everyone that is running a bitcoin full node to switch to this new code, which creates more coins. Nobody has the authority to push such a change onto the network (top-down governance), rather it is the independent choices of all of the network's nodes (bottom-up governance) that defines the network.
So the answer is that you don't have to trust someone to not increase the supply. You just have to run some code that will verify that they haven't.
Comment: @Jiminion doing so would simply cause those computers to fork off (creating an altcoin network), & any computers running the original code would just ignore them, and continue on as normal. There is some nuance (ie, how much hashpower each network would have pointed at it), but importantly: even if a majority of nodes try to change the rules, that would not force the remaining nodes to follow suit. You may be confusing this with a majority attack, in which the attacker controls >50% of the *hashpower* (but such an attacker would not be able to arbitrarily change the network rules either).
Comment: There has never (that I'm aware of) been a credible proposal to switch bitcoin to proof of stake. And no, generally speaking new releases of Bitcoin Core do _not_ contain backward-incompatible changes. (That's one of the key differences between Bitcoin and, say, Ethereum.)
Comment: The thing is that if majority ofplayers are convinced to follow the fork, then the remaining ones in the old network will be screwed. That's another thing though.
Comment: _"you would have to change the code running on all of those computers"_ doesn't this happen each time the core codebase is updated for non-backward-compatible changes such as some performance, most bug fixes, the proposed switch to proof-of-stake or other reasons anyway?
Comment: I think you're missing the point of the answer, the code technically can't change for real.  The Bitcoin blockchain is made up of the network of nodes, users, businesses, etc... that operate on it.  Bitcoin could be forked, but which of the two chains is considered "Bitcoin" all comes down to what the miners and the community choose to support. The answer here is stating that the code can't change on the current network, and whatever happens with forks is probably for the best.  For examples you can look at Bitcoin and Bitcoin Cash or Ethereum and Ethereum Classic.
Comment: There are some technicalities -- old clients can sync the network past major changes like segwit/taproot, but they will not understand or validate scripts from the "new world" -- they will treat them as automatically true. However, they will also never generate addresses of their own which use such scripts, so this does not threaten their own security. Depending on their age, and the address format used, they may or may not be able to send to newer scripts they don't understand.
Comment: Small point, but wouldn't you have to change the code on just a majority of the computers?
Comment: @GlennWillen Did not know this. So early bitcoin client of 2011 or before will still be valid node for all other peers and allowed to host a valid wallet? I think taproot is probably going to be change this.
Comment: I don't think this addresses OPs question. It's not about a "hacker" changing the code. It's about the actual code changing, for real. And I don't think there's a way around it other than hoping the demand will remain high enough to accomodate 2x the amount of coins. Pretty much like a stock split.
Comment: @thevikas yes, old clients can still sync to the network (with the nuanced exception of the consensus split when bitcoin-core upgraded to levelDB in v0.8.0, iirc software older than that needs a small tweak to the database memory lock limits in order to properly sync to the network). Taproot does not change this, the taproot code is still backwards compatible. Centralized altcoins can (and do) hardfork ad infinitum, but imo it would be almost impossible to convince users to hardfork the bitcoin network without encountering some absolutely critical bug that warranted such a thing.
Answer:
Well, the title is the only question, how can we trust supply wont be increased by just a few lines of code?

Just don't make any such changes to your code and you will never see an increased supply. You control the code running on your computer. If you never want to see an increased supply, never change your code in that way.
You can, of course, only interoperate with people who also don't want to see an increased supply. So the real issue has nothing to do with changes in code, it has to do with wanting a guarantee that there will still be people who don't want changes in the supply for you to interoperate with.
But you cannot ever force anyone to interoperate with you if they don't want to.
Comment: Watching Bitcoin desync because half the world wants to increase supply and half doesn't would be fun.
Comment: Great answer that explains in laymans terms the underlying technical details.  I especially liked the way the second paragraph is worded and the fact that it doesn't use "fork" or other technical terms.
Answer:
The bitcoin network is composed of 'bitcoin full nodes'... to change this 'coin issuance schedule', you would have to change the code running on all of those computers

Regardless of how many times this statement is repeated (and upvoted on SE!), it is obviously wrong to anyone willing to spend even a few minutes thinking about it.
Except for a few special ones (like ones that happened to be running at Coinbase and other influential places like that), full nodes have no influence on the block chain whatsoever.  Nodes do not create blocks, miners do. It is the code that is running on the miners' machines that matters. And, at some point, incentives will align for the miners to do something to replace revenue from the waning block rewards, and the politics will incentivize the few influential nodes to follow this new chain since it will have the hashpower behind it (continuing to follow an underpowered chain could have disastrous results).
If you still believe that full nodes matter at all, consider this: there are generally 10's of thousands of full nodes on the network at any given moment. I could, sitting here at my desk, easily spin up 100,000 full nodes and get them integrated into the network within the next 24 hours without even maxing out my credit cards. I would then control the vast majority of full nodes. So why don't I do this? (Or more importantly, why doesn't anyone else with more resources than me do it?) Because there is no benefit to controlling any number of non-influential nodes. None. There are only a few dozen nodes on earth that matter, and they are the only ones that matter, and they are controlled by a small number of people who may someday have incentives to allow the increase the supply of bitcoins.
See longer answer here...
https://bitcoin.stackexchange.com/a/108202/113175
Note that it is very likely that this answer will be heavily downvoted and will attract comments vehemently scolding me for being an idiot- while never offering any actual rebuttal to my argument. This too is a signal!


Is there a formal name for equations and inequalities containing parameters (known variables, coefficients)?

Question: Is there a formal name for equations and inequalities containing parameters (known variables, coefficients)? Is it just "equations with parameters"? "general equations"?
Here are some examples:

$$\sqrt{4x - 3} \cdot ln(5x - a) = \sqrt{4x - 3} \cdot ln(6x + a) $$
$$ (5^{2x + 1} - 25^x - 20)(\sqrt{ax - 6} - \sqrt{a - 2x}) = 0 $$
$$ \dfrac{log_ax}{x^2 + (a - 4)x + 4 - 2a} \le 0$$

I want to learn how to solve them, but my problem I cannot find resources in English on how to do it. I'm not a native English speaker, so I suspect this is because I'm translating it wrong. The literal translation from Russian would be "equations with a parameter", and usually such problems are stated in the following way: "find all the solutions of the equation depending on the value of $a$" or "find all the values of $a$ for which the equation has two distinct roots".
For example, when I search for YouTube videos on how to solve such equations in Russian with the search query "уравнения с параметром" ("equations with a parameter"), I get tons of relevant videos of different sorts, but when I do it in English with the same search query "equations with a parameter", I get almost nothing relevant. It makes me think that I'm doing something wrong.
Here's what I've found so far on Wikipedia:
Equation

Usually, the unknowns are denoted by letters at the end of the alphabet, x, y, z, w, ...,2 while coefficients (parameters) are denoted by letters at the beginning, a, b, c, d, ... . For example, the general quadratic equation is usually written $ax^2 + bx + c = 0$. The process of finding the solutions, or, in case of parameters, expressing the unknowns in terms of the parameters, is called solving the equation.

Parameter

Mathematical functions have one or more arguments that are designated in the definition by variables. A function definition can also contain parameters, but unlike variables, parameters are not listed among the arguments that the function takes. When parameters are present, the definition actually defines a whole family of functions, one for every valid set of values of the parameters. For instance, one could define a general quadratic function by declaring $f(x) = ax^2 + bx + c$.

But it doesn't really answer my question.
Answer: $x$ would be called a variable. $\sqrt{4x - 3} \cdot ln(5x - a) = \sqrt{4x - 3} \cdot ln(6x + a)$ would be called an equation. There is no other common word in usage that would be universally understood. Thats the best I can do unless you can narrow down your question more.
If you're looking to find these kinds of problems in english, they would just be referred to as olympiad problems, but this is much broader than what you want.
Answer: I believe they would typically be called equations with restrictions, such as restricted domain or restrictions on solutions


Node.js and Jetty 6

Question: I wanna use node.js and app.js in my application
My application under java programming language and my application container is Jetty 6 server
So can I use node.js and app.js inside my application ?
Answer: You wont be able to run node.js inside your servlet container.
However you can write services in node.js and host it along side jetty and have your application consume those services.
i.e your java application connects to a rest service that running on top of node, to perform its database access.
or vice versa.

Node.js and Jetty 6


iOS Application - intercept when a user deletes the app from device

Question: I'm developing an apple iOS application using Xcode.
How to know if a user removed an application from his iPhone/iPad Device?
thank you
Comment: No, that is not possible.
Answer: If you have several your apps on device - you can use SHARED KEYCHAIN to detect marker you've written in deleted app. Shared keychain can be accsessed by apps sharing same keychain access group. Or you can get approximate statistics using some statistics framework by checking whether some application stopped logging any events for a long period of time.
Answer: No you cannot. The only thing you can catch is first run of your app. There is no obvious reason for knowing when your app is uninstalled (except of spamming users). You can just keep stats to see your app usage if that's the case.
Answer: No, an app cannot detect when it is being deleted from the device.
An app runs in a sandbox / secure container. (Almost) everything outside that sandbox is just a 'mystery' for the app. Your app shouldn't need to know, so IF this is an issue at all, it is basically just a design issue for you to deal with.


Machine-learning input data distribution

Question: I'm trying to build a binary 1/0 ML classification algorithm, and was thinking about how to set up the input dataset. If the event I want to predict (the 1's) occur relatively less frequently in the total data than the 0's, does it makes sense to pare the dataset in such a way to get a more equal distribution of 1's and 0's? Would that be falsely representing the data to the algorithm? What are the disadvantages to doing so?
Comment: You _can_ do that, but it would be better if you didn't have to throw away data. I imagine the reason this question came up is that you're optimizing your solution for _accuracy_, but the classes are skewed enough that a high-accuracy algorithm has really poor [_recall_](http://en.wikipedia.org/wiki/Precision_and_recall). I would recommend optimizing for something other than accuracy (like minimizing a weighted sum of false negatives and false positives, more heavily weighting the false negatives).
Answer: Define an accuracy metric that reasonably models how you want your algorithm to perform.
Once you have a metric in hand you can cross-validate this question and see if it is an improves the performance.
Some common accuracy metrics that model the problem different: Normalized mutual information, Gini on the labels argsorted by the probabilities, Precision, Recall, AUC.
If the classes are extremely unbalanced and FN are crucial, you'll see an improvement.


What is a word for when someone likes bodily harm done to oneself.

Question: What word would work for someone who likes to be hurt by other people? Physically, like it may even be a turn on.
Answer: You call that someone a masochist.

a person who has masochism, the condition in which sexual or other gratification depends on one's suffering physical pain
  or humiliation.
a person who is gratified by pain, degradation, etc., that is self-imposed or imposed by others.

http://dictionary.reference.com/browse/masochist
Answer: I think you are referring to masochism:

gratification gained from pain, deprivation, degradation, etc., inflicted or imposed on oneself, either as a result of one's own actions or the actions of others, especially the tendency to seek this form of gratification.

Word Origin:

"sexual pleasure in being hurt or abused," 1892, from German Masochismus, coined 1883 by German neurologist Richard von Krafft-Ebing (1840-1902), from name of Leopold von Sacher- Masoch (1836-1895), Austrian utopian socialist novelist who enshrined his submissive sexuality in "Venus in Furs" (1869, German title "Venus im Pelz").

(dictionary.reference.com)


UI Binding updates to a ObservableCollection that gets re-assigned

Question: Description:
First I created an ObservableCollection which is accessed via the public property MyCollection.  Now if I bind my DataGrid UI to MyCollection it will recognize collection changes, but not if MyCollection itself changes (ie. UpdateCollection method).  To solve this issue I applied the familiar 'PropertyChanged("MyCollection")' to the MyCollection Property.
Now I found the need to group my DataGrid Content which requires a Collection View layer.  When I added and binded to the CollectionView the UI no longer updates when MyCollection gets re-assigned.  I read that only CollectionChanged propagate from the Source to the View.  I guess in my case it is the PropertyChange on MyCollection that needs to somehow trigger a CollectionChanged event on the Source or View.
Question:
How can I get a re-assigmend on MyCollection to trigger a UI update, which is bound to a View of MyCollection?
Note:  The reason for re-assigning MyCollection is due to a Modular MEF/MVVM architecture.
<code>public class MyViewModel
{
  public MyViewModel()
  {
    MyCollectionViewSource = new CollectionViewSource() { Source = MyCollection};
    // The DataGrid is bound to this ICollectionView
    MyCollectionView = MyCollectionViewSource.View;
  }

  // Collection Property
  // NotifyPropertyChanged added specifically to notify of MyCollection re-assignment
  ObservableCollection<MyObject> _MyCollection;
  public ObservableCollection<MyObject> MyCollection
  {
    get {return _MyCollection;}
    set {if (value != _MyCollection)
            {_MyCollection = value;
            NotifyPropertyChanged("MyCollection");}}
  }

  public MyCollectionViewSource PropertiesCollectionViewSource { get; private set; }
  public ICollectionView = MyCollectionView { get; private set; }

  // Method updates MyCollection itself (Called via ICommand from another ViewModel)
  public void UpdateCollection(ObservableCollection<MyObject> NewCollection)
  {
    MyCollection = NewCollection;
  }
}
</code>
Thanks,
Comment: Can you reassign `MyCollectionViewSource.Source` too? I don't see that `Properties` have changed.
Comment: My apologies that was a typo.  I have edited the question, the Source property should equal MyCollection.
Answer: Have a look at the Active Grouping Collection, its aimed at a different problem but might solve yours.
Building a smarter WPF CollectionView
Active Collection View on CodePlex


Diverges or converges? Find sequence of a limit

Question: I have a problem, I don't know how to transform the ratio test to get a proper result. Also, if $\lim_{n \to \infty}a_nb_n=\lim_{n \to \infty}a_n  \cdot\lim_{n \to \infty}b_n$and$a_n$ converges to $0$, then why doesn't $\lim_{n \to \infty}a_nb_n=0$ for every $b_n$? I think there's a proof of that and I can't derive it myself. Anyway here is the main problem:
$$\lim_{n \to \infty}\frac{n^{{(-1)}^n}}{n}$$
I was experimenting with limits and wolfram alpha cannot compute the answer for that limit.
From ratio test we get:
$$\lim_{n \to\infty}\frac{(n+1)^{(-1)^{(n+1)}}\cdot n}{n^{(-1)^n}\cdot(n+1)}$$
Answer: $a_n = n^{(-1)^n - 1} = \begin{cases} 1 \qquad n \text{ is even} \\ n^{-2} \quad n \text{ is odd} \end{cases}$
The point is , whenever you are doing the ratio test for this question, you will fall into trouble because the sequence has an alternating term, like $(-1)^n$, which is nagging and won't disappear. Hence, this route is the best one to use:
There is a result (easy to prove):

Suppose that $a_n$ is a convergent sequence. Then, every subsequence of $a_n$ also converges to the same limit as $a_n$.

Now, it is easy to see that $a_n$ does not converge at all, because one subsequence of odd terms $\{n^{-2}\}$converges to $0$, and another of even terms $\{ 1\}$ to $1$.
Comment: Is there another way to prove it than 'easy to see'?
Comment: @II I can think of a better way to prove this, but then again, that involves a complicated result. This problem is not easy, it cannot be done with the help of the tests you  know so far, because of the alternating term.
Comment: If you know what to prove (i.e., have computed the first few terms of the sequence or plotted them), then a simpler thing could be to observe that if $a_n\to L$, then $a_{n+1}-a_n \to L-L=0$, i.e. the difference between consecutive terms must go to zero. But here, you have $a_{2n+1}-a_{2n} = \frac{1}{n^2}-1 \to -1$. Clearly not zero.
Comment: @ClementC. Thank you for the clarification.
Answer: Concerning your limit, note that $\frac{(2k)^{(-1)^{2k}}}{2k} = 1$ and that $\frac{(2k+1)^{(-1)^{2k+1}}}{2k+1} = \frac{1}{(2k+1)^2}$, so your limit doesn't exist, which explains why wolphram alpha doesn't find it.
Concerning your proposition, $\lim\limits_{n \rightarrow + \infty} a_nb_n = \lim\limits_{n \rightarrow + \infty} a_n \times \lim\limits_{n \rightarrow + \infty} b_n$ is not true all the time. If these sufficient (but not necessary) conditions are met :

all limits in the proposition exist
all limits in the proposition are finite

Then you can say it. It may be also true with different conditions not included in that case, but not all the time. Consider

$a_n=(-1)^n$ and $b_n=(-1)^n$
$a_n = \frac{(-1)^n}{n}$ and $b_n=n$
$a_n=\frac{1}{n^2}$ and $b_n = n^3$
Comment: Indeed, it is also true with $b$ bounded and $a$ going to $0$. This is why I mentioned there may be other cases, but those are sufficient conditions.
Comment: What if $b_n$ is just bounded? Then limit may not exist but still $\lim_{n \to \infty}a_n b_n=0$?
Comment: I think that you can't just multiply in $\frac{(2k)^{(-1)^{2k}}}{2k} $ ${(-1)}^n=-n$ wolfram alpha gives another result


Is there a name for the genre that "movies of the future" fall into?

Question: Is there a name for movies/stories/whatever that intend to represent the future (i.e. the year is 2100 and blah blah, like Star Wars etc., actually anything that is not real and is an imagination fantasy of the future).
Comment: Just to pick a nit...  Star Wars is not a future story it's a story that happened "a long time ago, in a galaxy far, far away."
Comment: See also: http://scifi.stackexchange.com/
Comment: @oosterwal, I was going to pick that exact same nit, but you beat me to it.
Comment: I was talking aobut the future parts.
Comment: Movies of the future will be [elaborate] advertisements.
Answer: As others have said, in the absence of any more specific definition, science fiction is the most likely answer. It deals with:

the impact of imagined innovations in science or technology, often in a futuristic setting

However, depending on your point of view, Star Wars may not be a good example, as it can be classed as space opera, which:

emphasizes romantic, often melodramatic adventure, set mainly or entirely in outer space, generally involving conflict between opponents possessing advanced technologies and abilities

Space opera and science fiction are both subgenres of speculative fiction, which:

is an umbrella term encompassing the more highly imaginative fiction genres

For more information, take a look on the Science Fiction & Fantasy Stack Overflow site.
Answer: It all falls under the classification of science fiction. Note that these "future worlds" may actually represent a time in the distant past as well. If you recall from the first Star Wars film (now labeled IV), the opening text crawl announced: "A long time ago, in a galaxy far far away ..."
Comment: @MrHen: That's a long running, but never dominant meme. Those that don't like *"sci-fi"* are likely to use *"sf"* in it's place, and may mean "speculative fiction" by it. It is generally not hard to detect which kind of fans you are in the presence of, and it is not polite to unduly antagonize them.
Comment: And most of the science fiction fans I know never use the abbreviation "sci-fi" unless they're talking about what non-fans think science fiction is.
Comment: @Colin: That may be a quirk of your friends. The sci-fi fans here seem to use the term as much as they can.
Comment: Of course, [some](http://www.youtube.com/watch?v=GnYoyCgFKSI) sci-fi fans go to great lengths to define their genre as the improbable made possible, distinguishing it from fantasy where the impossible is made probable.
Answer: The term 'Future Noir' is used to describe movies like 'Blade Runner' and 'Twelve Monkeys'.  A subset of these films, like 'Terminator', get an additional classification of 'Techno-Noir'.  These all tend to be darkish stories set in a dystopian, often post-apocalyptic, future.  Literature, like '1984' and 'Fahrenheit 451', can fit within the future-noir genre, but can't really be called 'techno-noir'.
The more general term 'Speculative Fiction' covers a wider range of genres, including super-hero fiction and horror, that aren't necessarily set in some future.
Somewhere between the over-encompassing 'speculative fiction' and the narrowly focused 'future noir' and 'techno-noir' genres is 'Future History'.  The 'Star Trek' franchise would fit within this genre, as there are frequent references to their past, which is also our future.
The three links given in the previous paragraphs each have lists of other titles that fit within their respective group.

Edit:
There is also a genre called 'film-blanc', which in contrast to 'film noir's' dark settings and dystopian story lines, offers hope and utopian story lines.  Melding the two already accepted phrases 'future noir' and 'film-blanc' I propose coining 'future blanc' to describe films and literature that are set in a hopeful or utopian future.
Answer: Futuristic SciFi (Science Fiction)


Which Drones are most popular for speed, durability , long battery life?

Question: Also I'm having trouble finding good drones tha can do flips and have good quality of winds resistance and durability, which drone will be worth my time and money ; I have had Dij mavic loved it! But no tricks or flips or anything
Answer: Generally, drones that do "flips" are FPV and scratch-built.
DJI and others have things that come close, but as someone who cuts/designs/builds/flies, nothing comes close to a scratch-build FPV for speed and tricks, period!
Wind resistance (performance in the wind) is several factors. The drivetrain (battery potential, props, motors) and the drone's aerodynamics are the most important.  With little issue, I have flown my 5" drones in 60mph winds. Not fun flights. 5" drones in FPV are stable up to 15-20mph winds, 30mph + is felt, 40mph+ is hard to fly in.  But if you have the power wind is no problem.
Battery life is poor for speed and "tricks"; the only way to get the performance is to toss long flights out the window.  These drones are all motor and battery, little else.
Lower KV motors use higher-pitch props and spin slower.  That is the formula for long flights and battery conservation. Not tricks where inertia works against you.
FPV flights are 3 minutes of flying hard, with high KV motors and various pitches. Higher KV motors spin up and down faster than big lower KV motors.
Re "which drone will be worth my time and money" that's on you. If you want speed and freestyle, you are stuck in scratch-building. The DJI and off-the-shelf units are far from anything in the FPV domain. These types of flights (in which I specialize) break drones like crazy; if you can't repair units yourself, this is NOT a wise direction to go, as it will burn money.
Put into financial terms - as an experienced pilot; I learned to fly trees (literally IN the trees). It took about 1 year to learn, and I broke $2000 of gear learning.  If I were not self-building, this would have been 10x more.


What's the difference between streams and datagrams in network programming?

Question: What's the difference between sockets (stream) and sockets (datagrams)?
Why use one over the other?
Answer: A long time ago I read a great analogy for explaining the difference between the two.  I don't remember where I read it so unfortunately I can't credit the author for the idea, but I've also added a lot of my own knowledge to the core analogy anyway.  So here goes:
A stream socket is like a phone call -- one side places the call, the other answers, you say hello to each other (SYN/ACK in TCP), and then you exchange information.  Once you are done, you say goodbye (FIN/ACK in TCP).  If one side doesn't hear a goodbye, they will usually call the other back since this is an unexpected event; usually the client will reconnect to the server.  There is a guarantee that data will not arrive in a different order than you sent it, and there is a reasonable guarantee that data will not be damaged.
A datagram socket is like passing a note in class.  Consider the case where you are not directly next to the person you are passing the note to; the note will travel from person to person.  It may not reach its destination, and it may be modified by the time it gets there.  If you pass two notes to the same person, they may arrive in an order you didn't intend, since the route the notes take through the classroom may not be the same, one person might not pass a note as fast as another, etc.
So you use a stream socket when having information in order and intact is important.  File transfer protocols are a good example here.  You don't want to download some file with its contents randomly shuffled around and damaged!
You'd use a datagram socket when order is less important than timely delivery (think VoIP or game protocols), when you don't want the higher overhead of a stream (this is why DNS is primarily a datagram protocol, so that servers can respond to many, many requests at once very quickly), or when you don't care too much if the data ever reaches its destination.
To expand on the VoIP/game case, such protocols include their own data-ordering mechanism.  But if one packet is damaged or lost, you don't want to wait on the stream protocol (usually TCP) to issue a re-send request -- you need to recover quickly.  TCP can take up to some number of minutes to recover, and for realtime protocols like gaming or VoIP even three seconds may be unacceptable!  Using a datagram protocol like UDP allows the software to recover from such an event extremely quickly, by simply ignoring the lost data or re-requesting it sooner than TCP would.
VoIP is a good candidate for simply ignoring the lost data -- one party would just hear a short gap, similar to what happens when talking to someone on a cell phone when they have poor reception.  Gaming protocols are often a little more complex, but the actions taken will usually be to either ignore the missing data (if subsequently-received data supercedes the data that was lost), re-request the missing data, or request a complete state update to ensure that the client's state is in sync with the server's.
Comment: This example, or a very similar one, is from The Linux Programming Interface. The 2010 edition contains these examples on pages 1155 and 1159.
Comment: Simply superb for including the detail of SYNACK.
Answer: Stream Socket:

Dedicated & end-to-end channel between server and client.
Use TCP protocol for data transmission.
Reliable and Lossless.
Data sent/received in the similar order.
Long time for recovering lost/mistaken data

Datagram Socket:

Not dedicated & end-to-end channel between server and client.
Use UDP for data transmission.
Not 100% reliable and may lose data.
Data sent/received order might not be the same.
Don't care or rapid recovering lost/mistaken data.
Comment: Isn't data sent in the same order (not just "similar")? ie. it wouldn't make sense to build a packet ordering mechanism into a stream socket
Comment: Packets in a stream communication are sent and received in "similar" order in the sense that the packets themselves are NOT guaranteed to be delivered to the receiving host in order, but TCP figures out the discrepancies, rearranging the packets as they arrive and requesting anything that seems to have gotten lost along the way.
Comment: That makes sense. Maybe just remove that as a difference then and put it beneath (since if I'm understanding it correctly, when referring to only the order at which the packets are sent, in both cases the order that the data is sent/received might not be the same).
Comment: @Rick More precisely, sockets are known as end-to-end points because transport protocols are responsible for delivering messages to one or multiple network endpoints.
Answer: If it is the network programming I think starting from sockets would be a good start.
socket = ip + port
there are three types of sockets
stream (TCP, order and delivery guaranteed,no duplication,no length or char boundaries for data,connection-oriented,reliable, concurrency)
datagram(UDP,packet-based, connectionless, datagram size limit, data can be lost or duplicated, order not guaranteed,not reliable)
raw (direct access to lower layer protocols IP,ICMP)
I do not see any strict rule for transport protocol type as to what socket has to use what transport protocol and reliability should not be mistaken because UDP is realiable in case both ends are active.
Reliability refers  to more like reliability of delivery since there are sequence number checks by using TCP as transport protocol which do not exist in UDP.It is better using network protocol analyzer like wireshark tcpdump etc to see what your software is exactly doing; kind of verification or merging theory on the paper with your work in action.


How to add multiple items to cart?

Question: I came across this other question and wondered whether it was compatible with Drupal 6/UC 2:  Add multiple items to cart
I would like to create a page that shows the thumbnail and title of all products in a category, with a checkbox next to each one. Then, when a shopper checks three, four, five products and clicks "add to cart", those products are all added to the cart.
Or... even better would be if the product automatically gets added to the cart when they click the checkbox, and they can then click a link to go to the cart and finalize their order after they have added all of the products they want... but I know that may be asking a bit too much. ;)
I'm thinking it would be nice for the mobile environment too... the phone/tablet user could simply tap-tap-tap the products they want and then proceed to their cart.
Can anyone point me in the right direction for this?
Answer: For a list with checkboxes I suggest looking at this issue about using Views Bulk Operations.

How to add multiple items to cart?


How to find which of the first 1024 ports seem to be hosting TCP based servers on a specified host?

Question: I want to solve my problem using and I use java programming language.
Answer: Just try to connect to them with a Socket. If you don't get a ConnectException, something is listening st that TCP port. Then do the server a favor and close the socket immediately.
What's the purpose exactly?
Answer: This is a simple code to connect to a socket with a timeout
<code>// Create a socket with a timeout
try {
    InetAddress addr = InetAddress.getByName("java.sun.com");
    int port = 80;
    SocketAddress sockaddr = new InetSocketAddress(addr, port);

    // Create an unbound socket
    Socket sock = new Socket();

    // This method will block no more than timeoutMs.
    // If the timeout occurs, SocketTimeoutException is thrown.
    int timeoutMs = 2000;   // 2 seconds
    sock.connect(sockaddr, timeoutMs);
} catch (UnknownHostException e) {
} catch (SocketTimeoutException e) {
    // Could not reach host - network error.
} catch (IOException e) {
    // Network error
}
</code>
You can just run this code in a loop to check a series of ports.
NOTE: real portscanners are much more sophisticated: http://art-exploitation.org.ua/7261final/lib0021.html
Comment: The comments in your catch blocks are incorrect. SocketTimeoutException indicates a problem communicating with the host. If nothing is listening at the port you will get an immediate ConnectException, not a SocketTimeoutException.


Why does a SSH public key sit on the server and not with the client?

Question: I don't quite understand the theory behind keeping public keys on the server. In the lockbox analogy of public/private keys, to unlock Alice's box, Alice holds the private key while the public key is distributed to Bob. It would seem that the server plays the role of lockbox, so why does it hold the public key?
Answer: Keep in mind that the server DOES have a private and public key which is completely separate from the keypair you generate as a user.  The private key for the server is usually stored with the server configuration and the public key is transmitted by the server when you attempted to connect.  You client compares the server's public key against your known_hosts file.  If used properly, this prevents MITM attacks.
You have the private key for your personal account.  The server needs your public key so that it can verify that your private key for the account you are trying to use is authorized.
So using your example.  Both Bob and Alice have private keys and public keys.  The public keys which have been shared before hand or as part of the connection are used to verify the data encrypted by the private keys is legitimate.  If the client doesn't have the public key, or has a different public key you will get a scary warning.  If the server doesn't have the clients public key, you will not be allowed in.
Comment: Aha! That makes much more sense. I knew there was a method for protecting against MITM attacks, but I didn't know there was another keypair :) Thanks for the help!
Answer: You as the user are the one to provide the information that you are you when you log in.  So for the sake of authorization, you need the private key because the server will ask anyone who pretends to be you (attempts to logs in with your name) to prove it.
The way it works is that the server sends you a bit of text, asks you to encrypt it and decrypt it with your public key.  Only the person with your private key can do this.
Answer: A public key is a very large number, mathematically derived from your private key.

It is derived in such a way that the two numbers are linked,

but so that the private key cannot be discovered by anyone who only knows the public key. The public key is what you send to other parties, to whom you want to authenticate yourself, or to whom you want to send encrypted messages. The public key is not sensitive, and does not need to be protected. It can be disseminated publicly.
email@example.com
Comment: I don't feel there is anything new in this answer compared to the other answers already provided five years ago.
Answer: It holds the public key for convenience.
Otherwise you have to create a PKI - something similar to SSL CA.
The idea would be to check the public key fingerprint when the ssh client ask you to accept the remote server key.
Answer: I would say that a better analogy is that the server's public key is the open lockbox with a latch that you can close (but not open), only the server can open it. The real question is whether you trust the public key (is that really Alice's Box?) , wherever you get it from it is public by definition, and that is what PKI's are about.


Check number of slots used by a query in BigQuery

Question: Is there a way to check how many slots were used by a query over the period of its execution in BigQuery? I checked the execution plan but I could just see the Slot Time in ms but could not see any parameter or any graph to show the number of slots used over the period of execution. I even tried looking at Stackdriver Monitoring but I could not find anything like this. Please let me know if it can be calculated in some way or if I can see it somewhere I might've missed seeing.
Comment: Possible duplicate of [How do I know the number of slots used by Bigquery query?](https://stackoverflow.com/questions/40750393/how-do-i-know-the-number-of-slots-used-by-bigquery-query)
Comment: Okay. Is there no update on it since 2016?
Answer: BigQuery now provides a key in the Jobs API JSON called "timeline".  This structure provides "statistics.query.timeline[].completedUnits" which you can obtain either during job execution or after. If you choose to pull this information after a job has executed, "completedUnits" will be the cumulative sum of all the units of work (slots) utilised during the query execution.
The question might have two parts though:  (1) Total number of slots utilised (units of work completed) or (2) Maximum parallel number of units used at a point in time by the query.
For (1), the answer is as above, given by "completedUnits".
For (2), you might need to consider the maximum value of queryPlan.parallelInputs across all query stages, which would indicate the maximum "number of parallelizable units of work for the stage" (https://cloud.google.com/bigquery/query-plan-explanation)
If, after this, you additionally want to know if the 2000 parallel slots that you are allocated across your entire on-demand query project is sufficient, you'd need to find the point in time across all queries taking place in your project where the slots being utilised is at a maximum.  This is not a trivial task, but Stackdriver monitoring provides the clearest view for you on this.
Comment: Timeline gives you the totalSlotsMs in a specific point in time defined by elapsedMs.
Answer: A BigQuery job will report the total number of slot-milliseconds from the extended query stats in the job metadata, which is analogous to computational cost.  Each stage of the query plan also indicates input stats for the stage, which can be used to indicate the number of units of work each stage dispatched.
More details about the representation can be found in the REST reference for jobs.  See query.statistics.totalSlotMs and statistics.query.queryPlan[].parallelInputs for more information.
Comment: Sorry this is not very clear, Can you provide a more detail example of what you mean
Comment: What do you exactly don't understand, Tamir? Maybe I can help you. Anyway, there's more info too here in the documentation about [Query Plan Explanation](https://cloud.google.com/bigquery/query-plan-explanation#api_sample_representation).


Is a secondary dominant always a seventh chord?

Question: I noticed that secondary dominants are usually dominant seventh chords. Can you just make a secondary dominant a triad, or is it "required" to make it a seventh chord? (also I think this chord is always major).
Comment: always amazed at the answers I get on this forum, thank u all so much
Answer: No, secondary dominants aren't required to be seventh chords. They can be plain triads (e.g. V/vi). They also aren't required to be major or have a major triad--I've heard plenty of vii°7/V chords, and those are diminished 7th chords.
Comment: I think the point is the secondary dominant needs a leading tone, effectively either a `V` or a `viio` with or without 7th or 9ths. But a minor chord wouldn't be a secondary dominant for its lack of a leading tone.
Comment: The "vii°7" would be the Barry Harris style dominant. Barry Harris seems to be somewhat of a hot (or at least lukewarm) topic on teh interwebz.
Comment: @piiperiReinstateMonica, the idea that diminished seventh chords are incomplete dominant seventh flat ninth chords is much older that Barry Harris! It's in my first edition Piston, _Harmony_, but I think even Rameau had the same idea.
Answer: The fact that a secondary dominant, when a major triad, has a M3 in it, which usually moves to the root of the next chord (V) is sufficient. With that b7, there's the tritone which convincingly moves things on, but not needed. And as @piiperi says, that secondary dominant doesn't even need to be major or minor - diminished chords have the propensity to act as pivotal chords in their own right, and take the music into other modulations.
Even when the v/V is minor, there's still enough scope for it to work, as it sometimes does when something in a minor key only uses natural minor notes. Not as convincing, but still feasible. It's good that we are now moving away from the concept of rigid rules, which don't exist these days! I nearly said never, but a few centuries ago, adherence was expected!
Comment: Isn't a v/V just a normal ii chord? Even if we're in a minor key, I would describe that chord as a use of mode mixture. The leading tone is really necessary create the effect of a secondary dominant.
Comment: @Peter - v/V is the same chord as ii. True. The Roman numerals help to define not only the chord, but its function. V doesn't always follow v/V, but when it does, that ii takes on the role of secondary dominant - as in v/V.
Comment: I can't agree with you on this. The ii chord preceding a V acts as a subdominant (like a IV), which is a distinct function from a secondary dominant.
Comment: @Peter the subdominant in key C is F. The secondary dominant is Dm (or D/D7 or Dm7). Common notes abound. True. But its *function* is as a dominant leading to a dominant. Thus the term secondary dominant. That's it.
Comment: We'll have to agree to disagree. Your interpretation does not match with any definition of secondary dominant that I've ever seen.
Answer: A secondary dominant "tonicizes" the chord that follows it, temporarily making it sound like a I chord. So, the secondary dominant needs to lead into that chord. A V chord can do this with the third of the chord, which acts as a leading tone into the root of the following chord. It does not need the 7th of the chord, but that will increase the pull with the existence of the tritone between the 3rd and 7th of the chord. A diminished vii chord can also be used because it contains the leading tone going into the next chord (the root of the vii chord), in addition to the existing tritone in the diminished chord. It is basically the upper portion of a V7 chord, without the root.
A V chord or a diminished vii triad really only point towards one tonic. However, if a fully diminished vii7 is used, there are more possibilities. There are four different tritones in a fully diminished seventh chord, which could point towards four different tonics. For example, D F Ab Cb could "tonicize" Eb, F#, A, or C (and their enharmonic equivalents) depending on how it is interpreted. If more flexibility is desired with a diminished chord, the 7th needs to be used.
Answer: The answer is:NO
while the (V7)  is almost always used: in jazz (IIm7 - V7)
the proper V  is rarely found (as in folk tunes in a choir setting or in church choral settings *)
I just went through some Bach-preludes and didn't find a proper V.
They V will appear in a SATB voicing like:
Oh du fröhliche Weihnachtszeit
Comment: The OP asked about the *secondary dominant*, not the *dominant*.
Comment: yes, I forgot the ( )  thanks, Tim. In the sheet example it is clear that I am relating  to this.
Answer: Most people have stated here that you don't need the seventh to create a secondary dominant sound. That's true, as listening to D, G, C makes sense and sounds arguably just as good as D7, G7, C. But, there's one exception!
V7/IV must contain the seventh degree. In A major, one must use A7 to resolve to D, otherwise it's not a secondary dominant at all. Any other secondary dominant doesn't matter, because without the seventh they aren't diatonic, but V/IV is I7, and I is diatonic and so won't be heard as a secondary dominant unless the minor seventh is added over it.
Dekkadeci recently made me aware (thank you) that in minor keys, V/iv would not need the seventh (In A minor, A major to D minor doesn't need the seventh).
Comment: Note that the similar V/iv can get away without a seventh in a minor-key context, as another reading of it is the alien-in-a-minor-key I (instead of i).
Comment: @user45266 but if you precede the A with, say, a Gm6/E (a.k.a. Em7b5) or Em7 or G or just an Em, then the A works as a secondary dominant even without a 7th. :) (you'll probably say that it's because the preceding chord at least temporarily established the presence of a G)
Answer: "Required" by what? Are you referring to some cultural convention or a law of nature or what?  ;)
Wikipedia's example shows a D major without a seventh: https://en.wikipedia.org/wiki/Secondary_chord
In this example, I think the F# note alone works in some kind of a secondary dominant'ish function, even though it's not even a chord.

On the next line I added more simultaneous notes, leaving less room for imagination. Do these sound secondary-dominantish enough to you?
Some more:

To my ear, the one with the C-F# tritone gives the strongest secondary dominant vibes, followed by the D-F# version. There are at least two ways to think about it. What is the implied "true" chord there - is it D7, or ... F#dim7? In the Barry Harris way of thinking, the dim7 is the "real" dominant.
Comment: *Are you referring to some cultural convention or a law of nature or what?* - it's a question about terminology, so presumably it's just asking what's commonly understood by the term..?
Comment: @topomorto I want to teach a man to fish instead of just giving him a fish.


How to weight features when doing text mining?

Question: I have a case where I'm doing text mining over a list of product titles. In particular I want to run a clustering algorithm. But I also have some information about those products that I think can add a lot of information like the category of the product (if the product is a car, a furniture, etc)
When doing the vectorization of the text data I get a big number of text features ~100.000 and I am pretty sure the category information contains much more information than one single text token so the question is what is a reasonable weight for the category information when fitting a model using both the text features and the category information.
Answer: For obvious reasons we cannot determine the weight for you.
Because there is no mathematical correct weight.
It's entirely up to you to increase the weight of some features you believe to be more important.


Building a workspace (J2ME) on Eclipse 3.6.0

Question: I am beginning work on development/maintenance of a J2ME MIDlet application that uses the Nokia N97 SDK. As a first step (I have never developed J2ME/Java applications before), I completed the following steps on Eclipse 3.6.0 Helios:

Imported the project using the following step:
File -> Import -> Existing Projects into Workspace
Select root directory as TeleDB1 (the name of the directory that contains the files).
When I click on Finish after these steps, Eclipse automatically builds my new workspace. This step is unsuccessful. I get the following errors:

Errors running builder 'Preverification' on project 'TeleDB1'.
org.objectweb.asm.ClassReader.accept(Lorg/object/web/asm/ClassVisitor;Z)V

This is what I have tried:
1. Right-click on the project, Properties -> Java Build Path shows the following libraries:
  a. org-netbeans-modules-mobility-antext.jar - missing
  b. J2ME Library (failed to get library information).
These are my questions:
1. How can I get this project to compile?
2. How do I resolve the errors in the Libraries/Build Path?
I think I have set up my environment for running J2ME applications correctly.
Answer: I have situation as yours, and I find the way to solve it.
Right-click on the project---->properties---->j2me---->device---->manage device,choose a device you like.


Does InfoSec include monitoring?

Question: I am new to InfoSec role, and not really sure if it includes responsibility for monitoring: that's, when we write policies and procedures, who is checking whether they've been obeyed or not? Is it internal audit, is it InfoSec?
Answer: It can be either, depending on the purpose of the monitoring.
InfoSec needs to monitor in order to respond to issues quickly and efficiently so that risks are limited right now.
Governance, Compliance, and Audit will want to monitor in order to ensure that the controls, processes, and policies are working as intended and having the intended effect over time.
However, every organisation can have different resources and needs, and Infosec might also gather and review data for compliance and audit purposes. This is most common in small orgs with small teams where only the infosec people really understand the compliance issues and what the data means.
Comment: Thank you. This clarified a lot for me. The company I am working falls into small orgs category, even our InfoSec team is small, just three people. I'd like to ask one more question, a bit specific, so to clarify a little bit more for myself: Should InfoSec check whether IT admin passwords are stored in sealed envelope in a safe? We have a statement in our password policy stating domain admin passwords should be stored like this. But should we check that they are indeed stored as stated? I am really curious about this one.
Comment: Anyone can check this. The one thing you need to keep in mind is "conflict of interest". You don't want to "grade your own homework". That's why auditors are a separate department. But are you asking who checks or who reviews the info collected? Audit people gather the data and present it to the ***owner*** of the policy/control/risk for them to review and act on. Audit people don't care what the answers are, just that the answers are accurate and complete.
Comment: We've a Risk department above us, so basically we report to them. So I suppose they are the guys who reviews the info collected. I think it's more like as you said "grading our own homework." What I meant was like going to IT department, having them open the safe, checking whether there are sealed envelopes, maybe even opening them to see if there is a password note.
Comment: Info gathering can be done by anyone if they can be trusted to provide accurate and complete data. Heck, I've roped in the janitor to check some infosec things. Who collects the data is only an issue if the person gathering the data could benefit by providing inaccurate data (conflict of interest).
Comment: I see. In our case, I guess we're neutral, that's no conflict of interest. If IT didn't obey the policy, we would just report that. It's as if we don't have any "friendship" bonds with them. But again, it looks to me a bit more for such a small team. Last I heard we've been also required to write a procedure about what to do if incompliance is found. It feels like nobody has an understanding of infosec/audit/risk at my org.
Answer: Agreed with the above answer. I'm new to a security role as well. In the company that I work for and part of the work that my team is involved in is creating the policies and procedures.
But, we also monitor and follow up on anything that has been logged or blocked as a result of the enforced policies.
Comment: @jkwill Infosec can, indeed, include quite a lot of menial work. As a CISO in massive global enterprises, I also wander around looking for sticky notes every once in a while.
Comment: True, in fact some part of it looks very normal to me. It's just the part that requires us to do "menial" work that doesn't look normal. Maybe it's normal, and it's just that I am newbie at InfoSec. But again, it's difficult for me to assume responsibility of visiting offices and checking nobody had sticky password notes on their desk and screen (clean desk policy).
Comment: @schroeder thank you so much! this bit of information is very valuable for me.

Does InfoSec include monitoring?


Ubuntu 18.04.03 cannot hibernate

Question: I am using a swap partition of 10.5GB (almost) while RAM of my system is 8GB. My

/etc/fstab

file looks like this
<code># /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda4 during installation
UUID=19ea5c3c-94ff-4678-a071-f2990aac9191 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=C6C7-F14C  /boot/efi       vfat    umask=0077      0       1
UUID=9dab264a-b79a-42bc-affb-5b541ffaa057         none       swap     defaults    0   0
# /swapfile                                 none            swap    sw              0       0
/dev/disk/by-uuid/4C3886483886314E /mnt/Data auto nosuid,nodev,nofail,x-gvfs-show 0 0
</code>
swap is automatically mounted on boot (works fine)
when I execute the command

sudo pm-hibernate

It waits for sometime then pc shuts down (which is good).
The problem starts when I boot it after the whole process.
It does not continue where I left.
It just boots like it does without above process.
I also created a file

/etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

and added this in the file
<code>[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate
ResultActive=yes
</code>
But it does not seem to do anything.
Can anyone tell me how to hibernate ubuntu 18.04.3?
I want it to automatically hibernate on critically low battery level and also after 1 hour long hybrid-sleep/suspend/sleep.
My laptop is Dell Vostro 14-3468.
Plz, help guys...
Comment: If you are using Secure Boot, then hibernation is disabled as a security risk. I have this problem, and I don't want to disable Secure Boot, but I don't think there is another solution. (Note, I haven't verified that hibernation works with Secure Boot disabled.)
Answer: Problem is partially solved.
I just needed to add

resume=UUID={UUID of swap partition)

in kernel parameters in general section of grub-customizer.
I also installed a gnome extension 'Hibernate status button' for easy hibernation.

Ubuntu 18.04.03 cannot hibernate


Why are there no triple affine Hecke algebras?

Question: This question arised after I recently stumbled upon the paper "Triple groups and Cherednik algebras". Doubly affine Hecke algebras are sort of a natural object to consider after finite and affine Hecke algebras. This makes one wonder, why are there no "triple affine Hecke algebras"? Or, if such a construction exists, why are they not useful? (The theory of doubly affine Hecke algebras has proved to have deep consequences and relations with many fields of mathematics, see this previous question.)
Comment: The Weyl group $W$ acts naturally on the root and coroot lattices, and my understanding is that the (double) affine Hecke algebra is a deformation of the group algebra of the semidirect product of $W$ with (the coroot lattice plus) the root lattice. It seems like a "triple affine Hecke algebra" would require the action of $W$ on a third lattice, but I don't know any natural candidate for such a lattice.
Comment: This is probably unrelated, but I'm reminded of a quote (well, paraphrase) from Richard Borcherds in one of his Lie Theory classes. The context was the discussion of Kac–Moody groups. Recall that if the Cartan is positive definite ("of finite type") then the corresponding group is finite-dimensional and has a unique compact real form. If the Cartan has one-dimensional kernel ("of affine type"), then the corresponding group is a version of a loop group (up to some twisting) of a compact group. These groups are all very important. Richard ended his discussion by saying that one of the most ...
Comment: ... important open problems in Lie Theory is to find any applications at all for the Kac–Moody groups beyond affine type. (Note in particular that they do not correspond to "double loop groups" or anything so simple.)
Comment: @Peter correct, after deformation  we make q- difference operators from coroots which act on roots. In rational case we get differential operators. More generallly roots+coroots can be substituated by any symplectic vector space. And Weyl group by any finite group acting symplectically that what EtingofGinzburg did.
Comment: Looking 5min on paper it seems to me very interesting Kyoji Saito ideas deserving to be further explored however I did get their main idea. What they mean by triple group?
Answer: It would be great if they existed, even if only for the symmetric group. One possible application would be to algebraic combinatorics: Mark Haiman has collected data suggesting that the ring $R/R^{S_n}_+$ has dimension $2^n (n+1)^{n-2}$, where
$$R=\mathbb{Q}[x_1,\dots,x_n,y_1,\dots,y_n,z_1,\dots,z_n],$$ the symmetric group acts by simultaneously permuting the three sets of variables, and the notation $R^{S_n}_+$ means the ideal generated by positive degree symmetric polynomials.
Iain Gordon showed that it is possible to use the representation theory of the rational Cherednik algebra (the rational object in the rational/trigonometric/elliptic trichotomy whose elliptic object is the DAHA) to establish the correct lower bound on this dimension in the case of two sets of variables (this dimension turns out to be $(n+1)^{n-1}$, a theorem proved by Haiman using a suggestion of Procesi and the geometry of the Hilbert scheme of points in the plane). So one might hope to use the representation theory of a TAHA to prove the correct lower bound, at least.
The reason the double affine Hecke algebra exists at all is a little subtle, and has to do with @Theo Johnson-Freyd's comments to the question: the affine Hecke algebra has two realizations. First, the affine Hecke algebra is an affinization of a finite Hecke algebra; second, it is the Hecke algebra associated to the affine Weyl group (or, if you prefer, for a certain specialization it is the Hecke algebra corresponding to an Iwahori subgroup of a p-adic group). Starting with the second presentation, one affinizes again to obtain the DAHA. The point here is that
$$\{\text{affine Hecke algebras} \}=\{\text{Hecke algebras of affine groups} \}$$
and we know how to affinize the Hecke algebras on the RHS.
But so far the DAHA has no second realization as the Hecke algebra of something that can be affinized again. Perhaps recent work of Kazhdan and his collaborators could help here, but I have not read these papers carefully enough to know.
There is a second approach that is somewhat more geometrical. The rational Cherednik algebra is a deformation of the algebra $\mathbb{Q}[x_1,\dots,x_n,y_1,\dots,y_n] \rtimes S_n$, so one might look for nice deformations of the analogous objects in three sets of variables. Perhaps experts in Hochschild cohomology have done calculations suggesting where to look?
Answer: This is a wonderful and highly suggestive question. In addition to the fascinating hints provided by Stephen's answer, there are also reasons from geometric representation theory (as well as from physics) to expect that a triple affine Hecke algebra theory might exist.
A very faint hint in representation theory can be seen for example from my paper
Elliptic Springer Theory with David Nadler
(I am sure there are better references for this faint hint but I'm sadly ignorant
of the elliptic literature - just now learned of the beautiful paper of Ion-Sahi from reading this question!)
First recall that the Weyl group appears as endomorphisms of the
Grothendieck-Springer sheaf, a remarkable perverse sheaf (or $D$-module) on the nilpotent cone of a Lie algebra. However, if you consider the ext-algebra of the Springer sheaf, you find instead the degenerate affine Hecke algebra - i.e., you "sprout" a polynomial ring (functions on a torus Lie algebra, or if you prefer, torus-equivariant cohomology of a point). Next we can consider the group version, the Hotta-Kashiwara sheaf, a $G$-equivariant sheaf on $G$ constructed from the group version of the Grothendieck-Springer resolution. It has an endomorphism algebra which is an affine Weyl group, i.e. we've added the group algebra of the lattice, but an Ext algebra which is a form of the degenerate DAHA (really we are missing all the interesting parameters here, one ought to consider a ``mixed" version to see something closer to the objects of interest).
Finally there's an elliptic version, living on the "elliptic group" -- the moduli of semistable $G$-bundles on an elliptic curve (recovering the previous two when the curve degenerates to a nodal, then cuspidal, Weierstrass cubic). We discuss an obvious elliptic version of the Springer sheaf there -- in fact a special case of the theory of geometric Eisenstein series (a much more thorough study is in Dragos Fratila's thesis). Its endomorphisms are identified with a double affine Weyl group (ie two copies of the same lattice, not duals)... but its Exts will again sprout another polynomial ring, and should be considered a very degenerate form of a "degenerate triple affine Hecke algebra".
One really needs to make it much less degenerate to get something close to answering
this question - i.e., add a "q" (mixed version) and a "t" (twisted $D$-module/quantum group parameter) at the least. But it's something natural and triple.
[I can't say anything reasonable about the physics in finite length, or maybe at all, but I'll allow myself just a vague hint: double affine Hecke algebras (at least in type A) arise (again in very degenerate form) in studying the Seiberg-Witten integrable systems (i.e. moduli space after compactification on a circle) of $N=4$ super Yang-Mills in four dimensions - which is itself a reduction on two circles of the mysterious (2,0) theory in 6 dimensions, aka "theory $\mathfrak X$".. this realization shows that there are not just two, but three, circles in the picture - switching around two gives an $SL_2Z$ symmetry, aka Langlands/S/electro-magnetic duality, but switching around all three ought to give some
hint of $SL_3Z$ symmetry.]
Comment: Nice! I suppose the moral for me is, using Ext algebras instead of End provides an extra lattice (or polynomial ring). Is it right that without doing the mixed version you just get something like a semidirect product of the Weyl group with a commutative ring?
Comment: @StephenGriffeth: that sounds right... not so exciting without turning on some of the available deformation parameters! (Presumably one can arrange an extra lattice rather than polynomial rings by ``decompleting" - replacing cohomology with K-theory, or passing to inertia stacks..)


Basic AutoHotKey input doubler?

Question: I have a fairly simple idea that I think AutoHotKey could help me with. Essentially, when I use ctrl-v to paste, I want it to transmit a second ctrl-v so that I paste twice. I've got several keybinds in my development environment set up to be double-strokes of various ctrl keypresses, so I'd also like to be able to extend the script to various other keys aside from ctrl-v, too. This is my first AutoHotKey script though and I'm having a hard time getting off the ground since there's a lot here to digest. Thanks!
Comment: Is tapping v twice so hard you need to script it? Or should I say *request* a script for it ;)
Comment: Like I said, I have a number of other hotkeys that are set up as doubled keystrokes as well. This was partly to speed up those keystrokes, while also serving as a contextually-relevant way to get me started with AHK, I guess.
Answer: In AutoHotkey, double-sending a key is pretty straightforward.
#IfWinActive
~^v::SendInput, ^v

A few additional items:
1) You can tailor which programs will receive a double-send or not by using #IfWinActive and designating a window name, exe name, class, etc. for WinTitle
2) The tilde in the hotkey definition means that the script doesn't stop the original keystroke from going through.  If you want full control over whether the original goes through or not, you could remove the tilde (which will block the original keystroke) and then send it twice yourself (or not at all, or whatever you might want to do without the original keystroke getting registered).
3) You can add a delay if needed by extending the function to more than just a single-line hotkey definition and using a Return statement
4) You can use the same code for multiple hotkeys using A_ThisHotkey.
5) You can also allow keystrokes with multiple modifiers using a * modifier if needed.  This may not work exactly right with the example code below but just something to be aware of.
Example of above items 1-4:
; this will execute the code to send duplicate keystrokes
; for any of the hotkeys defined, in this case, a,b,c, or Ctrl+V
#IfWinActive ahk_exe notepad.exe
~a::
~b::
~c::
~^v::
    Sleep 200   ; Possibly use or adjust for reliability if needed
    SendInput % SubStr(A_ThisHotkey, 2) ; Remove tilde and send duplicate keystrokes for whichever hotkey executed
Return

Comment: I haven't worked with ahk for some time, but doesn't this trigger an infinite loop of hotkeys?
Comment: No. AutoHotkey prevents that by default. You can use SendLevel settings to retrigger hotkey definitions if needed.
Comment: I like the easy extensibility that this script exposes, rather than having nearly-identical blocks per-key that differ only in the key being duplicated. Very cool!

Basic AutoHotKey input doubler?


Endoscope for a pools plumbing

Question: Has anyone tried to use an endoscope for their pool plumbing? I bought one but it wont get very far into the pool lines without getting stuck. Ive tried using a plumbing snake by itself, but really it just does the same thing. Any ideas would be appreciated. Thanks guys.
Comment: Is it getting snagged on a 90 degree bend?
Comment: What are you trying to achieve?
Comment: I have 3 returns that are not working. I have in the past repaired kinked flex lines in the ground where I could dig them up, but now everything is under concrete. So I want to try and make sure its what I think it is, more kinked lines. If I could get the camera to go the whole length I could maybe find out where the kink is and have a chance at fixing it myself.
Comment: Flex lines underground well you know what the problem is ether a 90 since these lines are pressure based and not drains that have sweeps. It's that or crushed flex. Not much we can suggest other try going from the other side but you will hit the T or 90 and get stuck again even if not crushed.
Comment: Yup, tried that as well. I tried going into the return as well and just hit another 90 and it would not go any further.  I just thought I would ask. I was hoping someone tried it and succeeded. Thanks for your answers.
Answer: It's going to be tough to push anything semi-rigid through plumbing because plumbing uses tight 90 degree elbows -- not like the long-sweep type used for electrical conduit.
If the flow is not completely stopped then here are a few ideas.
You might have some luck getting some string through the pipe by letting it be carried in the flow of air from a vacuum or flow of water. It may help to tie a small object to the string (a small plastic bag is a common choice) so that the string experiences more drag and is pulled along better in the flow.
If you can get a string though you might be able to use the string to help pull the camera through. It's still going to be tricky to get around the elbows, particularly if the pipe is smaller in diameter.
Underground conduit systems are sometimes tested by feeding a "mandrel" through the pipe. This verifies the pipe is the correct size, is not crimped, etc. You might be able to inspect your piping with a mandrel instead of a camera. A small plastic ball, a piece of wood, etc could serve. Make it half the size of the pipe and find out whether it passes through. Attach a string marked with lengths like a measuring tape to the mandrel so that if it hits an obstruction you'll know how far along the path that occurred. Also, if it becomes wedged and cannot be pulled back out by the string, you'll know where to go digging to extract it.. :-(

Endoscope for a pools plumbing


Periods of Sine, Cosine and Tangent

Question: I would like to know how to calculate $(-1)^n$ and $(-1)^n(-1)^n$ being periodic and get an explanation for the functions sine, cosine, and tangent periods. I know that for a signal to be periodic there has to be such $T$, that satisfies:
$$f(n)=f(n+T)$$
It may explain the reason why sine and cosine periods are $2\pi$, once $(−1)^n$ period is $2$, and why the tangent period is $\pi$, once $(−1)^n⋅(−1)^n$ has period $1$.
Comment: Why are you having questions.  $\sin(n + 2\pi) = \sin n$ so $2\pi$ is *a* period of $\sin$ (but it might not be the smallest one) and $(-1)^{n+2} = (-1)^n$ so $2$ is a period of $f(n)= (-1)^n$.  .... so what's your question?
Answer:
I know that for a signal to be periodic there has to be such T, that satisfies:

By that definition there may be multiple periods.
$\sin(n + 4,567,282\pi) = \sin n$ so $\sin n$ is periodic.
And $4,567,282\pi$ is a period of $\sin$ but in might not be the smallest.
Likewise if $f(n+T) = f(n)$ then $f(n+97T)=f(n)$ so $f$ is periodic but $97$ isn't the smallest period and, for all we know, $T$ might not be either.
Usually when saying a function is "periodic" we want to know what the smallest period is (which we usually say is "the" period).
If $T = 2k\pi$ then $\sin (n+T) = \sin n$ but the smallest such $T$ (greater than $0$) so that $\sin (n+T)=\sin n$ is $T= 2\pi$.
It is true that for any $n$ that $\sin (n + 2\pi) = \sin n$.
I won't prove this, but for any $T< 2\pi$ there will always be some $n$ where $\sin (n+T) \ne \sin n$. For example if $T = \pi$ then $\sin(n+\pi) =-\sin n$ and those aren't usually equal.
So why is $\tan$ different.  Well, $\tan$ is a different function that $\sin$ so there is no reason it should be the same.
But notice:  $\tan (n+\pi) = \frac {\sin (n + \pi)}{\cos (n+\pi)} = \frac {-\sin n}{-\cos n} = \frac {\sin n}{\cos n}$ so $\pi$ is a period, even though it isn't a period for $\sin$ or $\cos$.

Periods of Sine, Cosine and Tangent


What is a ZKRollup? And how does it work in scaling a DAPP?

Question: I have tried looking into existing solutions such as ZKSync. I couldn't understand why you would rewrite your smart contracts in a different language - Zinc (as opposed to Solidity/Vyper).
Answer: Most of the ZKP frameworks such as Zokrates, Circom, SnarkJS, gNARK etc. are designed for creating circuits, quadratic arithmetic programs and internal representations. Zinc is a fresh attempt to bring smart contracts to the ZKP frameworks with good guarantee for safety and security. It is constructed as a smart contract language optimized for ZKP circuits.


How to add a popup menu to the default toolbar?

Question: Is there a way to customize the default toolbar in Mathematica 13? I would like to add a new icon to the toolbar, which triggers a popup menu containing several frontend operations I can customize (such as tagging cells and inserting automatic numberings). I imagine its behavior should be similar to the hyperlink icon:
Comment: The current toolbar does not support end user customizations. We know there is a good amount of interest in that.
Answer: I'm afraid we can't do that. However your need may be met in some other ways.

Why I feel it impossible
Mathematica provided a menu item placed in the menu Window/Toolbar. This item is parallel to Ruler etc., these items are toggled by several FrontEndTokens, while their neighborhoods Templating and Testing are DockedCells toggled by KernelExecute. In fact, these menu items change the absence of "MultipurposeBar" element in the notebook option WindowToolbars.
This seems to imply that this toolbar is a raw Qt frontend object, instead of something represented and controlled by a WL expression.

What can you do
For a customized menu, you can try adding you own DockedCells(by SetOptions) or integrating your buttons into the menubar(by modifying MenuSetup.tr).
The former way is usually preferred if you want this utility to be limited in some notebooks instead of be a global setting. WRI's Package.nb creates DockedCells in stylesheets, template notebooks set this option for each specific notebook.)
IMO, an advantage of the latter way is that you can have a keyboard shortcut with a better performance(compared to FrontEndEventActions).
The WL funciton for menus is ActionMenu, while its box representation is ActionMenuBox. With some knowledge of cell/box and proper Appearance option, you can easily achieve your goal.
BTW, WRI also provides palletes for such things. However I often feel those extra windows disturbing.


Whats the cross sectional area related to shear stress in torsion of a bar?

Question: In shear force in a rectangular bar,the relevant area is the cross sectional area parallel to the applied force.But in torsion which also undergo shearing we get shear stress from torsion equation.I like to know if we get a shear stress due to torsion in a rod,relevant area should be the cross section of the rod or is it irrelevant because rather than cross section its polar moment of area that influence shearing?
Comment: or is it the outer surface area?
Answer: Relevant area while applying torsional moment will one which is perpendicular to Moment direction. Shearing action will happen between surfaces which are perpendicular to the direction of the moment.
Even though the polar moment of the area appears in the equation saying that area is irrelevant doesn't make sense because it's the polar moment of that cross-sectional area where shear action is happening.
Answer: The terms shear stress and torsion stress are synonymous when it comes to stress due to torque versus stress due to shearing force. The torsion or shear stress in a circular member is given by
$$τ=\frac{Tr}{J}$$
Where $T$ is the applied torque, $r$ is the radius and $J$ is the polar moment of inertia.  The equation applies to a solid circular shaft or a thick walled shaft where the wall thickness $t$  is given by $t>0.1r$.
The cross sectional area is taken into account by the polar moment of inertia. The polar moment of inertia of a solid shaft is given by
$$J=\frac{πa^4}{2}$$
Where $a$ is the radius.
For a circular disc, it is given by
$$J=\frac{π(a^4-b^4)}{2}$$
Where $a$ is the outside radius of the disc and $b$ the inside radius.
You can see that the cross sectional material area of the disc is less than the solid circular area, and therefore the torsional stress due to torque on the disc is greater than the solid circle as you would expect. The same would apply if you apply the same shearing force to a rectangular bar of less cross sectional area.
Hope this helps.


What to do with a village too close to my Iron Farm?

Question: I have made an iron farm and I read something about villages having to be 150 blocks from the iron farm for it to function efficiently. I only read this after building it though, and there's a village about 120 blocks from the edge of the farm, and I cannot be asked to rebuild it.
I instead thought: could it be possible to get rid of the village? (I destroyed all the beds, workstations, doors, bells, houses and everything I could see that was village related).
Do I also need to kill all villagers becuase I created a few new ones to breed?
Answer: As far as I know, the reason that you can't have a village too close to an iron farm is because villagers will only spawn an iron golem if they haven't seen another iron golem recently. Villiger spawn iron golems periodically, so having a village near an iron farm means there is a risk that an iron golem from the village will wonder too close to the farm and prevent more iron golems from spawning.
Villagers also won't spawn an iron golem if they haven't slept recently. (I'm not sure if this is true for villagers running away from mobs, as their behaviour changes to make it easier for them to spawn iron golems. This is why the iron farm works.)
Because of this, I'd imagine that destroying most of the beds would be enough, however you could kill most of the villagers as well if you want to be safe.
See https://minecraft.wiki/w/Villager#Iron_golem_summoning
I think it should be ok to leave up to two villagers. (or 4 if you are sure that aggressive mobs will not be able to go near them)
I'm sorry that I've not been able to provide a concrete answer, however I hope my information is somewhat helpful.
Comment: Thank you i will try to spawn proof the area so no aggresice mobs will be able to spawn


Website Spidering Auto Detection

Question: Is it possible to write code to detect if a website is spidering the content?
Answer: a good spider

reads the robots.txt
has a proper user-agent
will query faster than an average user

But a clear detection if it's a browser or a spider is not possible i think.
Answer: You try using the user agent string to identify the bots.
Different bots seem to have different user agent strings:
http://www.useragentstring.com/pages/useragentstring.php
However, the user agent string can be easily spoof.
Answer: You can use a list of User-Agent strings that the common bots use. You can use some form of rate-detection and determine that a very high rate of requests will probably be a spider (or someone leeching your entire site).
There might also be lists of IP adresses used by common bots, but a fool-proof detection system is most-likely impossible.
You could create a link on your pages that a real visitor would never click and flag anyone that does follow the link as a spider. You will get some people clicking the link anyway but curiosity cannot be avoided.
Answer: If the spider is nice, you can detect it through it's user-agent using a list of existing user agents like this. But a nice webspider usually also follows robots.txt convention
Robots that ignore the robots.txt file and spoof their user-agent most likely also use other means to hide that they are a spider.

Website Spidering Auto Detection