Routing not working properly when two NICs connected

Question: We're running a server with a NetXtreme BCM5720 2-port Gigabit Ethernet PCIe card. This has two ports, which each maps to different physical id and logical names;
sudo lshw -class network
  *-network:0
       description: Ethernet interface
       product: NetXtreme BCM5720 2-port Gigabit Ethernet PCIe
       vendor: Broadcom Inc. and subsidiaries
       physical id: 0
       bus info: pci@0000:04:00.0
       logical name: eno1
       version: 00
       serial: b8:cb:29:97:26:61
       size: 1Gbit/s
       capacity: 1Gbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm vpd msi msix pciexpress bus_master cap_list rom ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=tg3 driverversion=3.137 duplex=full firmware=FFV21.81.3 bc 5720-v1.39 ip=192.168.1.211 latency=0 link=yes multicast=yes port=twisted pair speed=1Gbit/s
       resources: irq:17 memory:91930000-9193ffff memory:91940000-9194ffff memory:91950000-9195ffff memory:91d00000-91d3ffff
  *-network:1
       description: Ethernet interface
       product: NetXtreme BCM5720 2-port Gigabit Ethernet PCIe
       vendor: Broadcom Inc. and subsidiaries
       physical id: 0.1
       bus info: pci@0000:04:00.1
       logical name: eno2
       version: 00
       serial: b8:cb:29:97:26:62
       size: 1Gbit/s
       capacity: 1Gbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm vpd msi msix pciexpress bus_master cap_list rom ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=tg3 driverversion=3.137 duplex=full firmware=FFV21.81.3 bc 5720-v1.39 ip=192.168.3.201 latency=0 link=yes multicast=yes port=twisted pair speed=1Gbit/s
       resources: irq:18 memory:91900000-9190ffff memory:91910000-9191ffff memory:91920000-9192ffff memory:91d40000-91d7ffff

As shown by the output, they are given IPs on different subnets.
The 192.168.3 subnet faces outwards, whereas 192.168.1 is internal only.
We have configured port forwarding in our router such that inbound traffic to port 80 and 443 goes to 192.168.3.201
The intent is to run web applications on that server, while leaving the ssh open on the internal network for maintenance.
This works ... partly
In order to test we run the default nginx docker image
docker run -d -p 192.168.3.201:80:80 -p 192.168.3.201:443:443 --restart=unless-stopped nginx:latest

Initially, we are NOT able to access the web interface from outside. However, if we pull the ethernet cable to eno0, it suddenly works. What really boggles my mind is that it actually continues to work when plugging eno0 back in.
This is highly reproducible. After system reboot it does not work, but unplugging / re-plugging eno0 and it suddenly works again.
What are we missing?
Adding output of ip route as per suggest by JFL;
at rebbot;
default via 192.168.1.1 dev eno1 proto dhcp src 192.168.1.211 metric 100
default via 192.168.3.1 dev eno2 proto dhcp src 192.168.3.201 metric 100
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
192.168.1.0/24 dev eno1 proto kernel scope link src 192.168.1.211
192.168.1.1 dev eno1 proto dhcp scope link src 192.168.1.211 metric 100
192.168.3.0/24 dev eno2 proto kernel scope link src 192.168.3.201
192.168.3.1 dev eno2 proto dhcp scope link src 192.168.3.201 metric 100

When unplugging eno0;
default via 192.168.3.1 dev eno2 proto dhcp src 192.168.3.201 metric 100
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
192.168.3.0/24 dev eno2 proto kernel scope link src 192.168.3.201
192.168.3.1 dev eno2 proto dhcp scope link src 192.168.3.201 metric 100

After replugging eno0
default via 192.168.3.1 dev eno2 proto dhcp src 192.168.3.201 metric 100
default via 192.168.1.1 dev eno1 proto dhcp src 192.168.1.211 metric 100
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
192.168.1.0/24 dev eno1 proto kernel scope link src 192.168.1.211
192.168.1.1 dev eno1 proto dhcp scope link src 192.168.1.211 metric 100
192.168.3.0/24 dev eno2 proto kernel scope link src 192.168.3.201
192.168.3.1 dev eno2 proto dhcp scope link src 192.168.3.201 metric 100

Comment: Can you add the output of "ip route" before and after the unplugging / re-plugging?
Answer: your issue is that you have configured a gateway on both interfaces, as shown by:
default via 192.168.1.1 dev eno1 proto dhcp src 192.168.1.211 metric 100
default via 192.168.3.1 dev eno2 proto dhcp src 192.168.3.201 metric 100

Both have the same metric so the system has to choose one. How this choice is made depends on the operating system used.
Whatever the criteria your OS use, it select the route that goes out the eno1 interface at boot, so the traffic is not sent to the Internet.
When you unplug the NIC, there's only one gateway left (the correct one), so it works.
The fact it still works after you replug eno1 show that your OS probably use the "oldest" route (you can see the order of those two routes are reversed after re-pluging).
To fix this , you need to remove the default gateway on the internal NIC, and if needed replace it by routes to you internal network. If you don't have any other internal network than 192.168.1.X/X then you do not need those routes.
Since you are using DHCP you need to remove the "router" setting from the 192.168.3.X/X scope or to use a static IP address instead (if you need to leave the router option for other hosts).


Kivy rotation during movement

Question: I'm struggling with how to properly implement simultaneous movement and rotation using Kivy (in python, not kv lang). My goal is to rotate an object so it's facing its destination then move it towards the destination using Animation. Using the code below I typically get movement in relation to the angle rotated instead of in relation to my general playing area. For example the animation without rotation might move an image to point [1,1] whereas with rotation of 180* the animation is moving the image to [-1,-1]. The image is properly rotated in this scenario, meaning it's facing the right way but going the wrong way.
My understanding is that the push/pop matrix functions should provide the appropriate context for the animation rather than the rotated element context. Because the PopMatrix function is happening in Canvas.after it seems like this has no effect - my animation is completed before the original Matrix is restored.
I'm lacking some key piece of information here that's causing a lot of headache. Can someone explain why the code below causes an image to move to (-1,-1) rather than the (1,1) indicated, and how to properly implement this?
I threw this code together as an example, my game code is far more complex. That's why I'm hoping for an explanation rather than a direct solution for my code. Thanks.
    with self.image.canvas.before:
        PushMatrix()
        self.rot = Rotate()
        self.rot.axis = (0, 0, 1)
        self.rot.origin=self.center
        self.rot.angle=180
    with self.image.canvas.after:
        PopMatrix()

    self.anim = Animation(pos = (1,1), duration=1)
    self.anim.start(self)
    self.image.pos = self.pos
    self.image.size = self.size

Answer: In case others are interested in how to make this work consistently - I've found that setting origin and angle on each frame, along with binding the image widget to any pos change on it's parent will ensure the widget moves with its parent and in the proper direction. I implemented that like this:
Instantiate the image like this:
with self.image.canvas.before:
    PushMatrix()
    self.rot = Rotate()
    self.rot.axis = (0, 0, 1)
    self.rot.origin=self.center
    self.rot.angle = 0
with self.image.canvas.after:
    PopMatrix()

Bind it like this:
self.bind(pos = self.binding)

def binding(self, *args):
    self.image.center = self.center
    self.image.size = self.size

On each frame call a function that does similar to the below.
self.rot.origin = self.center
self.rot.angle = getangle()#you can use a set angle or generate a new angle every frame

Comment: There's a way using kv language to make this work reliably. Set an angle property in your widget upon creation and set the rotation properties on the canvas (similar to the above) in KV. Then just update the angle property from python when needed.
Comment: I'm not entirely clear - did this manage to (or were you trying to), decouple the bitmap-display-angle, from widget motion? Can a bitmap/widget, be pointed in a random angle (say 45 degrees), while its movement is, say, horizontal across the screen? Or does changing the angle, always change the frame-of-motion to follow? I might even make this a Question, but I figured the Answer would just be "it can't be done that way". :)
Comment: Never mind, got it working. Didn't need the binding, as my object was itself an Image - but using `rot.origin` and `rot.angle` inside the frame-update function, actually worked. The Image moved where I wanted it, but its bitmap-angle changed. Not entirely sure *why* this worked, will have to research it more, but it does. The joys of using pure-python, instead of kv-lang. :)
Answer: Rotate effectively changes the coordinate system used by the entire canvas, so after you've rotated by 180 degrees the position [1, 1] really is in the opposite direction to what it was before, as far as any canvas instruction is concerned.
I don't know what self.image is (maybe an Image widget?), but presumably whatever you see is something like a Rectangle drawn on its canvas, whose pos and size match those of the widget. When you update that pos and size, the Rectangle is positioned according to the current coordinate system, which is in the rotated frame.
Thinking about it, I'm not sure if there's a neat way to combine Rotate instructions with Kivy's high level widget coordinates in quite this way. Of course you can work around it in various ways, such as by accounting for the rotation when setting the position of the Rectangle, but that's kind of fiddly, and inconvenient when working with prebuilt widgets. You can also look at what the Scatter widget does to enable arbitrary transformations.
If you just want to rotate by 180 degrees, you can instead adjust the image being displayed, either before displaying it or by adjusting the tex_coords of the Rectangle to change the displayed orientation. However, this won't work for arbitrary rotations, which it looks like you may want.
Comment: Thanks. I've had some success by rotating the object then moving it after the rotation is complete. Simultaneous movement and rotation doesn't seem possible. The (seemingly) best way to do this is to set an object variable ("self.image.angle") specific to the rotation angle then update that property as needed. It seems like Kivy has an observer automatically attached to the property so by updating the angle the image is rotated appropriately.

Kivy rotation during movement


Using GORM efficiently to retrieve join data - Grails 2.3

Question: I have User, and Follow Domain class that construct the Follower, Following relationship like Twitter. When my User visits another User's page, and click on their Follower list. I pop-up the list of the visited person's follower list, and then show a button in front of it that is labeled "Follow" or "Unfollow" depending on if you already following that person. So I do it the following way, but I'm not sure if this is efficient or maybe there is a better way of doing it. In order to make it efficient, I only retrieve 20 follower at a time and allow pagination.
> example of pop-up:
> ----------------------------------------------
> alex [follow]
> dave [unfollow]
> sarah[follow]
> paul [follow]
> ----------------------------------------------

Follow domain class has:
// The person to follow
User follow
// The person who is following the follow
User follower
// The status of the relationship if removed or still following
boolean status

User domain class is the typical Spring Security User class with a bunch of extra fields like locations and etc.
In my controller when I receive a request for follower list I do the following.
def visitedUser = User.get(visitedUserId)
// get the list of top 20 followers of this user
def followerList = Follow.findAllByFollow(visitedUser, [max:20])

// get the list of all people current user follow who is in the 20 follower list
def mutualFollow = Follow.findAllByFollowerAndFollowInList(currentUser, followerList)

Now I have the list of all the followers in profile of the person I'm visiting, and also the list of those who are mutual. Then I pass both to my GSP and while loop through the followerList in GSP, I compare the id of that follower, if the follower exist in my mutualFollow list I tweak the button to "unfollow" otherwise I keep the button as follow.
One step further to optimize this is to user projection to only retrieve the id of the mutualFollow instead of the whole USER domain object, but since USERs coming back are proxied and they have wrapper around them, I'm not sure that makes a big difference. Because All I retrieve is the id.
I appreciate any suggestion to improve this approach or an alternative. Thanks
Answer: I decided to use HQL and only retrieve the necessary info of those USERs within the follow list, and then I did a join to get the mutual people they both follow. And used that in the GSP page. Here is the simplified solution in SQL:
SELECT Ur.follow_id, Urs.follow_id as mutual FROM (SELECT * FROM FOLLOW WHERE FOLLOWER_ID=1)as Urs
RIGHT JOIN (SELECT * FROM FOLLOW WHERE FOLLOWER_ID=3) as Ur
ON Urs.follow_id=Ur.follow_id order by Ur.follow_id;


python aws s3 file distributing

Question: I am looking to this tutorial. I would like to know is the anyway to distribute large amount of file over the different objects. As the example let's say I have video file with size 60 GB and I have S3 bucklets with size 4 x 15 GB. Now how can I split my file for keeping that at these size storages. I will be happy if you can share any tutorial.
Answer: S3 buckets don't have restrictions on size so there is typically no reason to split a file across buckets.
If you really want to split the file across buckets (and I would not recommend doing this) you can write the first 25% of bytes to an object in bucket A, the next 25% of bytes to an object in bucket B, etc. But that's moderately complicated (you have to split the source file and upload just the relevant bytes) and then you have to deal with combining them later in order to retrieve the complete file.
Why do you want to split the file across buckets?
Comment: Thank you for answer. Problem is I need to do that for my project. So would like to know how can I split the file in uploading or what is a way to split this to multiple storage
Comment: Use client-side file i/o to read the relevant portion of the source file and then write that using use boto3's put_object(ACL='private', Body=b'bytes', ...)
Comment: Thank you so much. Your comment was very helpful. Thank you again
Answer: Check this AWS documentation out. I think it would be useful.
http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadingObjects.html
The import part of the link is below:

Depending on the size of the data you are uploading, Amazon S3 offers the following options:

Upload objects in a single operation—With a single PUT operation, you can upload objects up to 5 GB in size.
For more information, see Uploading Objects in a Single Operation.
Upload objects in parts—Using the multipart upload API, you can upload large objects, up to 5 TB.
The multipart upload API is designed to improve the upload experience for larger objects. You can upload objects in parts. These object parts can be uploaded independently, in any order, and in parallel. You can use a multipart upload for objects from 5 MB to 5 TB in size. For more information, see Uploading Objects Using Multipart Upload API.
We recommend that you use multipart uploading in the following ways:
If you're uploading large objects over a stable high-bandwidth network, use multipart uploading to maximize the use of your available bandwidth by uploading object parts in parallel for multi-threaded performance.
If you're uploading over a spotty network, use multipart uploading to increase resiliency to network errors by avoiding upload restarts. When using multipart uploading, you need to retry uploading only parts that are interrupted during the upload. You don't need to restart uploading your object from the beginning.
For more information about mutipart uploads, see Multipart Upload Overview.
Comment: @Ivar Thanks! I didn't think of that, but you bring up a great point.
Comment: Multipart upload does not allow you to upload one source file and split it to multiple objects. It allows you to parallel upload parts of one source file to *one* object in S3.
Comment: @jarmod Thanks. What you said is very well true.
Comment: @Qaqa I don't think there's any limitation on buckets size. https://stackoverflow.com/questions/3980968/s3-limit-to-objects-in-a-bucket

python aws s3 file distributing


Rotman Algebraic Topology Exercise 1.14

Question: The question is

If CX is the cone of X, prove that $X \mapsto CX$ defines a functor $\text{Top} \to \text{Top}$  (the reader must define the behavior on morphisms) (Hint: Use Exercise 1.11)

I did exercise 11, and it says that if $f: X \to Y$ is continuous and respects an equivalence relation, i.e. if $X/\sim$, and $Y / \square$ are quotient spaces, $x \sim x'$, then $f(x) \square f(x')$. Then $f$ induces a continuous map $\bar{f}: X / \sim \to Y / \square$.
I see that if $f: X \to Y$, is continuous, then the functor $Tf: TX = CX \to TY = CY$ must be continuous. But I don't see how to do this since we don't know if the original function $f$ respects the equivalence relations.
Comment: Since the relation for forming a cone doesn't depend on anything about the spaces $X$ or $Y$, only the value of the variable on the interval, you are in.
Comment: That is clear now, thank you
Answer: It seems like the confusion comes from what $X$ and $Y$ are in exercise 11 vs the present exercise.  Given a continuous map $f:X\to Y$, you have an induced map $f':X\times I\to Y\times I$ defined by $f'(x,t)=(f(x),t)$, where $I=[0,1]$.  A cone $CX$ is a quotient of $X\times I$ by the relation $(x,1)\sim (x',1)$, for all $x,x'\in X$.  Similarly, $CY$ is $Y\times I$ by $(y,1)\mathbin{\square} (y',1)$, for all $y,y'\in Y$.
Notice that if $(x,t)\sim (x,t')$, then either $(x,t)=(x',t')$ or $t=t'=1$.  The second case is the more interesting one.  Since $f'(x,1)=(f(x),1)$ and $f'(x',1)=(f(x'),1)$, we have that $f'(x,1)\mathbin{\square} f'(x',1)$.  Paired with a similar statement for the first case, by exercise 11 there is an induced map $\overline{f'}:CX\to CY$.  Define $Tf$ to be this $\overline{f'}$.
Comment: Sorry, I left too much unsaid.  It's "induced" from $f$ and $\operatorname{id}_I:I\to I$ in the sense that $f'=f\times \operatorname{id}_I$ using the Cartesian product bifunctor.  I'm using "induced" to mean that it's defined from existing functions in some canonical way, but in the end it's just a function that's defined somehow.
Comment: Is there a difference between just defining a new function from one already defined and inducing a map? The terminology confuses me a bit.
Answer: Name the canonical projections by $\pi_1: X \rightarrow X/\sim$ and $\pi_2: Y \rightarrow Y/\square$.
To prove that $\bar{f}$ is continuous, by definition we need to check the preimage of any open sets in $Y/\square$ being open in $X/\sim$.
By the definition of quotient topology, we know all open sets $V$ in $Y/\square$ are exactly those sets whose preimages in $Y$ are open.
However, $\bar{f}^{-1}(V) = \pi_1(f^{-1}\circ \pi_2^{-1}(V))$, so by definition of the quotient topology of $X/\sim$, $\bar{f}^{-1}(V)$ is open. This proves your statement.
EDIT (for the comment. I am not able to comment before my reputation grows more than 50): from any $f^0: X\rightarrow Y$ you have a naturaly $:XxI \rightarrow YxI$. Then apply my argument above to this $f$.
Comment: Maybe you should be clear that by $X$ and $Y$ you mean $X\times[0,1]$ and $Y\times [0,1]$?
Comment: This was basically what I did for Exercise 1.11, but this doesn't help me define the functor for this exercise, which must map a morphism $f: X \to Y$ to a morphism $\bar{f}: X \times I / \sim \to Y \times I / \square$.

Rotman Algebraic Topology Exercise 1.14


Define image cropping in new image style

Question: When creating a new image style, is there a module which can let you define where to start the cropping? I think Drupal only crops from the very center. What if for this specific image I want the cropping to being from the top left? Or better yet, provide some gui which can let me crop the area manually like in fb.
Answer: There are many options to choose from in Drupal for image cropping. Here is a quick comparison.

EPSA Crop

Allows a user to choose coordinates for different presets on an image. If a user defines coordinates EPSACrop will override the Imagecache process and will set new coordinates.
Image Javascript Crop

With this one you define one or more presets in imagecache using the 'javascript crop" action, a new 'javascript crop' link appears underneath the image on the node edit screen, and the resulting popup window will display those presets. This screen shows the original image and initially applies the initial crop settings defined in the preset you select, e.g.: crop 50%-50%, center-center. However, you can then choose a different area of the original picture you want to crop, dragging an overlay box over the image, altering the size etc.
Imagefield Crop

When the user uploads an image, the image is presented inside a cropping area. A cropping box is shown inside, and the user can resize and move it. Upon clicking 'preview' or 'submit', the image is cropped and the result is saved instead of the original image.
Imagefield Focus

This module allows to scale and crop images focusing on their important portions.
Image Editor

Bring Photoshop-like functionality into your Drupal website! Create/edit any images online in the powerful and feature-rich image editors and save resulted images back to your site! This project integrates several popular online image editing services into Drupal:Pixlr editors: Pixlr Editor and Pixlr Express, Picnik, Simple HTML5 editor from Aviary: Aviary Feather, Advanced Aviary editors: Aviary Phoenix; Aviary Raven (vector editor - not working yet); Aviary Peacock; Aviary Falcon, Sumo Paint, FotoFlexer and Open-source HTML5 PaintWeb editor.
On a side note, (this is not what you were really asking, but) anyone coming to read this post looking for similar functionality directly in IMCE can use the IMCE Crop module which adds image cropping functionality to IMCE through its UI. And for kicks, if your looking for the ability for users to be able to do manual cropping on their avatars, use Avatar Crop. Or just to force Image presets on Avatars, use Image Cache Profiles.
Manual Crop
Comment: Much better answer than mine.
Comment: nah. u got the ball rolling. :)
Comment: Wooooow! So many modules to choose from yet so little time. Where to begin?
Comment: I personally, try to keep it simple as possible, while still keeping the images on my sites consistent. If you are going to have a ton of end users trying to upload images, use Imagefield Focus. If you need power, flexibility and all-round coolness, go with Image Editor. That being said, each site is different and I would evaluate each one at the time I implement it.
Answer: You mean like image field crop


Erro ao instalar API goslate para python em Windows

Question: Estou obtendo esse resultado quando tento instalar a API goslate, que é uma Api do Google mais otimizada pra mexer com traduções e outras coisas mais.
C:\Users\chris\Documents\PyCharm Projects\Integrador\goslate-1.5.1>py setup.py install
Traceback (most recent call last):
  File "setup.py", line 8, in <module>
      import goslate as module
  File "C:\Users\chris\Documents\PyCharm Projects\Integrador\goslate-1.5.1\goslate.py", line 33, in <module>
      import concurrent.futures
  File "C:\Users\chris\AppData\Local\Programs\Python\Python35-32\lib\site-packages\futures-3.0.3-py3.5.egg\concurrent\futures\__init__.py", line 8, in <module>
      from concurrent.futures._base import (FIRST_COMPLETED,
  File "C:\Users\chris\AppData\Local\Programs\Python\Python35-32\lib\site-packages\futures-3.0.3-py3.5.egg\concurrent\futures\_base.py", line 355
      raise type(self._exception), self._exception, self._traceback
                                 ^
SyntaxError: invalid syntax

Parece que está dando um problema no módulo futures, e eu já até baixei essa lib futures mais recente e a instalei tranquilamente, só que não adiantou de nada.
Pergunta
Alguém sabe o que posso fazer para solucionar esse problema?
P.S. Estou utilizando python versão 3.5.1
Comment: Tentou fazer a instalação no Python 2.7 ?
Comment: @DenerCarvalho, goslate diz que é compatível com 3.4+.
Comment: Como vc esta fazendo a instalação?
Comment: Eu preciso fazer isso no Python mais recente por conta de outros recursos do meu trabalho. A instalação é justamente o que está aí baixei o arquivo e fui instalá-lo. Goslate é compatível, só esse problema no `future` que tá atrasando o negócio.
Answer: Como é possível ver nessa issue do repositório da futures, o futures é um módulo feito pra programas da versão 2.x serem compatíveis com features da versão 3.x, então não faz muito sentido instalar o módulo future para as versões 3.x.
Logo, caso desinstalar a futures deve resolver o seu problema.
Outro adição é que, talvez, seja mais simples usar o pip para instalar esses pacotes.
Comment: Ok cara, desistalei tudo aqui e fiz pelo `pip` e funcionou certinho. Valeu!


What is the strongest known proxi-finite theory?

Question: [NEWEST EDIT] This a try to salvage this method, addressing the two objections that was raised by Noah. So I'll re-exposite this approach:
EXPOSITION
A theory $T$ is to be labeled as "proxi-finite" (i.e. in proximity with the world $HF$ of all well founded hereditarily finite sets) if and only if each axiom of $T$ OTHER than the axioms needed to define $V$ (the class of all sets) and $HF$ which are Extensionality, Class comprehension (of MK), empty set, closure of $V$ under singleton and Boolean union, and of course Infinity; must satisfy the following two conditions:

Is of form $\psi^V$, where $\psi^V$ is a sentence obtained by bounding by $V$  of all quantifiers in an unbounded first order set theoretic sentence $\psi$, using bounding relation symbols $\in, \subseteq$; and each variable in $\psi$ must be written as $x_i$, where $i$ is the order of quantification of that variable in $\psi$; such that for every subformula $\phi$ of $\psi$, the following is provable from the rest of axioms of $T$:

$$\phi^{*^V} \to \phi^{*^{HF}}$$
Where $\phi^{*^X}$ is the sentence defined as:
$$[\mathcal Q_1 x_{i_1} \ b_1 \ X ,...,\mathcal Q_n x_{i_n} \ b_n \ X  (\phi)] $$
where $i_j = 1,..,k$, for $j=1,..,n$; where $k$ is the total number of variables in $\psi$. Now $n$ is the total number of free variables in $\phi$. Each $\mathcal Q_i$ is a quantifier symbol, i.e. either $\forall$ or $\exists$; and each $b_i$ is a bounding relation symbol which is either $\in$ or $\subseteq$; the string $x_{i_1},..,x_{i_n}$ is the string of all free variables appearing in $\phi$ ordered after their quantificational sequence in $\psi$;  that is: $j<l$ if and only if $i_j < i_l$  . Also we must have each $\mathcal Q_j x_{i_j} \ b_j \ X$ being the same as how it appears in $\psi$; more precisely: each $\mathcal Q_j x_{i_j} \ b_j \ X $ in $\phi^{*^X}$ is exactly the same as $\mathcal Q_m x_m \ b_m  \ X$ in $\psi^X$ if $i_j=m$.

$\psi^{HF} \to \psi^V $ is not provable from the rest of axioms of $T$.

I think the above can be simplified if we require $\psi$ to be in prenex normal form; now for any subformula $\phi$ of the matrix of $\psi$, we can easily define the sentence $\phi^*$ as $\phi$ preceded by the string of quantifiers over all free variables in $\phi$ that is a substring of the prefix of $\psi$.
Also I think we can change the second requirement to demand that $\psi^{HF}$ is provable from the basic sub-theory of $T$ that defined the world of hereditarily finite sets.
To show how this blocks the earlier trivialities. lets take $\psi$ to be the formula $``\forall x (finite(x)) \lor \theta"$ where $\theta$ is any axiom that is consistent with $ZF$ but false in $HF$. What happened in the earlier attempt which only demanded $\psi^V \to \psi^{HF}$ is that $\psi$ is "trivially" true of the hereditarily finite set world, this came to effect through bounding the quantifiers in the first subformula $\forall x (finite(x))$ by $HF$, but when generalized over the whole set world $V$, it was true because of $\theta$ and not because of the first subformula, actually the first subformula was false in $V$. Such an argument would be blocked here because $\theta$ is true in $V$ but not in $HF$.
To show that it blocks the un-limited consistency strength argument, we'll see that any arithmetical formula $p$ is bounded by the predicate $natural \ number$, which would bypass the first requirement above, but not the second requirement! Also it doesn't bypass the alternative form of the second requirement.

[EDIT] since the line of thought presented below did fail as Noah showed. I think its time to present it informally. What I'm seeing is that known theories like ZFC and MK are what I would label here informally as proxi-finite, this means that all of its axioms other than infinity are rules coming from the well founded hereditarily finite set world, i.e. $V_\omega$. I tried to define that by requiring that those axioms be of the form $\psi^V$ such that $\psi^V \to \psi^{HF}$; unfortunately that failed. However, the informal idea is there, even though it badly fails formally, for example an axiom saying that every set having many members, there is a set whose cardinality is strictly bigger than the cardinality of it and strictly smaller than that of its power. However, we can trivially also arrange for the opposite of that by having the formula "every set is finite or the negation of the above statement", and this would work to the opposite of what is intended. I think there must be some formal technique that ensure our informal notion. As examples :the general violation of the continuum hypothesis (for many membered sets) is proxi-finite, while the generalized continuum hypothesis is NOT. There are many other possible extensions of the former that are also proxi-finite. Also Choice is proxi-finite, while its negation is not.

This is the older post:
Let's label a theory $T$ as proxi-finite (i.e. in proximity with the world $HF$ of all well founded hereditarily finite sets) if and only if every axiom of $T$ other than the axiom of infinity is of the form $\psi^V$, that is a sentence that is $\in, \subset$-bounded by the class $V$ of all sets, such that: $$\psi^V \to \psi^{HF}$$
where $\psi$ is an sentence in the language of set theory, and $\psi^b$ is the formula obtained by merely $\in or \subset$ bounding every quantifier in $\psi$ by the set $b$.
For example Morse-kelley set theory is proxi-finite!

What is the strongest known proxi-finite theory?
Is there a limit to the consistency strength of proxi-finite theories?

Proxi-finite theories can be very strong! For example take MK and add to it the failure of the continuum hypothesis for all sets having many members. Which goes way beyond measurable cardinals! Yet I'm not sure if this is the furthest one can go? I suspect not!
Comment: What you're essentially asking is "what is the largest large cardinal", to which there is no reasonable answer. If $\varphi$ is the largest definition, then $\kappa$ is an inaccessible such that $V_\kappa$ satisfies that there is a proper class of cardinals satisfying $\varphi$ is stronger. You can also move from proper class to stationary class, etc. etc.
Comment: @AsafKaragila do you mean that the answer to the second question is NO. But what's the answer to the FIRST question? What's the strongest KNOWN proxi-finite theory? I suspect that not all large cardinal axioms are formulated in proxi-finite theories? No?
Answer: There is no limit to the consistency strength of proxi-finite theories. If $T$ is a proxi-finite theory capable of talking about HF in an appropriate way - say, $T=$ MK for massive overkill - then $T+p$ is also proxi-finite for any arithmetical sentence$^1$ $p$. So just take $p=Con(S)$ for your favorite theory $S$. E.g. the theory $$\mbox{MK + Con("ZF + "There is a Reinhardt cardinal"")}$$ is proxi-finite, and has the same consistency strength as ZF + "There is a Reinhardt cardinal."
Note that whether or not $S$ is proxi-finite doesn't enter into the proxi-finiteness of $T+Con(S)$.

$^1$Or more precisely, the appropriate reformulation of an arithmetical sentence in the language of set theory; the "appropriate way" bit in the first half of that sentence is just to ensure that such reformulation can be done.
Comment: what is the proof that the sentence "There is a Reinhardt cardinal" fulfills the implication in the definition of proxi-finite theories.
Comment: @Zuhair It doesn't; I've fixed it. Per the prior sentence, the point is to look at *consistency statements*.
Comment: I remember from a discussion with Rupert, him saying that the consistency statement is NOT at the same strength as the assertion of existence of the large cardinal.
Comment: I need to understand why the consistency statements can be reformulated in such a manner as to fulfill the implication in the definition of proxi-finite theories? An example would help!
Comment: $(\exists x (x=x+1))$; $(\exists x (x> 1 \wedge \not \exists k (x < k < 2^x)))$ are arithmetical statements, yet ZFC + the second statement is not a proxi-finite theory?
Comment: @Zuhair "the consistency statement is NOT at the same strength as the assertion of existence of the large cardinal" Yes, but you asked about consistency strength, not existence ("Is there a limit to the **consistency strength** of proxi-finite theories?") If you want to ask about large cardinal existence principles, then ask that instead.
Comment: As to your second comment, those **are not** arithmetical statements. An arithmetical statement $\varphi$ is *relativized to $\mathbb{N}$* (which doesn't contradict the requirement that the axiom be relativized to $V$ - we can always relativize further), so that $\varphi,\varphi^V$, and $\varphi^{HF}$ are all equivalent.
Comment: but by then $p$ won't satisfy my conditions, since $p$ won't be of the form $\psi^V$.  If you meant by $p$ a formula of the form $\psi^V$ but by replacing each occurrence of $V$ by $\mathbb N$ we get an arithmetical sentence, then the same would be of my formula that I've mentioned in the comment (consider all variables in it bounded in $V$). Notice that $\psi$ in my requirement is ***unbounded*** sentence.
Comment: @Zuhair How precisely do you define "unbounded sentence," given that we can always "push the bounding in" (e.g. "$\forall x\in y(P(x))$" is equivalent to "$\forall x(x\in y\rightarrow P(x))$," which only uses unbounded quantifiers)? Are you going to just forbid any sentence of the form "$\forall x(P(x)\rightarrow Q(x))$" or similar? Until you precisely define this restriction, I don't think this question can be answered, and frankly I don't see any approach which isn't extremely ad-hoc.
Comment: OK, there is no need for $\psi$ to be unbounded since this can be circumvented as you alluded to.  But the axiom must be a formula in the language of set theory and the symbol $V$ allowed in binding the quantifiers only. And when you replace $V$ by $HF$ then the implication given above should stand true. Can the arithmetical formulas do that, you need to replace $\mathbb N$ by its defining formula, and all quantifiers in those must be bounded by $V$, now if you replace $V$ by $HF$ would the implication above still holds? I checked it! We can make it hold. So basically your answer is correct!
Comment: However, the first question, which is about existence of large cardinals extending ZFC in a proxi-finite manner, is not yet solved?
Comment: @Zuhair That can be solved similarly: given a large cardinal axiom $\theta$, consider the sentence "either there is no infinite set, or $\theta$" - the relativization of this to HF is trivially satisfied.
Comment: Yes you are right! this method fails.


Accidentals should apply to both clefs? Chopin Op. 9 No. 2 Measure 13

Question: It's my understanding that any accidental showing on the treble clef also applies to the bass clef unless indicated otherwise, correct?
For measure 13 of Chopin Nocturne Op. 9 No. 2, my Henle Verlag urtext (the image here is from a video but has the same notes as my Henle book) shows the natural sign for the note A in the treble clef, and no accidental shown in the bass clef. Shouldn't the left hand play the natural A, too? But I watched three videos and they all played Ab on left hand. (One video by Paul Barton used a score that has a flat sign next to the 2nd occurence of the A note in bass clef, but he played both A as Ab.)
Having said the above, I would tend to play Ab on left hand, too, since up to that part all the previous cases of the same chord combination had Ab. However, the Henle truly didn't have the flat symbol in the bass clef.
(Maybe it's no big deal? am I being too pedantic? ;-))
Answer: Accidentals apply only to the specific line or space on which they appear. For example, an A above the treble staff would also be an Ab unless specifically marked otherwise.
See Does an accidental apply to all octaves?.
Comment: @GrandAdagio Bar lines cancel any accidentals that appear in the preceding measure.
Comment: Aaron, in this late version he corrected that: at 1:40 https://www.youtube.com/watch?v=O-0Gjl7oF5A
Comment: The rules are quite simple - *accidentals* (not key sigs) refer only to the notes that follow them, and they only last for the bar they're written in!
Comment: Oh, thank you! I don't know how I got that mistaken impression! By the way, that Paul Barton played B-natural for the 2nd B on left hand (the bottom note of the blue arrow chord), which I think is wrong?
Comment: @GrandAdagio Based on the edition you posted, yes, Bb would be wrong. It's possible, however, that Barton simply chose to alter that pitch, because it gives a nice color to the harmony. Whether he's using a different edition, just decided on his own to make the change, or simply hit the wrong note I can't say, but I like the sound.
Comment: Seems not, see at 1:49  https://www.youtube.com/watch?v=rlqCEu_4oJA
Comment: @GrandAdagio Yeah, playing B-natural on the other Bs would definitely be wrong.
Comment: Aaron, at the link your provided in the answer, I don't understand why the last F is F natural. Shouldn't it follow the previous sharp accidental on the same line/level?
Comment: Oh, right! So many rules to remember :). Thanks!
Comment: Thanks. I think I confused it with the rules for key signatures.


Packed 3D vector float points into unsigned int and unpacked it

Question: GetPacked will pack a 3D point into an unsigned int. I want to unpack it back to point, but not work. Help please
uint32_t GetPacked(float x, float y, float z)
{
    return ( 0xff000000
        | ( ( uint32_t ) ( ( x * 127.5f ) + 127.5f ) << 16 )
        | ( ( uint32_t ) ( ( y * 127.5f ) + 127.5f ) << 8 )
        | ( ( uint32_t ) ( ( z * 127.5f ) + 127.5f ) ) );
}

// buggy unpacked
void UnPacked(uint32_t p, float* _x, float* _y, float* _z)
{
    *_z = ( ( p & 0xff ) - 127.5f) / 127.5f;
    p >>= 8;
    *_y = ( ( ( p ) & 0xff ) - 127.5f) / 127.5f;
    p >>= 8;
    *_x = ( ( ( p ) & 0xff ) - 127.5f) / 127.5f;
}

thanks
PS: I created an online test in ideone
Answer: You will loose the precision.
// a, b, b in the range of -127.5 +127.5

uint32_t Code(float a, float b, float c)
{
    union
    {
        uint32_t u32;
        uint8_t u8[4];
    } u;

    u.u8[3] = 0xff;
    u.u8[0] = a + 127.5f;
    u.u8[1] = b + 127.5f;
    u.u8[2] = c + 127.5f;

    return u.u32;
}

void DeCode(uint32_t u32, float *a, float *b, float *c)
{
    union
    {
        uint32_t u32;
        uint8_t u8[4];
    } u;

    u.u32 = u32;
    *a = (float)u.u8[0] - 127.5f;
    *b = (float)u.u8[1] - 127.5f;
    *c = (float)u.u8[2] - 127.5f;
}

int main(void)
{
    float a = 102.3f, b = -56.4f, c = -126f, d,e,f;

    uint32_t coded = Code(a, b, c);
    DeCode(coded, &d, &e, &f);

    printf("Original values: %f,%f,%f. Coded -%x. Decoded %f,%f,%f\n", a, b, c, coded, d, e, f);
}

For the better precision you may scale it to the 10 bits.
#define B10MAX      ((float)((1u << 10) - 1))
float Scale(float x)
{
    return B10MAX * (x + 127.5f) / 255.0f;
}

float DeScale(unsigned x)
{
    return 255.0f *(x) / B10MAX - 127.5f;
}

uint32_t Code10(float a, float b, float c)
{
    union
    {
        uint32_t u32;
        struct
        {
            uint32_t value1 : 10;
            uint32_t value2 : 10;
            uint32_t value3 : 10;
        };
    } u;

    u.value1 = Scale(a);
    u.value2 = Scale(b);
    u.value3 = Scale(c);

    return u.u32;
}

void DeCode10(uint32_t v, float *a, float *b, float *c)
{
    union
    {
        uint32_t u32;
        struct
        {
            uint32_t value1 : 10;
            uint32_t value2 : 10;
            uint32_t value3 : 10;
        };
    } u = {.u32 = v,};

    *a = DeScale(u.value1);
    *b = DeScale(u.value2);
    *c = DeScale(u.value3);
}

and in the main
coded = Code10(a, b, c);
DeCode10(coded, &d, &e, &f);

printf("Original values: %f,%f,%f. Coded = %x. Decoded %f,%f,%f\n", a, b, c, coded, d, e, f);


We repeatedly toss a fair coin until we see 'heads'. Let X be the number of tosses we need. Compute the probability that X is a multiple of 3.

Question: I'm given the problem

We repeatedly toss a fair coin until we see 'heads'. Let X be the number of tosses we need. Compute the probability that X is a multiple of 3.

I did find a solution to this problem, shown below, that uses an infinite sum.
I was wondering if there was a solution where no knowledge of infinite sums is required.

This was my solution:
The probability that X is a multiple of 3 is equal to the probability that heads lands first on the 3rd throw + the probability that heads lands first on the 6th throw etc.
This is equal to $\sum_{n=1}^{\infty} \frac{1}{2^{3n}}$. As this is a geometric series with ratio equal to 1/8 this sum is equal to (1/8)/(7/8) = 1/7.
Comment: This is a copy of your homework. But what is your question?
Comment: Hints: what is the probability you get at least one heads in the first three tosses?  What is the probability that the first time you get heads is the third toss?
Comment: I've edited your question to better emphasize the question you're asking. Also, I've formatted the sum you were writing; if you edit your post again you can see how to do the formatting yourself.
Answer:
I was wondering if there was a solution where no knowledge of infinite sums is required.

There is actually a way to solve this pretending no infinite series is involved, but, IMHO, this is more hiding the series under the rug than really avoiding it.
Anyway, simply note that, if $3$ divides $X$, then:

either $X=3$, when the three first results are tails, tails, heads, which happens with probability $\frac18$,
or $X=3+X'$, when the three first results are tails, tails, tails, which happens with probability $\frac18$, and then $X'$ denotes the first time one sees heads in the sequence of tosses starting at the fourth toss, and one demands that $3$ divides $X'$.

Thus, $$P(3\text{ divides }X)=\frac18+\frac18P(3\text{ divides }X')$$ Furthermore, $$P(3\text{ divides }X')=P(3\text{ divides }X)$$ hence $$P(3\text{ divides }X)=\frac{\frac18}{1-\frac18}=\frac17$$

We repeatedly toss a fair coin until we see ‘heads’. Let X be the number of tosses we need. Compute the probability that X is a multiple of 3.


Computing Sampling Cost Tradeoff

Question: I'm working with a Bayesian Optimization problem where the accuracy of sampled data varies based on sampling cost (low-uncertainty data is expensive, high-uncertainty data is cheap).
What kinds of approaches are there for quantifying this trade-off, and making decisions about what is the best balance between sampling cost and data accuracy? And what is the name/term for this kind of analysis? I'm not familiar with this topic so I don't know what to search for.
Answer: This idea of using multiple fidelities(low-uncertainty vs high-uncertainty) data within Bayesian optimization is an area of active research. There are multiple ways of incorporating this information. If you are aware of basic bayesian optimization terminology, it can be incorporated in following ways:

To pick the next point for evaluation during acquisition function optimization.
By modeling directly in the surrogate model(gaussian process).

Some related literature is below:
https://papers.nips.cc/paper/6118-gaussian-process-bandit-optimisation-with-multi-fidelity-evaluations.pdf
https://arxiv.org/pdf/1807.01774.pdf
Both of them has source code available too.

Computing Sampling Cost Tradeoff


Combine two data sets from two different regions

Question: This is a actually very basic question, but I can't get my head around it.
I have two datasets for Europe and U.S. that contain the same two variables. These two variables are in a linear relationsship, which I proved by statistical t-testing.
Now I want to check if the two regional differentiated data sets can be combined and are in fact based upon one mechanism.
Should I simply combine the data, implement a new linear relationsship and t-test the entirety again on statistical signifance? Or is there a other way?
Best!
Answer: I assume you used a simple linear regression model to estimate the association between these two variables. Now technically, you can append data sets from two different regions but you need to be careful. Does it make sense to combine them, theoretically? (e.g., Europe is a continent, U.S. is a country). Let's say it does (we need to know more about your analysis to make a better judgment), then you could create an indicator variable for each data set. We can call this variable region, or something else, and it will have two categories (Europe and the U.S.). You can include this variable in your regression model as a dummy indicator. That way, you could hope to adjust for the region effect in your multiple regression model.


VLAs when compiling a C++ source with g++

Question: I understand that VLAs are part of C99 but not C++0x.  My question is then why and how g++ would compile code with VLAs.  I wrote a test case below:
test.c
#include "stdio.h"

int main(int argc, char *argv[]) {
    int i;
    int array[argc];

    for(i = 0; i < argc; i++)
        array[i] = i;

    for (i = 0; i < argc; i++)
        printf("%d ", i);
    puts("");

    return 0;
}

I also copied it into a file called test.cpp.  The following all compile:
$ gcc test.c -o test                 // expected
$ g++ test.cpp -o test               // not expected
$ g++ test.cpp -o test -x c++        // really not expected
$ g++ test.cpp -o test -std=c++11    // really not expected

I have read the SO questions Variable length arrays in C++? and What is the difference between g++ and gcc? but I cannot find an answer as to why g++ would do this or how it does. This seems like extremely unpredictable behavior as the standard specifies no VLAs. Does g++ recognize this as C code and compile with cc1? Is there a way to force g++ to stick to the standard?
Additionally, I can break it with the following:
test2.cpp
#include "stdio.h"
#include <vector>

int main(int argc, char *argv[]) {
    int i;
    int array[argc];

    for(i = 0; i < argc; i++)
        array[i] = i;

    for (i = 0; i < argc; i++)
        printf("%d ", i);
    puts("");

    std::vector<decltype(array)> temp;

    return 0;
}

Which then fails to compile:
$ g++ test2.cpp -o test2 -std=c++11
test2.cpp: In function 'int main(int, char**)':
test2.cpp:16:32: error: 'int [(((sizetype)(((ssizetype)argc) + -1)) + 1)]' is a variably modified type
     std::vector<decltype(array)> temp;
                                ^
test2.cpp:16:32: error:   trying to instantiate 'template<class> class std::allocator'
test2.cpp:16:32: error: template argument 2 is invalid
test2.cpp:16:38: error: invalid type in declaration before ';' token
     std::vector<decltype(array)> temp;

This error appears to mean that I am still allowed to declare VLAs, I just can't have them as an argument to decaltype. This makes everything seem much stranger. I can understand the obvious answer of, "It's wrong, so just don't do it" or, "if you're using C++, use std::vector" but that seems like an end-game type of answer and doesn't quite get to the root of the issue.
I cannot compile on Visual Studios to compare as I do not currently have access to it.
System information in case that is the difference:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)

Comment: Compile with `-pedantic` and you'll get a warning. By default, GCC allows them.
Comment: Compilers typically implement a whole bunch of extensions, you have to tell it not to if you don't want them. And even then you get some anyway; the standard usually specifies a minimum set of behaviour.
Comment: Are you asking how GCC implements its VLA extension? Or?
Comment: @LightnessRacesinOrbit he's asking why g++ does not reject the code containing VLA
Comment: @Matt McNabb That's what I was looking for, thank you! Standards are minimums and this functionality is due to an extension.
Answer: VLAs are a gcc (and clang) compiler extension in C++ mode, documented here. These extensions are enabled by default.
You should see a warning if you compile with -pedantic.
Funnily, you will not with gcc4.9 and -std=c++14 or -std=c++1y. As they explain here, they removed the -Wvla warning in C++14 mode because VLAs were once in the draft for the standard. They did not actually make it in the final version of C++14.
clang still warns in C++14 mode, as it should.
Edit: gcc 5.1 warns in C++14 mode too, so that got updated correctly.
Comment: Thank you for the link to the documentation! This explains everything listed in the comments above.
Comment: A small update to this answer: VLAs didn't make it to C++17, after all.


Integrating the fractional Laplacian over $\Omega$

Question: Let $\Omega$ be a bounded regular open subset of $\mathbb{R}^N$, $N\geq 1$.
I want to know if this statement is true : for $u\geq 0$ in $\Omega$, and $u=0$ in $\mathbb{R}^N\setminus \Omega$,
$$
\int_\Omega (-\Delta)^s u(x) dx\geq 0.
$$
I reasoned by the fact that, for $s\in (0,1)$,
$$
\int_\Omega (-\Delta)^s u(x) dx=\int_\Omega P.V.\int_{\mathbb{R}^N} \frac{u(x)-u(y)}{|x-y|^{N+2s}} dy dx \geq \int_\Omega P.V.\int_{\mathbb{R}^N\setminus \Omega} \frac{u(x)-u(y)}{|x-y|^{N+2s}} dy dx = \int_\Omega P.V.\int_{\mathbb{R}^N\setminus \Omega} \frac{u(x)}{|x-y|^{N+2s}} dy dx\geq 0,
$$
as  $u=0$ in $\mathbb{R}^N\setminus \Omega$.
Am I correct?
Thank you in advance for your help.
Answer: Yes, the result is true and your proof is correct, but the first inequality you have is actually an equality. Let $u\in C^2(\Omega)\cap L^\infty(\mathbb R^n)$. You write $$\int_\Omega \int_{\mathbb R^n} \frac{u(x)-u(y)}{\vert x - y \vert^{n+2s} } \, dy dx \geqslant \int_\Omega \int_{\mathbb R^n \setminus\Omega} \frac{u(x)-u(y)}{\vert x - y \vert^{n+2s} } \, dy dx $$ which is equivalent to the inequality $$\int_\Omega \int_{\Omega} \frac{u(x)-u(y)}{\vert x - y \vert^{n+2s} } \, dy dx \geqslant 0. $$ This is true, but actually $$\int_\Omega \int_{\Omega} \frac{u(x)-u(y)}{\vert x - y \vert^{n+2s} } \, dy dx = -\int_\Omega \int_{\Omega} \frac{u(y)-u(x)}{\vert y - x \vert^{n+2s} } \, dy dx = -\int_\Omega \int_{\Omega} \frac{u(\tilde x)-u(\tilde y)}{\vert \tilde x - \tilde y \vert^{n+2s} } \, d\tilde y d\tilde x$$ by making the change of coordinates $\tilde x =y$ and $\tilde y =x$, so actually $$ \int_\Omega \int_{\Omega} \frac{u(x)-u(y)}{\vert x - y \vert^{n+2s} } \, dy dx =0.$$ Thus, $$\int_\Omega (-\Delta)^s u(x) \, dx = \int_\Omega \int_{\mathbb R^n \setminus \Omega} \frac{u(x)-u(y)}{\vert x - y \vert^{n+2s}}\,dydx, \tag{$\ast$}$$ so for $u=0$ in $\mathbb R^n\setminus \Omega$ and $u \geqslant 0$ in $\Omega$, the result follows exactly as you said.

As a fun side note, often we define $$ \mathcal N_s u(x) = \int_\Omega \frac{u(x)-u(y)}{\vert x - y \vert^{n+2s}}\, dy$$ which is a sort of fractional Neumann derivative. Then $(\ast)$ can be rewritten as $$\int_\Omega (-\Delta)^s u(x) \, dx = -\int_{\mathbb R^n \setminus \Omega} \mathcal N_su(x)\, dx $$ which is a nonlocal analogue of the identity $$\int_\Omega \Delta u \, dx = \int_{\partial \Omega} \partial_\nu u \, \mathcal H^{n-1}_x, $$ see Nonlocal problems with Neumann boundary conditions by Dipierro, Ros-Oton, and Valdinoci.
Comment: Thank you for your help!


music publishing: Old notation vs modern notation

Question: At some point old notation gave way to new notation.
The unit note of contemporary music is the Semibreve, and the half note, the Minim.  Both words mean short (and shorter) time duration.
Early music had: the Long, the Breve, and the Semibreve.
The Semibreve being the shortest note, whereas now it is the longest.
Both systems were binary: ie each succeeding note was half the preceding note.
My theory is this:
With the invention of movable type used in printing presses the dies for the Long, the Breve, and the Semibreve would have become clogged with ink very frequently.  Far better to have dies with solid surfaces like the Crotchets, Quavers, and Semiquavers etc., with only the occasional Minim and Semibreve.
In short, has the change from long notation to short notation been precipitated by the invention of the printing press?
Or is there another explanation for the change in notation?
Comment: I strongly doubt printing processes have anything to do with it. In fact I was under the impression that hand-copying was still the dominant means of score reproduction well into the classical period, long after the new notation took over; but coming to think of it I actually don't know about the timeline of printing for musical scores, so I could be completely off here.
Comment: I was about to write an answer along the lines of @leftaroundabout's comment, when I found [this Wikipedia article](https://en.m.wikipedia.org/wiki/History_of_music_publishing) which details a *much* earlier timeline than I thought. I don't know whether its sources check out but it seems quite plausible. Interesting question!
Comment: @leftroundabout movable-type printing flourished in Italy in the 16th century and into the 17th.  Lots of music survives only in that form.  More pieces were probably copied by hand, since any music that didn't appeal to the mass market would not have been printed.  But my understanding is that the technical circumstance that led to the popularity of open "white" notes in the first place was the switch from parchment and vellum to paper.
Answer: I believe that the transition to shorter notes came in mid-16th century Italy, with the development of the note nere (literally "black note") style of madrigal. In addition to using shorter note durations, note nere madrigals also replaced the use of the slashed-C time signature (alla breve) with an open-C. In theory, this should have resulted in halving the tempo, thus cancelling out the shorter note values, in which case, note nere would only be a notational convention. While this doesn't seem to have totally been the case; it appears that musicologists are uncertain of the exact stylistic implications of this change, much less the reasons behind it. For reference, I found the first page of a 1965 article, The Note Nere Madrigal by James Haar, which states "the line between notational fad and stylistic advance is doubtless a thin one." Unfortunately, I don't have access to the full paper, so I can't see where the author ultimately draws that line. Nor do I know how far modern historical research has gone since then.
Answer: Chant (from around the time of Guido if not before) used solid head notes, so I don't think the solid-open head means anything other than notationally. The linked paper suggests that solid notes became open to make it easier to notate by pen (which begs the question of why new solid but flagged notes developped) https://www.thelantern.com/2015/09/professor-breaks-down-history-of-music-notation/.
I would guess that the Gregorian notation was adapted to other uses then extended to make longer notes by using open notes and shorter durations by flagging (the eighth note had a flag.) Some open note stuff showed 3 vs 2 divisions by using several notes before and after a given note to give the length. More information here: http://www.thisisgabes.com/images/docs/musicsymbol.pdf
Carl Parrish's book, "The Notation of Medieval Music," discusses notation up to the 1500s. I didn't find much about why composers (printers or copiers actually) changed the "default" note durations. Of course, one can use anything for duration. Old tango and swing notation was in 2/4 with an eighth note pulse; more recent composers and arrangers prefer 4/4 markings with a quarter note pulse. I've seen waltzes written 3/4 and 3/8; those in 3/8 seem to me to be faster. This is probably a hold over from mensural notation in which note values and time signatures indicated tempo value. Dolmestch online suggests that musical styles used faster notes (perhaps improvements in instrument construction) so the breve got slower. https://www.dolmetsch.com/musictheory2.htm
Comment: Flags originally made notes longer, not shorter (that is, the longa has a flag while the breve does not).
Comment: The longa has a *stem*.but not a flag. Likewise the maxima (which is distinguished by its open head being longer).
Answer: Prior to Gutenberg, open head notes were used for other purposes.  We weren't using bar lines (or time signatures) as a standard for marking meters.  The precursors of bar lines were actually used to denote rests, with the length of the line determining the number of rest beats.  Meters were noted by "colorization", with open head notes indicating duple meter and solid note note heads triple meter.
There were significant variations in notation geographically, and even where handwritten notation was identical there were significant variations in the interpretation of the notation - the "Italian" style was binary, while the "French" style was ternary (similar to modern "swing").
The development of the printing press didn't lead to changes in notation - it lead to the opposite, the fixing of notation in a standard form.  Music notation adapted to what was readily available for notation: Once you have a cast for a symbol, why spend the time developing another one for the same concept? (This is also seen today, with software like Finale and Sibelius leading to more standardization in chord symbols).
And the clogging of type was definitely not a factor.  If you've ever visited a print shop in a historical setting you might have witnessed the regular cleaning of the form with brushes.  Ink is generally sticky stuff, and as the form (the type locked in the chase) collected dust and dirt, ALL of the type surfaces became fuzzy in the transfer of images to the page.
While that's going to happen faster with open symbols, in the context of your hypothesis it's important to realize that the bulk of printing wasn't music - it was text.  We did not alter the symbols for all of the letters with closed loops (abdegopq)... we developed the habit of regularly cleaning the printing form.  By the time we started printing music we had already been printing text for about 20 years, so printing open headed notes was no more difficult than printing p's and q's.
Answer: Each language/notation system provides a fluency but also imposes limitations on the expression of creative ideas. Our current (Western) music notation system is based on an archaic modal framework. Accidentals were added later, to accommodate an expanded chromatic pitch system. Temperament methods (n-limit just intonations, meantone, equal temperament, etc) were then added to accommodate tonal modulation and harmonic intonation within a chromatic system.
In many cases, notation (symbol) evolutions are a secondary effect of advances in theoretical terminology (nomenclature). Pitch (note) duration terminology has evolved in specificity from indirect, esoteric and cumbersome terms (crotchet; hemidemisemiquaver) to simpler quantified terms (quarter note/rest; 64th note/rest). By indirect, I mean note definitions like: "the value of a quaver is one eighth of a semibreve, or half of a crotchet". Direct terminology skips the step of esoteric translation: the value of an quarter note is 1/4 of a whole note, 1/2 of a half note; the eighth note is half of a quarter note, etc.
As musical languages continue to evolve, the larger problem becomes: how much longer can 'bolt-on' expansions to a simple modal (7 pitch per octave; A-G) notation and theoretical framework suffice. One modern example is microtonal (>12 pitches per octave) music, which is pushing modal notation and modal intervallic theory to its endpoint. As a result, we see an increasing notation 'discordance' in the continuing invention of numerous, incompatible pitch-modifier symbols (accidentals) necessary to notate musical ideas beyond the limits of a chromatic (12 pitch per octave) system.
Pitch (note) duration terminology has been updated to the modern era in its  quantitative basis. It has a dual complexity in notating a wide array of simplified, absolutely-defined duration relationships (half note=2 quarter notes), as well as symbolizing a contextually adaptive structure: accommodating flexible variances in the temporal duration of a quarter note (in seconds), relative to tempo or pulse. However, the underlying modal system and theoretical framework of music is proving to be much more resistant to modern evolution.


Symmetric matrix $S$ with collapsed eignevalues $\lambda_i=\alpha$ implies $S=\alpha I$.

Question: Suppose we have a symmetric $n \times n$ matrix $S$ whose eigenvalues all collapse to a single eigenvalue $\alpha$. Show that $S = \alpha I$.
From this it is clear that the characteristic equation must be $(\lambda - \alpha)^n$ and it's easy to see that $S = \alpha I$ fits the bill here but I can't seem to show why it does so necessarily?
Answer: Every real-symmetric matrix is diagonalizable. Since our matrix $S$ has only one eigenvalue $\alpha$, this implies that there exists an invertible matrix $P$ such that
$$
S=P(\alpha I)P^{-1}=\alpha\cdot P\cdot I\cdot P^{-1}=\alpha\cdot P\cdot P^{-1}=\alpha\cdot I
$$


How to delete object which is connected to another model with FK. ASP.NET Core MVC

Question: There is the error: The DELETE statement conflicted with the REFERENCE constraint "FK_ShoppingCartItems_ItemsTable_ItemId". The conflict occurred in database "RandDb", table "dbo.ShoppingCartItems", column 'ItemId'. The statement has been terminated.
Item
public class Item : BaseEntity
    {
        [Required]
        [Display(Name = "Item Photo")]
        public string ItemPhoto { get; set; }
        [Required]
        [Display(Name = "Item Type")]
        public string ItemType { get; set; }
        [Required]
        [Display(Name = "Item Name")]
        public string Name { get; set; }
        [Required]
        [Display(Name = "Item Color")]
        public string Color { get; set; }
        [Required]
        [Display(Name = "Item Size")]
        public string Size { get; set; }
        [Required]
        [Display(Name = "Item Material Type")]
        public string MaterialType { get; set; }
        [Required]
        [Display(Name = "Designed For")]
        public string DesignedFor { get; set; }
        [Required]
        [Display(Name = "Item Price")]
        public double Price { get; set; }
        [Required]
        [Display(Name = "Item Description")]
        public string Description { get; set; }
    }

CartItem
public class CartItem : BaseEntity
    {
        public int? ItemId { get; set; }
        [ForeignKey("ItemId")]
        public Item Item { get; set; }
        public int? UserId { get; set; }
        [ForeignKey("UserId")]
        public User User { get; set; }
        public int Quantity { get; set; }
    }

Repository
public async Task<bool> DeleteAsync(T item)
{
    _entity.Remove(item);
    return await SaveChangesAsync();
}

public async Task<bool> SaveChangesAsync()
        {
            try
            {
                return (await _db.SaveChangesAsync()) >= 0;
            }
            catch
            {
                return false;
            }
        }

I want to do the following: so I have an admin page from where i make crud operations, i also have shopping cart where user can add items, so when any item is added in cart of any user, it doesn't delete, it throws the error which i mentioned above. so what can i do to remove shopping cart items, when admin deletes this item from admin page.
Comment: Hello, deleting related entities is a little tricky, you need to include related subEntities :
var item= context.CartItem .OrderBy(e => e.Name).Include(e => e.Item).First();
context.Remove(item);
context.SaveChanges();

You can also breack the link with war entity by  :
var item= context.CartItem .OrderBy(e => e.Name).Include(e => e.Item).First();
item.Item = null;

Look at this page for more details
https://learn.microsoft.com/fr-fr/ef/core/saving/cascade-delete
Comment: this context is little bit confusing to me, i also checked the link you provided but i dont get it where this context is coming from
Comment: Hello, I think in your code the context is "_db " object
Answer: Delete is getting tricky when you have foreign keys, So I don't recomend you to use a generic repository. you can try this code
var cartItems= _entity.Set<CartItem>().Where(i=> i.ItemId == item.Id).ToArray();

    if(cartItems!=null)
          foreach(var cartItem in cartItems) cartItem.ItemId=null;

    _entity.Set<Item>().Remove(item);

    return await SaveChangesAsync();
}

Comment: okay but if i add this code in repository it won't be good. i mean i have to add item and cartItems references and would it be best practice?
Comment: @SabaMinashvili The generic repository is the bad practice, since EF core has it and UoF (unity or work too) already.  So it will only improve your code.
Comment: oh okay. one more question, where should i implement this code, i mean if i implement it in repository deleteAsync method it won't be correct, but if i do that in controller, it doesn't make sense... so i am little confused
Comment: @SabaMinashvili I usually create the repository, one for each controller ( not generic repository). It is the best place to put this code. Ideally, an each controller action should have only 2 lines of code - get model or result from  a repository and return View. This it the best practice.
Comment: for this kind of result i used CQRS in project and had only 2 lines of code, but in case of repositories, its more. somehow can i see your project structure? i mean where are these repositories located, how do they communicate with each controller and etc? it would be easier for me to understand
Answer: Adding [Required] would force cascade delete
public class CartItem : BaseEntity
{
    public int? ItemId { get; set; }
    [Required]
    [ForeignKey("ItemId")]
    public Item Item { get; set; }
}

Or using Fluent API you can configure WillCascadeOnDelete(true) to cascade delete.
Comment: Wait i am confused, i want to delete item and also all related cartItems and do these codes above do that? i mean it seems that these codes do opposite. i dont want to  delete cartItem and related items to it, i want to delete item and all related cartItem to this item
Comment: i tried this code but unfortunatly it still doesn't work :(


What software can calculate the order of $b \mod p$, where $p$ is a large prime?

Question: I wasn't sure where to ask this, but Mathematics seems better than StackOverflow or Programmers.
I have no background whatsoever in number theory, and I need to find software that can calculate the order of $b \mod p$, where $b = 2^{32}$ and $p$ is of the form $p = a * b^r + 1$.  I've calculated a number of suitable primes using NewPGen and PFGW (as well as Proth.exe), but I have no obvious way of calculating the order of $b \mod p$.
Does anyone know of any program that can do this?
Context, if needed:
I read here (https://stackoverflow.com/questions/5760639/complimentary-multiply-with-carry-period/8781297#8781297) that calculating the order requires factoring $\phi(p) = p - 1$.  Then, for every factor $k$, the order of $b \mod p$ is the smallest $k$ such that $b^{(\phi(p)/k)}\mod p = 1$.
Factoring $p - 1$ is easy in my case, since all of my candidates are already factored for the most part (except the $a$ term), but from what I understand I need not only the prime factors but ALL factors of $p - 1$, and it seems there will always be a ton of them when $b$ is a large power of $2$.  (I don't understand all of that post though, such as their calculation of the number of factors the original poster would have to test.)
Unfortunately, I'm dealing with relatively large numbers here, e.g. $p = 131071 * 2^{864} + 1$.  In this example $a = 131071$ is mercifully prime, but there are $864$ different $2$ factors.  Naively trying every possible combination of the $865$ prime factors would presumably require calculating $b^{phi(p)/k}\mod p$ for, uh...$\sum_{i=1}^{865} 865!/(i!(865 - i)!)$ different $k$'s, which is more than anyone could calculate in the lifetime of the universe.
Knowing $864$ of $phi(p) = p - 1$'s factors are all $2$'s makes things much more manageable, and we only need to try I think $1730$ different $k$'s ($1$ or $131072$ times anywhere from $0$ to $864$ factors of $2$).  If this post is anything to go by, I MIGHT be able to get away with testing only $k$'s containing all $864$ $2$ factors, but I could easily be wrong, since the presence of a non-$2$ factor might change things:  Why 4 is not a primitive root modulo p for any prime p?.
I don't know modular arithmetic though, so even if I only had to test a handful of $k$'s to obtain the order, there's no obvious way for me to calculate something as huge as $b^{(\phi(p)/k)}\mod p$ even once, when $b = 2^{32}$.  The numbers are just too big...so I need some software that knows how to do this sort of thing, preferably software that can calculate the order of $b \mod p$ straight out of the box.
I've found a program that claims to be able to do this, but even the smallest and most trivial prime I'm interested in ($p = 255 * 2^{32} + 1$) is too big for it to handle:
http://www.softpedia.com/get/Science-CAD/ORDER-OF-A-MODULO-P.shtml
Additional Context:
I'm trying to find suitable parameters for complementary multiply with carry (CMWC) generators, a class of random number generators invented by George Marsaglia (https://en.wikipedia.org/wiki/Multiply_with_Carry).  These generators require a prime of the form $p = a * b^r + 1$, where $a$ is some multiplier, $b$ is the base, and $r$ is the lag of the generator (which increases the period).  The period of a CMWC generator is the order of $b \mod p$, and I'm trying to calculate the period of generators fitting the following description:

$b = 2^{32}$, which allows the generator to natively return the full range of unsigned 32-bit numbers, without incurring the cost of a remapping output function.
$r$ is in $[1, 32]$, with special emphasis on $r = 4, 8, 16, 32$.  $r$ controls the maximum possible period of the generator, but it also controls the amount of state that needs to be stored, and I'm looking for lightweight generators that come as close as possible to maximal period.  (Marsaglia calculated suitable parameters for smaller base-$2^{32} - 1$ CMWC generators, and he also provided parameters for smaller base-$2^{32}$ MWC generators...but the only base-$2^{32}$ CMWC generator he talked about was CMWC4827, with $r = 4827$...which is too large for my purposes.)
$a$ can be anything, but things can be a bit more efficient if $a = 2^n \pm 1$.  I have a few candidate $a$'s that fit this description, but not for my preferred power-of-2 $r$ candidates, unfortunately.
Comment: You know that $\phi(p) = p-1 = a \cdot 2^{32r}$ and the order or $b$ is a divisor of $\phi(p)$. So there are at most $64r + 2$ possible values for the order of $b$: $a^{\{0,1\}} \cdot 2^{\{0, 1, \ldots, 32r\}}$.
Comment: I want to upvote both you and kcrisman, but I don't have the rep yet...hopefully this comment will help get me there.  Anyway, doesn't your full post contradict what you're saying here in this comment?  The order of b for this example is a * 2^858, and since r = 27, the order is apparently not a^{0, 1} * 2^{0, 1, ...,32r}, since r does not cleanly divide into 858.
Answer: If I'm not mistaken, Sage might help you.
sage: p = 131071*2^864+1
sage: is_prime(p) # check that it's prime
True
sage: b = mod(2^32,p) # makes a modular integer
sage: b.multiplicative_order()
251908540996674781143692700238872014353662372271648506382312691467942113675280721713248000547359389291315410905230983600885476978770662739599958129278514946363281164152553521078806838898769965654577169449156458268844603358445019507312417844944481614256657162829824

You can make an account for free at sagenb.org or other various similar Sage servers online, or download it.  This functionality comes via Pari.
Comment: Hello to the downvoter - any particular reason on this?  Both of these answers seem appropriate to the question...
Comment: You should also really consider investing some time in an elementary number theory text or course; I think that a lot of your difficulties will be eased in that case, and if you are implementing something like this you obviously have the chops to assimilate this material.  Plus, number theory is beautiful :)
Comment: Sounds great.  I'm surprised that one can't upvote one's own question's answers... Anyway, remember that there are a lot of binaries available as well, and the online servers are in many ways more convenient.  And I look forward to hearing you did pick up that number theory ;-)
Comment: Thank you!  I'm in the middle of compiling Sage, so I haven't put it to use yet, but your clear usage example - and TMM corroborating the answer it produced - shows this is exactly what I'm looking for.  The RNG is really just an indulgent subproject of a subproject of a project I'm working on, so I don't deal with this kind of math (or huge numbers) often, but I may follow your advice someday and learn some basic number theory if I ever find the time. :)  In the meantime, I'll try to digest TMM's post below.  Whenever I get the rep to do so, I'll upvote your answer and his.
Answer: If you are still looking for a solution,
Mathematica's MultiplicativeOrder
can do this.
Unlike Sage, Mathematica is not free, but for smaller inputs you can use Wolfram Alpha.


How do I add seasonal & trend components to the final prediction when using neural networks?

Question: I've got a question about stationarity: let's say I've made seasonal & trend adjustment for my time series input, scaled it and then passed this data to some NN model (e.g., LSTM or windowed-MLP), how do I add seasonal & trend components to the final answer?
Comment: This comment raises a rhetorical question. The authors of the paper *Statistical and Machine Learning forecasting methods: Concerns and ways forward* found that machine learning time series models, at a minimum, did not improve predictions over statistical models and in many cases were less computationally efficient (http://journals.plos.org/plosone/article/file?id=10.1371/journal.pone.0194889&type=printable) Given these fairly conclusive findings, does it make sense to proceed with a NN model of time series *at all* when statistical models are so much more tractable, efficient, etc.?
Comment: @Alex, well, one of the first articles I was able to google: https://www.researchgate.net/publication/258221036_Comparison_between_ARIMA_Models_and_Artificial_Neural_Networks_in_Forecasting_Al-Quds_indices_of_Palestine_Stock_Exchange_Market
Comment: Well, I've found a lot of articles on arxiv.org that say NN models performs better than ARIMA-like methods. The issue is that I cannot integrate ARIMA into my Go code, and I can easily do it with NN model (just hardcode the weight of the model).
Comment: @AlexKornakov can you link to some of those articles?
Comment: @DJohnson anyway, what's the best way (aside from ARIMA and LR) to forecast time series than?

One more article: https://eng.uber.com/neural-networks/
Comment: Thank you for the links. The Uber paper was the more interesting of the two. I found several pretty blatant mistakes in their analysis the most important of which is that they used only a small subset of data -- significantly less than one full year -- to train their models (figs. 1-3, 7). Any experienced time series statistician knows that to initialize seasonal events such as Xmas you need at least two full years of data. Next, NNs require the levels of categorical features be transformed into 0,1 dummy variables, i.e., NNs are unable to treat categorical features as categorical. ctd.>>
Comment: Finally, sampling and treating observations (records, the smallest unit of data) as *iid* ignores inherent structure and variance, e.g., cross-sections such as *city* or seasonalities due to time of day, day, week, month, etc., get lost. My view is that their approach is destructive of explanatory information, structure and variance. A much better approach to modeling time series and especially exceedances or extreme events would be quantile regression rooted in panel data techniques.
Comment: @AlexKornakov I don't have time to write a full answer now. I will later. To answer your comment about other approaches besides ARIMA and LR, exponential smoothing is one the most commonly used methods and in many cases has been shown to perform better than more complex methods.
Comment: @Alex, thank you in advance, it sounds extremely promising!
Comment: BTW, I've got 35 RMSE when using linear regression and less than 1 (yes!) when using LSTM from this tutorial (https://machinelearningmastery.com/multivariate-time-series-forecasting-lstms-keras/#comment-438949): https://imgur.com/a/RvDo2wu. Probably it's about overfitting, but still 35 -> even 10 looks pretty solid, IMO (this's a plot from a simpler LSTM model: https://imgur.com/a/FDsQgNo).
Comment: https://imgur.com/a/8Y7Gmpo
Comment: @DJohnson here's what I get by using LSTM model: https://imgur.com/a/wq5Ha3O The 1st array is the real data, I used log = 3, so I don't predict the 1st 3 values and then you can see the quality of forecast is superb (03:00:00 -> real value: 468, forecasted: 491, 04:00:00 -> real: 681, forecasted: 667). Will try to use exponential smoothing right now!
Comment: @DJohnson the forecast in the graph from the last comment is too good to be true. Are you sure you're not overfitting the data? Or another common mistake I have seen when people use LSTM is that it seems like the LSTM is doing a very good job of estimating the shape pdf the signal when in fact is simply performing a naive 1-step ahead forecast (i.e. it simply memorized the input signal). Have you tried it for n-septs ahead? Also based on your actual values you might want to look into using the TBATS approach, since you have multiple seasonalities in the same series.
Comment: I thought about overfitting, too, and then I run this model on a completely different data and got that plot. I used this [tutorial](https://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/). Actually it's 4300-steps ahead (for about half a year and I pasted a plot for a random month here). TBATS is a good idea, but I want to be able to insert my model into Java code.
Comment: And exponential smoothing behaves strangely for my data: https://stats.stackexchange.com/questions/348803/strange-output-while-using-holt-s-linear-trend-method I can send you a code & data if you don't believe that LSTM is so good.
Comment: @AlexKornakov for exponential smoothing, you are using Holt's linear (also called double exponential smoothing) when in fact you should be using Holt-Winters (triple exponential smoothing).
Comment: @AlexKornakov also can you please clarify which method you used to deseasobalise and detrend your data?
Comment: @Alex do you mean for LSTM or Holt-Winters method? LSTM: use lag = 3, didn't use anything to deseasobalise and detrend my data for Holt-Winters method (just copy pasted code from that tutorial).
Comment: If someone is looking at this topic -> nice way of joining ES and NN methods posted by Slawek Smyl who won last m4 forecasting competition
https://github.com/M4Competition/M4-methods/blob/slaweks_ES-RNN/ES_RNN_SlawekSmyl.pdf
Answer: To answer the main question:

how do I add seasonal & trend components to the final answer?

First you need to be careful with the terminology. Making a series stationary and removing trend and seasonality from a series are not the same thing - even though they are related.
More specifically - removing trend and seasonality might make a series stationary, but there is also the possibility that even after removing the trend and the seasonality, the series is still not stationary (for the variance is still no constant even after detrending and deseasonalising).
Bringing back the seasonality and the trend into the forecast after removing them also depends on what transformation you used to detrend and deseasonalize the signal in the first place.
If differencing was used to make the series stationary (the way it usually is in ARIMA models) then cumulative summing is how you reverse transform the data back to it's original shape. Note that when differencing is used, then the trend and seasonality are being removed implicitly not explicitly.
For example if your differencing order is one:
Original series:
$X_1,X_2,X_3...X_n$
Differenced series:
$Y_1 = X_1$
and for $n>1$
$Y_n = X_{n+1} - X_n$
Initial forecast series:
$\hat{Y}_1,\hat{Y}_2,....\hat{Y}_n$
Final (summed) forecast series:
$\hat{X}_1 = \hat{Y}_1$
For $n>1$
$\hat{X}_n = \hat{Y}_1+\hat{Y}_2+...+\hat{Y}_n$
Other approaches such as Facebook Prophet (GAM based) or STL() try to model the trend $T$, the seasonal component $S$ and the residuals $R$ individually and then add them back together.
In such cases, you try to explicitly model the trend $\hat{T}$, the seasonality $\hat{S}$, and the residuals $\hat{R}$ and then you simply add them back together:
$\hat{X}_n = \hat{T}_n +\hat{S}_n+\hat{R}_n$.

A note on the use of Neural Networks based on the discussion in the comments on the OP (Full disclosure: I am more of a practitioner of time series - I do demand forecasting for retail - than an academic).
From what I see, the idea of Neural Networks - especially LSTM - outperforming traditional methods like ARIMA and exponential smoothing seems to driven mainly by the current overall hype for using Neural Networks and Tensorflow to try to solve every single data science problem out there. Google (and Amazon with their DeepAR model) have been pushing for this since it brings more customers to their cloud platform.
The results in the academic literature seem to be more nuanced and mixed.
In theory, for an LSTM to perform better than Triple Exponential Smoothing, Seasonal ARIMA or TBATS, means that your time series has to have highly complex non linear patterns beyond the seasonal and trend components. In practice, I've found such time series to be rare, and anything that can be modeled by an LSTM can also be modeled by a simpler statistical model with considerably less computational cost and the additional benefit of being easier to interpret.


Time signature issue in MuseScore

Question: How to add only one rest or note at the starting of the piece against the time signature without changing it in musescore?
Comment: Are you asking how to add an anacrusis?
Comment: Does this answers your question: https://music.stackexchange.com/a/82601/63781 ?
Answer: It's called an "anacrusis" or pickup measure.
1/ Easiest way is to add one when you start a new score, just tick the checkbox and add the value:

2/ Another way, e.g. if you already have created a score without a pickup measure, is to modify the first measure, by right clicking on it, then selecting "measure properties". There you can change the actual duration to 1 for example:

As was commented below, you should also tick the "Exclude from measure count" checkbox, since (as explained here: Should pickup measures have measure numbers?) pickup measures aren't considered measure 1.
Comment: The "Exclude from measure count" box should also be checked.

Time signature issue in MuseScore