text stringlengths 49 10.4k | source dict |
|---|---|
c#, object-oriented, event-handling
Then the Bitbucket dispatcher. On GitHub: Bitbucket.EventDispatcher.
public class EventDispatcher : IEventDispatcher
{
public void Dispatch(string eventKey, string json)
{
switch (eventKey)
{
case PushEvent.WebhookEventName:
OnPushReceived(new PushEventArgs(Deserialze<PushEvent>(json)));
break;
}
}
public T Deserialze<T>(string json)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
ms.Position = 0;
return (T)serializer.ReadObject(ms);
}
}
protected void OnPushReceived(PushEventArgs e)
{
var del = PushReceived;
del?.Invoke(this, e);
}
public event EventHandler<PushEventArgs> PushReceived;
}
I'm not going to put all the events or event args here, as I thing I would exceed the character limit (even if it is 65k), but they all share the same basics.
We'll use the PushEvent as an example, as this is one of the more popular/regular events.
Here we have the PushEventArgs. On GitHub: GitHub.Events.Args.PushEventArgs.
public class PushEventArgs : EventArgs
{
public PushEvent Event { get; }
public PushEventArgs(PushEvent e)
{
Event = e;
}
}
Next, the PushEvent model. On GitHub: GitHub.Events.PushEvent.
[DataContract(Name = "root")]
public class PushEvent
{
public const string WebhookEventName = "push";
[DataMember(Name = "ref")]
public string Ref { get; set; }
[DataMember(Name = "before")]
public string Before { get; set; } | {
"domain": "codereview.stackexchange",
"id": 15963,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c#, object-oriented, event-handling",
"url": null
} |
programming-languages, computer-architecture, cpu-cache, garbage-collection
Title: Are generational garbage collectors inherently cache-friendly? A typical generational garbage collector keeps recently allocated data in a separate memory region. In typical programs, a lot of data is short-lived, so collecting young garbage (a minor GC cycle) frequently and collecting old garbage infrequently is a good compromise between memory overhead and time spent doing GC.
Intuitively, the benefit of a generational garbage collector compared with a single-region collector should increase as the latency ratio of main memory relative to cache increases, because the data in the young region is accessed often and kept all in one place. Do experimental results corroborate this intuition? Here are a few papers that talk about the cache implications of generational garbage collectors:
Caching Considerations for Generational Garbage Collection
The Effect of Garbage Collection on Cache Performance
From what I can gather, the primary issue is that garbage collected systems trade off space in memory to avoid up front collection. The same thing applies to cache memory. As you suggested, the things in the first generation are most likely going to be sitting in cache, and so their allocation and collection will be much faster than something in main memory, or paged out to disk. The main issue is the size of the first generation with respect to the size of your cache. If your cache fills up before the first generation does, then you start to lose those benefits as the misses start piling up. | {
"domain": "cs.stackexchange",
"id": 406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "programming-languages, computer-architecture, cpu-cache, garbage-collection",
"url": null
} |
homework-and-exercises, classical-mechanics, rotational-dynamics, rotation
Title: Direction of angular momentum and torque being applied does the direction of external torque and angular momentum resulting from the external torque same? if not, then why it is so and in what cases? The vector sum of the external torques determines the rate of change of the angular momentum vector. For an object on an axle, the vector representing the torque (relative to the axle) is defined as being along the axle. Starting from zero, the vector representing the increase in the angular momentum would be in that same direction along the axle.
For an object already spinning, a torque vector at right angle to the axis would cause the angular momentum vector to swing in the direction of the torque vector (assuming the axis is free to move). (You may want to look up the associated right hand rules.) | {
"domain": "physics.stackexchange",
"id": 66070,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework-and-exercises, classical-mechanics, rotational-dynamics, rotation",
"url": null
} |
immunology, antibody
Title: Calibration curve for single radial immunodiffusion When we draw a calibration curve for single radial immunodiffusion, the curve does not pass through origin. Instead, there is a y intercept. Why does that happen ? Shouldn't zero antigen give zero ring diameter ? When the radial immunodiffusion method is used to measure antigen concentrations in samples, a plate or slide is set up using agarose containing an antibody or antiserum. Holes are punched out of the agarose to form wells into which antigen is dispensed. The antigen diffuses out into the agarose and when the antigen/antibody ratio is favourable an immunoprecipitate will form as a ring (immunoprecipitin ring). The final diameter of the ring is proportional to the initial concentration of antigen.
Addressing the question: isn't this simply explained because the values on the Y axis are squares of the diameters of the rings, and this includes the well into which the antigen is dispensed? | {
"domain": "biology.stackexchange",
"id": 2420,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "immunology, antibody",
"url": null
} |
python, beginner, unit-testing, palindrome
first_pointer = 0
last_pointer = len(text) - 1
# iteration through when the first index is less than the last index
while(first_pointer <= last_pointer):
# set up different while loop condition to do comparison
# test different condition of the palindrome cases
#
# Get letters only
while not text[first_pointer].isalpha():
first_pointer += 1
if first_pointer > len(text) - 1:
return True
while not text[last_pointer].isalpha():
last_pointer -= 1
if last_pointer < 0:
return True
# Not same, return
if(text[first_pointer].lower() != text[last_pointer].lower()):
return False
first_pointer += 1
last_pointer -= 1
return True
def main():
import sys
args = sys.argv[1:] # Ignore script file name
if len(args) > 0:
for arg in args:
is_pal = is_palindrome(arg)
result = 'PASS' if is_pal else 'FAIL'
str_not = 'a' if is_pal else 'not a'
print('{}: {} is {} palindrome'.format(result, repr(arg), str_not))
else:
print('Usage: {} string1 string2 ... stringN'.format(sys.argv[0]))
print(' checks if each argument given is a palindrome')
if __name__ == '__main__':
main()
test_palindrome.py
import unittest
class TestPalindromes(unittest.TestCase): | {
"domain": "codereview.stackexchange",
"id": 28001,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, beginner, unit-testing, palindrome",
"url": null
} |
ros, rqt-reconfigure, dynamic-reconfigure
Title: Use PTZ controls on Axis Camera
I have an Axis camera (AXIS M5014 PTZ) and I am using axis_camera package to get the video stream. The video stream using axis.py works perfectly fine.
Now I am trying to use axis_ptz.py node to control PTZ parameters of the camera. Firstly, there is barely any documentation on this page explaining how you can actually set the parameters for dynamic configuration. After some research I found that rosrun rqt_reconfigure rqt_reconfigure opens a GUI for you to set parameters on different available variables. Now, only "pan" variable works, and "tilt" doesn't do anything. Are there and examples/tutorials/documentation that can help me out?
Originally posted by ajain on ROS Answers with karma: 281 on 2014-10-27
Post score: 0
The teleop.py node subscribes to sensor_msgs/Joy and publishes axis_camera/Axis messages. If you have a joystick, you should be able to control the PTZ using it.
The axis_ptz.py node subscribes to the cmd topic and receives the published axis_camera/Axis in order to control the PTZ unit.
In a nutshell, if you publish axis_camera/Axis messages from your node, you should be able to control the PTZ unit. I based myself on the teleop.py when I wrote my own node.
As for the dynamic reconfigure, I haven't tried that out.
I hope it helps!
Originally posted by Murilo F. M. with karma: 806 on 2014-10-29
This answer was ACCEPTED on the original site
Post score: 2 | {
"domain": "robotics.stackexchange",
"id": 19861,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "ros, rqt-reconfigure, dynamic-reconfigure",
"url": null
} |
python, tree, comparative-review, hash-map
Which approach is better?
EDIT: Clarifications added at based on comments by Konrad.
Gloweye attempts to make the case that "recursive is the way to go". I disagree.
First off, Python does not do tail call optimization. If it did, it would close the performance gap with the iterative approach, but with the current recursive implementation, the iterative method would still win.
In each recursive call, the p[1:] is being passed to the p argument. This is building a brand-new list, and copying the elements to the new list. With n items in the original list, n-1 elements are copied the first time, n-2 are copied the second, n-3 the third, and so on, making this an \$O(n^2)\$ time algorithm.
Gloweye's approach is a constant factor worse, since *args[1:] in addition to constructing the list slice must "splat" the items into the argument list, which then gets unsplatted back to args tuple in the next call. I should stress it is not that much worse; it is still only \$O(n^2)\$.
Both Gloweye's and the current recursive approach, passing p[1:] as the argument in the recursive call, can be corrected from \$O(n^2)\$ to \$O(n)\$ by replacing the list slicing with an iterator. Since the recursive argument has changed from a list to an iterator, a second function would be needed to implement this change.
If tail call optimization was present, and the list was not being repeatedly sliced and recreated each step, such as by using an iterator to walk down the list of keys, then things would be better (as in \$O(n)\$). Tail call optimization works by updating the arguments for the next call, and jumping to the top of the function, which turns the recursion into a simple loop.
So why not just use a loop? | {
"domain": "codereview.stackexchange",
"id": 36366,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, tree, comparative-review, hash-map",
"url": null
} |
python, python-3.x, regex, file-system
Any suggestions? I was told to put the content of the for block in a function, in order to substitute the for block with a list comprehension, but I don't know if it would be significantly faster (the number of files is O(103), tops). Also, the resulting function wouldn't do only one thing: at the very least, it would extract the 4 digits and delete those files for which the corresponding integer is not divisible by 20. I think that most functions should only one thing. Requirements
The requirements are somewhat imprecise because they rely on untold assumptions about the filenames we should expect. Before implementing anything, we should try to think about the different inputs we can have and how we should handle them.
In our case, this could correspond to:
what if the regexp does not match (no underscore or less than 3 numbers) ?
what if we have more than 4 numbers ? Should we consider only the first 4 ?
what if the pattern appears more than once ?
In order to tests tests, I've defined the following list of file names from my invention.
files = [
'.h5',
'_.h5',
'foo_.h5',
'foo_123.h5',
'foo_1234.h5',
'foo_1240.h5',
'foo_12345.h5',
'foo_12340.h5',
'foo_12340.h5',
'foo_12400.h5',
'foo_12403.h5',
'foo_123_bar.h5',
'foo_1234_bar.h5',
'foo_1240_bar.h5',
'foo_12345_bar.h5',
'foo_12340_bar.h5',
'foo_12400_bar.h5',
'foo_12403_bar.h5',
'foo_1234_bar_1240.h5',
'foo_1240_bar_1234.h5',
] | {
"domain": "codereview.stackexchange",
"id": 34544,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, python-3.x, regex, file-system",
"url": null
} |
computability, integers, randomness, real-numbers
uncomputable reals. And this will remain so for any future value of $n$. Stating that you want to print an uncomputable
number, any uncomputable number, is a meaningless endeavor.
It reminds me of people looking for the pot of gold at the foot of the rainbow.
The meaningful problem is not to write any uncomputable number, but to write a specific one, identified by a specific property. Consider for example the binary real $h\in[0.0, 1.0[$ defined as follows: its $n^{th}$
digit is $1$ iff the Turing Machine with Gödel number $n$ halts on empty
input, and $0$ otherwise. This number is very precisely defined. But
if it were computable, we would have a way to decide the halting
problem. Hence, there is no algorithm, no program, that can enumerate the bits of
the real number $h$, and thus there is no way to print it. And using random generators will not help.
Of course, it could be that some random generator, controlled by a
random physical process such as radioactive decay would produce
precisely that number (with a probability closing to zero as time
passes). But, at best:
1- you would have at any time only a rational number which is a prefix
of the non-computable real you are interested in
2- you would most likely be unable to check wether your prefix is
really correct
3- you would have no garantee that the next digit will still be correct.
But, even then, you must assume that the random generator uses some
physical "true" randomness source. Even randomly created, or
computing with whatever technique known or yet to be invented, no computer program can
print an uncomputable real number, such as the number $h$ defined above. That
is a result of computability theory that no such program can exist.
Your only hope is that computability theory does not apply to
radioactive decay or some other such physical phenomena. But I know of no proof | {
"domain": "cs.stackexchange",
"id": 4336,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "computability, integers, randomness, real-numbers",
"url": null
} |
electromagnetism, lagrangian-formalism, classical-field-theory, effective-field-theory
The Darwin Lagrangian just explicitly excludes this interaction. But then what do people mean when they say it's accurate to order $(v/c)^2$?
Even though it looks like the required term isn't present in $L_{\text{int}}$, the desired contribution appears after one computes the complicated Euler-Lagrange equations. But this didn't seem to occur when I did it. The accelerations of the charges are quite complicated, but they don't contain any terms proportional to $q_1 q_2$ besides the magnetic term.
This interaction cannot be included without accounting for retardation or radiation effects, which the Darwin Lagrangian explicitly excludes, since otherwise one would need to keep track of the field configuration. But the interaction is present even for charges which have had uniform velocity forever.
The magnetic interaction somehow also accounts for the effect. I don't see how this could happen, because the magnetic force on charge $i$ vanishes when $v_i = 0$, and this effect doesn't.
What's going on here?
… what do people mean when they say it's accurate to order $(v/c)^2$? | {
"domain": "physics.stackexchange",
"id": 66326,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "electromagnetism, lagrangian-formalism, classical-field-theory, effective-field-theory",
"url": null
} |
So
$\int\frac{dx}{1+\cos(x)}=\tan\left(\frac{x}{2}\rig ht)$
3. Originally Posted by arbolis
The problem states to use the substitution $t=\tan \left( \frac{x}{2} \right)$ or equivalently $x=2 \arctan (t)$ with the integral $\int \frac{dx}{1+\cos (x)}$. I know that the derivative of the $\arctan$ function is $\frac{1}{1+x^2}$ which is very similar to the integral I must calculate, but I don't understand why we bother with a coefficient of $2$ here... Also, even if it's quite similar, I don't know how to do it. Can you help me a bit? Maybe there's something to do with $\sqrt{\cos (x)}$...
Do not do that. Just use $2\cos^2 \tfrac{x}{2} = 1+\cos x$.
4. You could also note that
$\cos\left(\frac{x}{2}\right)=\pm\sqrt{\frac{1+\cos (x)}{2}}$
Squaring both sides gives us
$\cos^2\left(\frac{x}{2}\right)=\frac{1+\cos(x)}{2}$
So $2\cos^2\left(\frac{x}{2}\right)=1+\cos(x)$
EDIT: Looks like TPH beat me to the punch
5. Hello
Originally Posted by arbolis
but I don't understand why we bother with a coefficient of $2$ here...
Because with $t=\tan \frac{x}{2}$ one has $\cos x=\frac{1-t^2}{1+t^2}$. (trig. identity) | {
"domain": "mathhelpforum.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.975576913496333,
"lm_q1q2_score": 0.8493346025630882,
"lm_q2_score": 0.8705972751232809,
"openwebmath_perplexity": 212.03679533018556,
"openwebmath_score": 0.9387497901916504,
"tags": null,
"url": "http://mathhelpforum.com/calculus/43848-clueless-front-integral-s-not-complicated-one-though.html"
} |
quantum-mechanics, hilbert-space, angular-momentum, lie-algebra, spacetime-dimensions
L^+ &= \frac{L+K}2 & L^- &= \frac{L-K}2 \\
[L_i^+,L_j^+] &= \epsilon_{ijk}L_i^+ & [L_i^+,L_j^-] &= 0 & [L_i^-,L_j^-] &= \epsilon_{ijk}L_i^- \\
\end{align}
$$
Thus, you can label the representations are classified by the eigenvalues of $(L^\pm)^2\to l^\pm(l^\pm+1)$, and the natural analogue of the magnetic quantum number is rather $L^\pm_z\to m^\pm_z$ which must obey:
$$
\begin{align}
|m^\pm_z|\leq l^\pm
\end{align}
$$
It turns out that you may already be familiar with it if you’ve seen the Runge vector of the Kepler problem. For the bound states, you can check that you have an algebra of conserved quantities isomorphic to $\mathfrak{so}(4)$ (angular momentum and Runge vector).
Fo the 4D particle in a central potential, the Hamiltonian is:
$$
\begin{align}
H &= \frac{p^2}2+V \\
&= \frac{p_r^2}2+\frac{3p_r}{2r}+\frac{2(L^+)^2+2(L^-)^2}{2r^2}+V
\end{align}
$$
so using the same trick of changing the wave function to revert to a 1D problem with a wall at $r=0$ and effective potential:
$$
V_e = \frac{2l^+(l^++1)+2l^-(l^-+1)}{2r^2}+V
$$ | {
"domain": "physics.stackexchange",
"id": 99575,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "quantum-mechanics, hilbert-space, angular-momentum, lie-algebra, spacetime-dimensions",
"url": null
} |
c++, object-oriented, snake-game
Coordinates newFront = { newFrontX, newFrontY };
m_snakesBody.push_back(newFront);
//reducing y axis as we move up
m_frontPosition.y -= 1;
}
void Snake::move(mapType& map) {
switch (m_direction) {
case Direction::right: {
// changing snakes position on the map as it moves to the right
addHeadToRight(map);
//snake grows in tail if it ate (so we are not erasing it if there isn't fruit spawned what means snake ate)
if((Fruit::isSpawned())){
eraseTail(map);
} | {
"domain": "codereview.stackexchange",
"id": 43332,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, object-oriented, snake-game",
"url": null
} |
# In how many ways can $5$ balls of different colours be placed in $3$ boxes of different sizes if no box remains empty?
5 balls of different colours are to be placed in 3 boxes of different sizes. Each box can hold all 5 balls. The number of ways in which we can place the balls in the boxes so that no box remains empty.
My attempt:-
First choose 3 balls to be placed in 3 boxes so that none of them remain empty in ${{5}\choose{3}}\cdot3! = 60$ ways.
Now remaining 2 balls can go into any of the 3 boxes in $3\cdot3 = 9$ ways.
Total number of ways $= 60\cdot9 = 540$.
Where am I going wrong ?
• When you place the last two balls, you are over counting. Your answer better be less than $243$. Oct 1 '17 at 10:51
There are three choices for each of the five balls. Hence, if there were no restrictions, the balls could be placed in the boxes in $3^5$ ways. From these, we must exclude those distributions in which one or more of the boxes is empty.
There are $\binom{3}{1}$ ways to exclude one of the boxes and $2^5$ ways to distribute the balls to the remaining boxes. Hence, there are $$\binom{3}{1}2^5$$ ways to distribute the balls so that one of the boxes is empty.
However, we have counted those distributions in which two of the boxes are empty twice, once for each of the ways we could have designated one of the empty boxes as the excluded box. We only want to exclude them once, so we must add these cases back.
There are $\binom{3}{2}$ ways to exclude two of the boxes and one way to place all the balls in the remaining box.
Hence, the number of ways the balls can be distributed so that no box is left empty is $$3^5 - \binom{3}{1}2^5 + \binom{3}{2}1^5$$ by the Inclusion-Exclusion Principle.
Where am I going wrong? | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9843363549643402,
"lm_q1q2_score": 0.840537368527786,
"lm_q2_score": 0.8539127548105611,
"openwebmath_perplexity": 122.18986063362453,
"openwebmath_score": 0.9724416732788086,
"tags": null,
"url": "https://math.stackexchange.com/questions/2452609/in-how-many-ways-can-5-balls-of-different-colours-be-placed-in-3-boxes-of-di"
} |
localization, navigation
Title: Building a firefighting robot using ROS: a good idea?
I have entered a firefighting robot competition which is similar to the famous Trinity College one. The robot must conduct a search of rooms in a known map with a known starting position.
My thought was that I could use some sonar or IR sensors along with encoders on the robot, and use ROS via XBee to a PC to localize the robot and publish the necessary cmd_vel to control the motors. I have already gotten teleop with a joystick to work (which is good news, my kids will be able do to their part of the competition). However, as I sit and wait for parts to arrive, I am wondering if my solution has any chance of working. Is the navigation stack on ROS fast enough to keep up with a speedy little robot? Will it do a decent job on localization if don't have a laser scanner or Kinect? I do know the map and the starting position.
I know that Fergs is a prior Trinity winner and he used wall following as his primary form of navigation. Perhaps a combination approach of that with ROS doing corrective localization would work? Or is this a completely crazy idea.
I realize this is largely a "try it and see" type of situation, but I'd welcome any comments or advice.
Originally posted by eschulma on ROS Answers with karma: 23 on 2012-03-20
Post score: 2
I would recommend for ROS, but against using the nav stack for your particular application. The default mapping, localization, and planning algorithms in the nav stack are fairly CPU-intensive, and would be unlikely to be able to keep up with the speeds your robot would likely be running at. Though you can fake a laser with sonar as Dimitri said, you really have to be sitting still if you want to simply drop that data in place of the LIDAR data the nav stack wants (since a LIDAR scan is much more of a snapshot than a slow sonar/IR scan is).
Though the nav stack can be modified to meet your needs, it would likely be easier for you to use ROS as the underlying infrastructure and write your own behaviour node(s) if you're not already familiar with transforms and the nav stack. | {
"domain": "robotics.stackexchange",
"id": 8661,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "localization, navigation",
"url": null
} |
star, temperature, spectral-type
Title: Is there an O1 or O0 star? Okay, we've seen the super hot Wolf-Rayet stars, especially WR 102 and 142, and the "slash stars," many of which are early O (O2-4.5/WN). We know the temperatures of these Wolf Rayet stars. So if we know that, what would their spectral types be in the standard Morgan-Keenan spectral classification (i.e. O2V or B0Ia+), and are there known stars with spectral class earlier than O2? This is what Wikipedia says about it:
When the MKK classification scheme was first described in 1943, the only subtypes of class O used were O5 to O9.5. The MKK scheme was extended to O9.7 in 1971 and O4 in 1978, and new classification schemes that add types O2, O3, and O3.5 have subsequently been introduced.
It references the paper A New Spectral Classification System for the Earliest O Stars: Definition of Type O2
Thus, a new earliest spectral type has been defined.
So unless that information is outdated, there's no such thing as O1 or O0. | {
"domain": "astronomy.stackexchange",
"id": 4944,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "star, temperature, spectral-type",
"url": null
} |
quantum-mechanics
Title: non-negative energies Can someone help me with the following question:
given the hamiltonian: $H=\frac{1}{2m}(iP-\hbar f(X))(-iP-\hbar f(X))$
where $f(x)$ an analytic real function. prove that the eigenenergies of the system are non-negative and then given that the ground state has $0$ energy find it's eigenstate.
all I got is that from the given hamiltionian I can write it in the form: $$H=\frac{P^2}{2m}+\frac{\hbar ^2}{2m}(f^2(X)-f'(X))$$
and if I consider some eigenstate $|\varphi\rangle$ of $H$ I try to show that $\langle \varphi |H|\varphi \rangle\geq0$
but I can't show that $\langle \varphi |f'(x)|\varphi \rangle\geq0$ for arbitrary function $f$. It is best to start from the form of the Hamiltonian itself: The operator $H$ is of the form $H = \frac{1}{2m} Q^\dagger Q$ with $Q^\dagger = iP -\hbar f(x)$ so that for any $|\phi>$ $$<\phi| H |\phi> = \frac{1}{2m}<\phi| Q^\dagger Q |\phi> = \frac{1}{2m} \left( Q |\phi>, Q|\phi>\right) \, \, \ge 0$$ and is only zero when $Q |\phi> = 0$. | {
"domain": "physics.stackexchange",
"id": 32104,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "quantum-mechanics",
"url": null
} |
asymptotics, landau-notation
Title: If my algorithm has complexity O(n!*n), can I just write O(n!), or do I have to keep it like O(n!*n)? Just as I asked in the title: if my algorithm has complexity $O(n!\times n)$, can I just write $O(n!)$, or I have to keep it like $O(n!\times n)$? The function $n! \cdot n$ grows faster than $n!$, so it is not the case that $n! \cdot n$ is $O(n!)$. Therefore if all you know about an algorithm is that it runs in time $O(n! \cdot n)$, you cannot conclude that it runs in time $O(n!)$.
What you can do is "O tilde" notation, and write $\tilde{O}(n!)$. The meaning of "O tilde" is not completely standard, so you will have to explain that for you, $\tilde{O}$ suppresses factors which are polynomial in $n$. | {
"domain": "cs.stackexchange",
"id": 13638,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "asymptotics, landau-notation",
"url": null
} |
java, swing
// draw top
g.drawLine(p.mX, p.mY, p.mX + SPACING, p.mY);
// draw left
g.drawLine(p.mX, p.mY, p.mX, p.mY + SPACING);
// draw right
g.drawLine(p.mX + SPACING, p.mY, p.mX + SPACING, p.mY + SPACING);
// draw bottom
g.drawLine(p.mX, p.mY + SPACING, p.mX + SPACING, p.mY + SPACING);
}
/**
* Build entire UI
*/
public static void buildGUI() {
// create a container level JFrame
JFrame frame = new JFrame("Maze Generator");
// set up frame
frame.setSize(800, 800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// create a panel
MazeBuilder app = new MazeBuilder(frame);
app.buildMenu(frame);
frame.setContentPane(app);
}
}
Program
import javax.swing.SwingUtilities;
public class Program {
public static void main(String args[]) {
// run on event-dispatching thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
MazeBuilder.buildGUI();
}
});
}
}
I knew it was very bad when putting the logic of maze into the UI class, but I couldn't find a way to extract them out. Please help criticizing my code. Thanks. Here's a few tips:
When I ran you program at first, I got a blank frame. Make sure frame.setVisible(true) is the last thing you do. Everything else should be set up before that.
Really, really, really avoid magic numbers. Code like this:
public void draw(Graphics g) {
int width = 15;
int height = 18;
// etc.
} | {
"domain": "codereview.stackexchange",
"id": 1988,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, swing",
"url": null
} |
quantum-field-theory, path-integral, double-slit-experiment, interference, gauge-invariance
4.3 The Aharonov-Bohm effect
The Aharonov-Bohm effect (Aharonov and Bohm, 1959) deserves special attention since it is
often considered to be an instance of the Berry phase. The scenario is very well known: a
split electron beam passes around a solenoid in which a magnetic field is confined. The region
outside the solenoid is field-free, but nevertheless, a shift in the interference pattern on a screen
behind the solenoid can be observed upon alteration of the magnetic field. The phase shift can
be calculated from the loop integral over the potential, which—due to Stokes’ theorem—relates
to the magnetic flux,...etc.
More can be read here, where the Berry phase is discussed. Somehow this seemed important for this problem. I don't know exactly how though. A full analysis of the Aharanov-Bohm effect in the double slit experiment is beyond the scope of this answer, but the idea can be understood from a toy model. Consider the following setup: | {
"domain": "physics.stackexchange",
"id": 76729,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "quantum-field-theory, path-integral, double-slit-experiment, interference, gauge-invariance",
"url": null
} |
### 1.2.2 Example: Linear Regression revisited
We will apply gradient descent to linear regression in the lab session.
Exercise: Define $$\sigma(x) = \dfrac {e^x}{e^x+1}= \dfrac 1 {1+e^{-x}}$$. In Logistic Regression we will minimize the following error function $E ({\boldsymbol{w}}) = - \sum_{n=1}^N \{ t_n \ln y_n + (1-t_n) \ln (1-y_n)\},$ where we write $${\boldsymbol{w}}=(w_1, w_2, \dots , w_{k+1})$$ and $$y_n=\sigma(w_1 x_{n1}+ w_2 x_{n2} + \cdots + w_k x_{nk}+w_{k+1} )$$. Compute the gradient $$\nabla E({\boldsymbol{w}})$$.
## 1.3 Newton’s Method
Let us first consider the single-variable case.
• Let $$f: \mathbb R \longrightarrow \mathbb R$$ be a single-variable (convex, differentiable) function.
• To find a local minimum $$\Longleftrightarrow$$ To find $$x^*$$ such that $$f'(x^*)=0$$
Make a guess $$x_0$$ for $$x^*$$ and set $$x=x_0+h$$. | {
"domain": "jeremy9959.net",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9912886137407894,
"lm_q1q2_score": 0.8239026438779147,
"lm_q2_score": 0.8311430520409022,
"openwebmath_perplexity": 330.6237713004506,
"openwebmath_score": 0.9999312162399292,
"tags": null,
"url": "https://jeremy9959.net/Math-3094-UConn/published_notes/notes/GD.html"
} |
• Sorry for the late reply, I've read your answer thoroughly and found it very helpful. Thanks for taking the time and explaining things! – Ebrin Jun 28 '20 at 15:59
So if $$\cos W = 0$$ then $$W = \pm \frac \pi 2 + 2k\pi$$. Notice $$-\frac \pi 2 + 2k \pi = \frac \pi 2 + (2k-1)\pi$$. And $$\frac \pi 2 + 2k \pi = -\frac \pi 2 + (2k+1) \pi$$. So to simplify $$W = \frac \pi 2 + m\pi$$ would be the simplest way to state this.
(Alternativily as $$0 = -0$$ and $$\cos(W \pm \pi) = -\cos W$$ we'd note that for an $$W = \pm \frac \pi 2 +2k \pi$$ then $$\mp \frac \pi 2+ (2k+1)\pi$$ is a solution).
So $$\frac x2 -1 = \frac \pi 2 + m\pi$$ then $$x = (2m+1)\pi + 2$$
And if $$\cos W = 1$$ then .... well... do I need to point out that solution is $$W=m\pi$$?
So $$\frac x2 -1= m\pi$$ so $$x=2m\pi +1$$.
So the solutions are $$x = k \pi + 2$$. If $$k$$ is odd then $$\cos(\frac x2 -1)=\cos(\frac k2 \pi) = 1$$. And if $$k$$ is odd then $$\cos(\frac x2 -1)=\cos(\frac {k-1}2\pi + \frac \pi 2) = 0$$. | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.969785412932606,
"lm_q1q2_score": 0.8557656788498805,
"lm_q2_score": 0.8824278726384089,
"openwebmath_perplexity": 188.86791788394024,
"openwebmath_score": 0.8674164414405823,
"tags": null,
"url": "https://math.stackexchange.com/questions/3732112/general-solution-for-cos-fracx2-1-cos21-fracx2"
} |
# Recursion, DP & Backtracking
Dynamic Programming, Recursion, & Backtracking
# Recursion
Recursion
Thinking Recursively in Python - Real Python
5 Simple Steps for Solving Any Recursive Problem
Explore - LeetCode
Master Recursion
Recursion is an approach to solving problems using a function that calls itself as a subroutine.
Recursion,%20DP%20&%20Backtracking%20525dddcdd0874ed98372518724fc8753/fixing_problems.webp
When do you use recursion? making one choice, then one after that, on and on. Or in hierarchies, networks and graphs.
Recursive strategy:
• Order your data (not necessarily via code - just conceptually)
Helps in identifying the base case
Decompose the original problem into simpler instances of the same problem. This is the recursive case:
# Factorial
n! = n x (n−1) x (n−2) x (n−3) ⋅⋅⋅⋅ x 3 x 2 x 1
n! = n x (n−1)!
# Fibonacci
Fn = Fn-1 + Fn-2
Whatever data we are operating on, whether it is numbers, strings, lists, binary trees or people, it is necessary to explicitly find an appropriate ordering that gives us a direction to move in to make the problem smaller. This ordering depends entirely on the problem, but a good start is to think of the obvious orderings: numbers come with their own ordering, strings and lists can be ordered by their length, binary trees can be ordered by depth.
Once we’ve ordered our data, we can think of it as something that we can reduce. In fact, we can write out our ordering as a sequence: | {
"domain": "paulonteri.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9559813501370535,
"lm_q1q2_score": 0.8218225111577803,
"lm_q2_score": 0.8596637487122111,
"openwebmath_perplexity": 6090.381773024074,
"openwebmath_score": 0.30743175745010376,
"tags": null,
"url": "https://dsa.paulonteri.com/Data%20Structures%20and%20Algorithms%2016913c6fbd244de481b6b1705cbfa6be/Recursion%2C%20DP%20%26%20Backtracking%20525dddcdd0874ed98372518724fc8753.html"
} |
acid-base, amines
I was unable to find an exact definition for relative basicity, so I am going to assume based on the following reasoning. First we define the basicity for ammonia, $Bf(\ce{NH3})$, and an arbitrary amine $Bf(\ce{NR3})$.
\begin{align}
\ce{NH3 + H+ &~-> NH4+} -\Delta G_\mathrm{r}^\circ(\ce{NH4+}) &
Bf(\ce{NH3}) &= -\Delta G_\mathrm{r}^\circ(\ce{NH4+})\tag{1} \\
\ce{NR3 + H+ &~-> NR3H+} -\Delta G_\mathrm{r}^\circ(\ce{NR3H+}) &
Bf(\ce{NR3}) &= -\Delta G_\mathrm{r}^\circ(\ce{NR3H+})\tag{2} \\
\end{align}
We can follow up and define the relative basicity of an arbitrary amine to ammonia $Bf_\mathrm{rel}(\ce{NR3})$ as the difference of the independent basicities.
$$Bf_\mathrm{rel}(\ce{NR3}) = Bf(\ce{NR3}) - Bf(\ce{NH3})\tag{3}$$
With (3) we would actually describe the following reaction:
$$\require{cancel}
\begin{align}
\ce{NR3 + \cancel{H^+} + NH4+ &~-> NR3H+ + \cancel{H^+} + NH3}\\
\ce{NR3 + NH4+ &~-> NR3H+ + NH3}\\
\end{align}$$
So the relative basicity describes in this scenario how likely it is that the arbitrary amine is abstracting a proton from the conjugate base of ammonia, i.e. ammonium. The higher the relative basicity, the stronger the base. | {
"domain": "chemistry.stackexchange",
"id": 4990,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "acid-base, amines",
"url": null
} |
$(x^2)^{1/2}$ is defined for every real $x$, but $(x^{1/2})^2$ is defined for $x \ge 0$
-
if it is presented as $x^\frac{2}{2}$, then simplify the exponent first. – Joshua Biderman Mar 19 '14 at 6:21
@xs21 What is "wrong" with that is that fractional exponents have the specific meaning $\ x^{p/q} = \ \sqrt[q]{x^p} \ .$ The domains of such functions must be considered when proposing to evaluate them for chosen values of $\ x \ .$ Also, the square-root operation is defined as giving the positive square-root. That is why $\ \sqrt{x^2} = |x| \ .$ – RecklessReckoner Mar 19 '14 at 6:30
But the OP has asked about $(x^2)^{\frac 1 2}$ with respect to $x^1$ which are both defined for all $x$. – Emanuele Paolini Mar 19 '14 at 7:30
@RecklessReckoner: No. Fractional exponents do not have to satisfy $x^{p/q} = \sqrt[q]{x^p}$. This will hold if $x$ is a positive real number; if not, one or both sides could be undefined, independently, and even if both are defined their values could be different. $(-1)^{6/2}=(-1)^3=-1\neq 1=\sqrt{(-1)^6}$. – Marc van Leeuwen Mar 19 '14 at 13:51
@MarcvanLeeuwen I realized later that my definition is incomplete. The interpretation I should have written is $\ x^{p/q} \ = \ \sqrt[q]{x^p} \ = \ (\sqrt[q]{x})^p \ .$ Had I done so at the time, I'd have noticed I was being inconsistent; I have hopefully said this better in the answer I've now written. – RecklessReckoner Mar 19 '14 at 15:59 | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9719924793940119,
"lm_q1q2_score": 0.8099852455725217,
"lm_q2_score": 0.8333246015211008,
"openwebmath_perplexity": 412.83255918405536,
"openwebmath_score": 0.910518229007721,
"tags": null,
"url": "http://math.stackexchange.com/questions/717882/how-does-the-exponent-of-a-function-effect-the-result"
} |
Is there no other way to solve this problem? I doubt I need to go through such complicated stuff for this problem because it is an exam problem.
#### Pranav
##### Well-known member
We can use the digamma function
We can regularize a divergent infinite sum to give it a finite value
$$\displaystyle \sum_{n\geq 0}\frac{1}{n+a}=-\psi(a)$$
So
$$\displaystyle S=\frac{1}{4}\sum_{r=0}^\infty \left(\frac{1}{r+\frac{1}{4}}-\frac{1}{r+\frac{3}{4}}\right)=-\frac{1}{4} \left(\psi\left(\frac{1}{4}\right) -\psi\left(\frac{3}{4}\right)\right)$$
Now use the reflection formula
$$\displaystyle \psi(1-x)-\psi(x)=\pi\cot(\pi x)$$
so
$$\displaystyle \psi\left(\frac{1}{4}\right) -\psi \left(\frac{3}{4}\right) =-\pi\cot \left(\frac{\pi}{4} \right)=-\pi$$
Hence
$$\displaystyle S=\frac{\pi}{4}$$
- - - Updated - - -
Interestingly using the regulaized representation we can find that
$$\displaystyle \sum_{n\geq 0}\frac{1}{n+1}=\sum_{n\geq 1}\frac{1}{n}=-\psi(1)=\gamma$$
So
$$\displaystyle \lim_{n \to \infty }H_n = \gamma$$
Thank you for your participation ZaidAlyafey but unfortunately that's no better, it still requires a level of Math I haven't reached. | {
"domain": "mathhelpboards.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9693241991754918,
"lm_q1q2_score": 0.8219556645920126,
"lm_q2_score": 0.8479677545357569,
"openwebmath_perplexity": 807.0518803603455,
"openwebmath_score": 0.7397052049636841,
"tags": null,
"url": "https://mathhelpboards.com/threads/limit-of-sum.8576/"
} |
-
Another way to look at it is by the divisibility lattice, where gcd is the greatest lower bound. So 5 is the greatest lower bound of 10 and 15 in the lattice.
The counter-intuitive thing about this lattice is that the 'bottom' (the absolute lowest element) is 1 (1 divides everything), but the highest element, the one above everybody, is 0 (everybody divides 0).
So $\gcd(0, x)$ is the same as ${\rm glb}(0, x)$ and should be $x$, because $x$ is the lower bound of the two: they are not 'apart' and 0 is '$>'$ $x$ (that is the counter-intuitive part).
-
In fact, the top answer can be generalized slightly (sorry, I don't have enough points to post comments, yet): if $a \vert b$, then $gcd(a,b)=a$ (and this holds in any algebraic structure where divisibility makes sense (eg a commutative, cancellative monoid)).
To see why, well, it's clear that $a$ is a common divisor of $a$ and $b$, and if $\alpha$ is any common divisor of $a$ and $b$, then, of course, $\alpha \vert a$. Thus, $a=gcd(a,b)$.
-
Indeed, even more generally, it is a special case of the distributive law - see my answer. As for commutative monoids, one usually requires them to be cancellative in order to obtain a rich theory. – Bill Dubuque Mar 18 '11 at 18:26 | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9777138092657496,
"lm_q1q2_score": 0.8348822922864437,
"lm_q2_score": 0.8539127548105611,
"openwebmath_perplexity": 277.6971379961575,
"openwebmath_score": 0.9452710151672363,
"tags": null,
"url": "http://math.stackexchange.com/questions/27719/what-is-gcd0-a-where-a-is-a-positive-integer/27821"
} |
php, form, mysqli
Title: Inserting data in the database through POST My code here is completely working, but I feel like I destroyed or didn't follow the DRY rule, what suggestions can you give to me for this code??
<?php require_once("./includes/Utilities.php") ;?>
<?php require_once("./includes/Db_Resources/db_connection.php");?>
<?php require_once("./includes/Db/DatabaseUtilities.php"); ?>
<?php
if(isset($_POST['submit'])){
require_once("./includes/process_form.inc.php");
require_once('./includes/Db/CheckPassword.php');
require_once('./includes/Db/CheckUsername.php');
$check_pwd = new Db_CheckPassword($password);
$check_user = new Db_CheckUsername($username,$conn);
$passwordOK = $check_pwd->check();//Checks if Password is valid
$userOK = $check_user->check();//Checks if Username is valid
//Checks if Password is the same with the retyped password
$password_match = Db_CheckPassword::confirmPassword($password,$conf_pass);
//if everything is okay! we'll finally add the muthafucking users account
if($userOK && $passwordOK && $password_match){
if(Db_DatabaseUtilities::registerAccount($conn,$username,$password,$email)){
header("Location: login.php");
exit;
}
}else{
$pass_error = $check_pwd -> getErrors();
$user_error = $check_user->getErrors();
}
}
?> Here are some things that I would recommend: | {
"domain": "codereview.stackexchange",
"id": 1962,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "php, form, mysqli",
"url": null
} |
java, object-oriented, game, gui, libgdx
public void sliderClosed(SideButtonSlider slider) {
if (slider == this.overlaySlider) {
this.libGDXGame.disableOverlays();
this.uncolorAllTileActors();
}
}
I know that I could separate all of this logic out into another class, a SideBar class perhaps, but all of these buttons call methods in the GameScreen class so that will require a lot of work. Not sure if it is worth it.
I don't like that all of the buttons need to be created before this whole structure is put together, but again, all of the callbacks are pointing to private methods in the GameScreen class so this seemed like a reasonable way to do things.
All feedback is appreciated, as always. You can literally use the builder pattern for your Builder game here. :)
See, you have group of buttons that must be assigned a same color. These buttons have a corresponding pair of button label and a ClickListener implementation. Therefore, it's not hard to imagine a Builder implementation that lets you chain these operations:
public final class SideButtonSliderBuilder {
private final GameScreen screen;
private final Skin skin;
private final String groupLabel;
private final Color color;
private final List<String> labels = new ArrayList<String>();
private final List<ClickListener> listeners = new ArrayList<String>();
private SideButtonSliderBuilder(GameScreen screen, Skin skin,
String groupLabel, Color color) {
this.screen = screen;
this.skin = skin;
this.groupLabel = groupLabel;
this.color = color;
}
public SideButtonSliderBuilder addButton(String label, ClickListener listener) {
// remember null checks too, just in case
labels.add(label);
listeners.add(listener);
return this;
}
private TextButton toButton(String label, ClickListener listener) {
// since this is a private method, null checks are probably optional
TextButton button = new TextButton(label, skin);
button.setColor(color);
button.addListener(listener);
return button;
} | {
"domain": "codereview.stackexchange",
"id": 14622,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, object-oriented, game, gui, libgdx",
"url": null
} |
java, beginner, game, android
public static boolean won (List<Tile> tiles) {
for (Tile t : tiles) {
if (!t.selected)
return false;
}
return true;
}
public static void resetStage()
{
if(GlobalValues.best > GlobalValues.moves)
GlobalValues.best = GlobalValues.moves;
GlobalValues.moves = 0;
Field.tiles = new ArrayList<Tile>();
}
public static void clearStage() {
GlobalValues.moves = 0;
Field.tiles = new ArrayList<Tile>();
}
}
Tile Class:
package com.timcorp.timotheus.colorgame;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
public class Tile {
public boolean selected;
public int x;
public int y;
public GlobalValues.Colors color;
public ImageView image;
public Tile(int X, int Y)
{
this.x = X;
this.y = Y;
if(this.x==0 && this.y == 0)
this.selected = true;
else
this.selected = false;
}
public void changeColor(GlobalValues.Colors color)
{
this.color = color;
}
@Override
public String toString()
{
return "(" + this.x + "," + this.y + ") " + this.color + " " + this.selected;
}
}
Menu Class:
package com.timcorp.timotheus.colorgame;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class MenuActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu); | {
"domain": "codereview.stackexchange",
"id": 24857,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, beginner, game, android",
"url": null
} |
population-genetics, molecular-evolution, microbiome, quantitative-genetics
Microbiome members are often interdependent
As hinted at in the question update, bacteria display a type of community altruism, where an individual cell with a specific gene can influence the fitness of neighboring cells that lack the gene. For an example, see my answer to Will all bacteria become resistant against all antibiotics in the long term? concerning secreted β-lactamases.
Therefore, spatial association is an added factor when considering population dynamics of a genetically heterogeneous bacterial species. Some methods that address cell-cell spatial proximity in microbiomes include sequencing of cryofractured fragments 17 and probe-based spectral imaging.18 Even if microbes are not spatially associated, different microbes may play complementary roles in the iterative metabolism of large carbohydrates into small metabolites.19,20
Surely, this discussion is incomplete, though I hope my answer has given you the footing you need to continue your own exploration to find the appropriate resources for your research. For a more in-depth discussion of the points I've addressed here, see What Is Metagenomics Teaching Us, and What Is Missed?,21 particularly the sections titled Strain-Level Analyses and Ecoevolutionary Modeling. | {
"domain": "biology.stackexchange",
"id": 11034,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "population-genetics, molecular-evolution, microbiome, quantitative-genetics",
"url": null
} |
five -- is it 0.5 or five? -- a 0.5 kilogram block is placed on top of the polystyrene, and what fraction will be above the water now? Before, there is 90 percent above the water and now with this block on top what fraction will be above the water now? So the buoyant force is the weight of the fluid displaced, Archimedes principle, because the thing is floating that's going to equal the weight of the thing, so that's the mass of the polystyrene plus the mass of the block, times g. So we have this expression now, mass of the water displaced is the total mass of the block and polystyrene, and density of water is this as we've seen before. We can solve this for V w by multiplying by V w over density of water and we get the volume of water displaced is mass of the water divided by density of water. That's going to equal the fraction of the block that is submerged, times the total volume of the block. So we're solving for b here, the fraction submerged because this amount by which it's submerged, this is the volume submerged, is going to equal the volume of water displaced. So we have b then after we divide both sides by V p here, is the mass of the water divided by density of water times V p. Now the mass of the water is mass of the polystyrene block plus the mass of the block. Then we substitute for mass of the polystyrene which is density of polystyrene times its volume, and then we can divide this denominator into both terms on the top here. We get the ratio of the densities of polystyrene to water plus the mass of the block divided by density of water times volume of the polystyrene. This works out to 100 kilograms per cubic meter divided by 1000 kilograms per cubic mete plus 0.5 kilograms, mass of the block, divided by 1000 kilograms per cubic meter times 0.1 meter cubed, this is the volume of the polystyrene, this works out to 0.6. So 60 percent of the polystyrene block is submerged which means the percent above is 100 minus 60 which is 40 percent. That's 40 percent of the block, polystyrene, is above the water. Then if the fluid was not | {
"domain": "collegephysicsanswers.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9805806546550656,
"lm_q1q2_score": 0.8016977194538288,
"lm_q2_score": 0.8175744806385543,
"openwebmath_perplexity": 431.2630230973122,
"openwebmath_score": 0.7273207902908325,
"tags": null,
"url": "https://collegephysicsanswers.com/openstax-solutions/cube-polystyrene-measuring-10-cm-side-lies-partially-submerged-large-container"
} |
c, socket, tcp
ret = setsockopt(fd1, IPPROTO_TCP, TCP_NODELAY,
(char *) &flag, sizeof(int)); // --- TCP_NODELAY used to disable nagle's algorithm
if (ret != 0) {
perror("Error in setsockopt");
close(fd1);
exit(EXIT_FAILURE);
}
if (connect(fd1, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1) { // --- Connect the socket to the server
perror("ERROR in Connecting");
close(fd1);
exit(EXIT_FAILURE);
}
printf("Client connected Successfully\n");
return fd1;
}
Initial definition (init.c):
#include "init.h"
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <stdbool.h>
#define SIZE 220000
struct hostent *server;
unsigned char *receive(int csd, unsigned int size)
{
long int ret;
unsigned char *buf = malloc(size), *buf1 = NULL;
if(buf != NULL) {
memset(buf, 0,size);
} else {
fprintf(stderr, "Memory not allocated\n");
close(csd);
exit(EXIT_FAILURE);
}
while(true) {
ret = recv(csd, buf, size, 0);
if(buf[ret-1] > 0) {
buf1 = malloc(size);
if(buf1 != NULL) {
memset(buf1, 0,size);
} else {
fprintf(stderr, "Memory not allocated\n");
free(buf);
close(csd);
exit(EXIT_FAILURE);
} | {
"domain": "codereview.stackexchange",
"id": 31002,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c, socket, tcp",
"url": null
} |
electrostatics, electric-fields
My hang up at the moment is this: how can you prove that the field line passing through $C$ will pass this point perpendicular to the central line?
Intuitively, we might expect that lines of force (in isotropic homogeneous media) cross an axis of symmetry of a system of point charges at oblique angles if and only if there is a point charge on the axis at that location. Then, because the field line passes through an axis of symmetry, and no point charges are present, it must be perpendicular to the central line (neglect the case of a parallel line).
However, throughout the first chapter, Gauss's law in integral form is used to solve problems with field lines, and I'm hoping to find a more rigorous proof along these lines. I am trying to respond quickly and perhaps not very carefully. (And sorry for my poor english !).
Given the symmetries, we can consider developments of the field around the point of equilibrium of the following form, odd in $r$ for the radial component, even for the $z$ component:
$E_z (r,z)=a_1 (z) r^2+a_2 (z) r^4+⋯$
$E_r (r,z)=b_1 (z)r+b_2 (z) r^3…$
As $dz/dr=E_z/E_r $, we have to find the limit of the slope when one approaches the point of equilibrium,that is the limit of $(a_1 (z) r^2+a_2 (z) r^4…)/(b_1 (z)r+b_2 (z) r^3…)$ when $r$ tends to $0$. As this limit is $dz/dr=0$, the angle is $90°$.
For the other angle, it should be noted that the field lines inside the cone limited by all the lines from A to E return towards the charge $-q$. Only the outer field lines go to infinity.
The flux of the electric field around the charge $4q$ is $(4q/ε_0)$
The solid angle corresponding to the field lines external to the tube which joins A to C is $Ω=2π(1+cos(θ))$ and the corresponding flux is | {
"domain": "physics.stackexchange",
"id": 92724,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "electrostatics, electric-fields",
"url": null
} |
quantum-field-theory, photons, interactions, propagator
where $\mu$ is really just an arbitrary parameter. Now we can see that
$$i\Delta_F(x,\mu^2)=\int \frac{d^4q}{(2\pi)^3} \theta(q^0)\ e^{-iqx} \delta(q^2-\mu^2)=\int \frac{d^3q}{(2\pi)^3}\frac{1}{2\sqrt{|q|^2+\mu^2}} e^{-ixq}$$
It's clear now that we can write the two point function as in $(1)$, to make manifest the presence of the one particle state the decomposition of $\rho$ will be
$$\rho=\frac{Z}{(2\pi)^3}\delta(q^2)+\rho_{M}$$
(where $M$ stands for multi-particle states) then we will have
$$\langle O(x)O(0)\rangle=Z \ i\Delta_F(x,0)+\int_{0}^{\infty} d\mu^2 \rho_{M}(\mu^2) \ i\Delta_F(x,\mu^2)$$
where
$$i\Delta_F(x,0)=\int \frac{d^3p}{(2\pi)^3}\frac{1}{2|p|} e^{-ixp}$$
As far as i know the same argument and proof (with some tweaks to take in account the polarization degrees of freedom) goes for the photon two point function. For non-Abelian gauge theories it's not possible to have a well-defined $\rho$ by itself because it is necessary to take into account the ghost fields which have the role of canceling out unphysical degrees of freedom of the gluon propagator. That's why i think it's not very practical to use this formalism in the context of non-Abelian gauge fields where it's easier to operate from a path integral approach. | {
"domain": "physics.stackexchange",
"id": 25233,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "quantum-field-theory, photons, interactions, propagator",
"url": null
} |
ros-melodic, ros-kinetic
def loop():
input_1_pub = rospy.Publisher('mswrapper/input_1', Bool, queue_size=10)
rospy.Subscriber('mswrapper/set_speed', Float64, set_speed_callback)
rospy.Subscriber('mswrapper/send_command', String, send_command_callback)
rospy.init_node('asciicom', anonymous=False)
send_command_service = rospy.Service('mswrapper/send_command', SendCommand, handle_send_command)
rate = rospy.Rate(1)
while not rospy.is_shutdown():
input_1_pub.publish(cm.get_input_1())
rate.sleep()
if __name__ == '__main__':
try:
loop()
except rospy.ROSInterruptException:
pass
The error message is quite odd:
ERROR: Unable to send request. One of the fields has an incorrect type:
<type 'exceptions.TypeError'>: 'object of type 'String' has no len()' when writing 'data: 'mtr on''
srv file:
std_msgs/String command
string data
---
std_msgs/String result
string data
As you can see, there is no line number provided, only an error and a printout of my .srv file.
Meanwhile, on the node I'm running this from, I get another error message:
[ERROR] [numbers]: incoming connection failed: unable to receive data from sender, check sender's logs for details
So I have no idea where the error is coming from since I don't get a line number or even a file where this is taking place. Any help would be much appreciated!
Originally posted by Qwertazertyl on ROS Answers with karma: 1 on 2019-07-02
Post score: 0 | {
"domain": "robotics.stackexchange",
"id": 33321,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "ros-melodic, ros-kinetic",
"url": null
} |
c++, beginner, c++11, comparative-review, c++14
are these methods complex?
By "these methods" I think you mean "methods of writing recursively-stated algorithms into code other than naive recursion and unrolling the recursion into a loop".
That's a matter of opinion. Let me put it this way.
I work on a compiler team, and I interview a lot of people. My standard coding question involves writing a simple recursive algorithm on binary trees that is inefficient when written the naive way, but can be made efficient by making a few simple refactorings. If the candidate is unable to write that clear, straightforward, efficient code, that's an easy no-hire.
Where things get interesting is when I ask "suppose you had to remove the left-hand recursion from this tree traversal; how might you do it?"
There are standard techniques for removing recursions. Dynamic programming reduces recursions. You could make an explicit stack and use a loop. You could make the whole algorithm tail recursive and use a language that supports tailcalls. You could use a language with cocalls. You could use continuation passing style and build a "trampoline" execution loop.
Some of these techniques are, from the perspective of the novice, terribly complicated. I ask the question because I want to know what is in the developer's toolbox. | {
"domain": "codereview.stackexchange",
"id": 37510,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, beginner, c++11, comparative-review, c++14",
"url": null
} |
quantum-mechanics, operators, complex-numbers, linear-algebra, observables
Title: Conjugate complex of linear operators in quantum mechanics I'm pretty new to quantum mechanics (I would like to understand it broadly as an hobbyist). I'm trying to reading Principles of Quantum Mechanics by Dirac. I've found difficult to understand a particular piece on p. 28 in the II chapter. It says that:
the conjugate complex of the product of two linear operators equals the product of the conjugate complexes of the factors in reverse order:
$$\overline{\beta} \overline{\alpha} = \overline{\alpha \beta}\tag{$*$} $$
As simple examples of this result, it should be noted that, if $\xi$
and $\eta$ are real, in general $\xi \eta$ is not real. This is an important difference from classical mechanics. However, $\xi \eta + \eta \xi$ is real, and so is $i(\xi \eta - \eta \xi)$. Only when $\xi$ and $\eta$ commute is $\xi \eta$ itself also real. | {
"domain": "physics.stackexchange",
"id": 74943,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "quantum-mechanics, operators, complex-numbers, linear-algebra, observables",
"url": null
} |
opencv, sensor-msgs, tutorial, rosdep, ros-kinetic
Title: sensor_msgs - Can't build tutorial project
I am trying to pass images as messages in a simple ROS project. I'm a complete beginner in ROS and robotics. The tutorial I'm trying to follow is here:
http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython
But I can't get past adding dependencies to the package and building it. Here are the commands I have used to create my project:
mkdir image_pkg_test
cd image_pkg_test/
mkdir -p catkin_ws/src
cd catkin_ws/
catkin_make
source devel/setup.bash
cd src
catkin_create_pkg image_msg_tests sensor_msgs opencv3 cv_bridge rospy roscpp std_msgs
cd ..
catkin_make
The catkin_make command fails with the following message:
CMake Error at /opt/ros/kinetic/share/cv_bridge/cmake/cv_bridgeConfig.cmake:172 (find_package):
Could not find a package configuration file provided by "sensor_msgs" with
any of the following names:
sensor_msgsConfig.cmake
sensor_msgs-config.cmake
Add the installation prefix of "sensor_msgs" to CMAKE_PREFIX_PATH or set
"sensor_msgs_DIR" to a directory containing one of the above files. If
"sensor_msgs" provides a separate development package or SDK, be sure it
has been installed.
Call Stack (most recent call first):
/opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:76 (find_package)
image_msg_tests/CMakeLists.txt:10 (find_package)
-- Configuring incomplete, errors occurred!
However, rospack find sensor_msgs shows:
/opt/ros/kinetic/share/sensor_msgs
So this package is at least partially installed. What am I doing wrong? How can I debug the issue more effectively? | {
"domain": "robotics.stackexchange",
"id": 30321,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "opencv, sensor-msgs, tutorial, rosdep, ros-kinetic",
"url": null
} |
python, neural-network, cross-validation, sampling
(I also opted to keep things as dataframes. You could even use "nested cross-validation," using another CV instead of the train_test_split inside the loop, depending on your needs and computational budget.)
For the question of normalizing data, you don't want to let information from the testing fold affect the training, so normalize within the loop, using only the training set;
https://stats.stackexchange.com/questions/77350/perform-feature-normalization-before-or-within-model-validation | {
"domain": "datascience.stackexchange",
"id": 4597,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, neural-network, cross-validation, sampling",
"url": null
} |
c, array, c99
///
/// @brief Adds a new element to the back of the Dynamic Array.
/// @remarks The capacity will be more than doubled if it is too low.
/// @remarks If needed memory cannot be allocated, the contents of the
/// Dynamic Array will not be changed.
/// @param [in,out] DynArray The Dynamic Array.
/// @param [in] ElemVal Value of the element to be added.
///
#define dynarray_pushback(DynArray, ElemVal) if (true) { \
void *ptrdata = (DynArray).data; \
size_t ncapacity = (DynArray).capacity; \
if ((DynArray).count + 1 > (DynArray).capacity) { \
ptrdata = DYNARRAY_REALLOC( \
(DynArray).data, \
(sizeof *(DynArray).data) * ((DynArray).count + 1) * 2); \
ncapacity = ((DynArray).count + 1) * 2; \
} \
if (ptrdata != NULL) { \
(DynArray).data = ptrdata; \
(DynArray).data[(DynArray).count] = (ElemVal); \
(DynArray).count += 1; \
(DynArray).capacity = ncapacity; \
} \
} else (void)0 | {
"domain": "codereview.stackexchange",
"id": 22509,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c, array, c99",
"url": null
} |
c++, performance, algorithm, interval, priority-queue
// Push the interval onto the queue and it will be sorted according to it's maxError value
queue.push(std::move(i1));
queue.push(std::move(i2));
}
}
return 0;
}
I decided to push( value_type&& value ) instead of push( const value_type &value ) since it's much more efficient (~30% faster). We avoid doing a lot of copies. The drawback is the little trick we have to do for each top() operation since top() returns const value_type &. You have to be really delicate here not to ruin the order of the queue.
You might wonder why I need to have the error array as a class member since I never do anything with it? In my more realistic application I need to subtract the errors from a global error before splitting the intervals in two. So that is the reason.
Really appreciate you feedback on how I can optimize the performance of this in terms of CPU time. Tweak it? Rewrite it from the ground? Trips to the heap are expensive; avoid them if possible. When errors is not too big, the cost of moving a vector is probably similar to the cost of just copying the data.
1) If the dimension of errors is known at compile time and you don't need intervals with different errors sizes to be the same type, then make it a template parameter, and make errors a std::array:
template<size_t Dim>
struct Interval {
// ...
std::array<double, Dim> errors;
// ...
}; | {
"domain": "codereview.stackexchange",
"id": 20096,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, algorithm, interval, priority-queue",
"url": null
} |
black-holes
Title: Effect of black hole mergers on life Would the gravitational energy released in the explosion affect life in any way if it were on a planet close by? You would not want to be very close to a black hole merger. Suppose you have two black holes of the same mass $M$ and $m = GM/c^2$. The radius of each black hole is then $r = 2m$, and the horizon area is $A = 4\pi r^2$ $ = 16\pi m^2$. Two constraints are imposed. The first is that the type-D solutions have timelike Killing vectors, which are isometries that conserve mass-energy, and with the merger the gravitational radiation is in an asymptotically flat region where we can again localize mass-energy. So the initial mass $2M$ is the total energy. The entropy of the two black holes is a measure of the information they contain and that too is constant. So the horizon area of the resulting black hole is the sum of the two horizon areas, $A_f = 2A$ $ = 32\pi m^2$, that has $\sqrt{2}M$ the mass of the two initial black holes. Now with mass-energy conservation
$$
E_t = 2M = \sqrt{2}M + E_{g-wave}
$$
and the mass-energy of the gravitational radiation is $.59M$. That is a lot of mass-energy!
Does this mass-energy in the gravity wave demolish planets? The Einstein field equation is $G_{ab} = (16\pi G/c^4)T_{ab}$, where I am going to as a back of envelope calculation consider the gravitational wave's matter interaction as just its energy density. The $T_{ab}$ then pertains to the interaction of the gravitational wave with a set of masses, and the mass-energy of the gravitational radiation is absorbed by these masses. Let us focus in on the $T^{00} = \rho$ or the mass-energy density. To get this density was consider this mass-energy in the form of a gravity wave in a volume $V = (4\pi/3)r^3$. The $G_{00}$ curvature term is then
$$ | {
"domain": "physics.stackexchange",
"id": 31385,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "black-holes",
"url": null
} |
Substituting $b^2-f(a) = -\frac{b-a}{2b}$, we get $$(b-a)^2 = \frac{4b^2}{4b^2+1}$$
Since $(a,f(a))$ is always on the interior of the parabola, we have $b-a > 0$ if $b > 0$, and $b-a < 0$ if $b < 0$. Therefore $b-a$ should have the same sign as $b$ and we can simplify
$$b-a = \frac{2b}{\sqrt{4b^2+1}}$$
and
$$b^2 - f(a) = -\frac{1}{\sqrt{4b^2+1}}$$
From here, you have the solution in parametric form \begin{align} x &= b - \frac{2b}{\sqrt{4b^2+1}} \\ y &= b^2 + \frac{1}{\sqrt{4b^2+1}} \end{align}
Here is a visualization. Two "bends" occur when $b = \pm \frac12$
Also note that this does not represent one continuous motion in your original proposed problem, as the ball is too large and would get stuck at the peak, where the tangent points are $b = \pm \frac{\sqrt{3}}{2}$
EDIT: A natural question you might ask is, what radius does the ball need to be to not get stuck at the peak? To find out, redo the problem with a radius of $r>0$ to get the parametric solution
\begin{align} x &= b - \frac{2br}{\sqrt{4b^2+1}} \\ y &= b^2 + \frac{r}{\sqrt{4b^2+1}} \end{align} | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9766692339078752,
"lm_q1q2_score": 0.8052266001266644,
"lm_q2_score": 0.824461928533133,
"openwebmath_perplexity": 159.0434363244908,
"openwebmath_score": 0.9899697303771973,
"tags": null,
"url": "https://math.stackexchange.com/questions/2754209/the-smallest-distance-between-any-point-on-a-curve-and-the-parabola-y-x2-is-1"
} |
$$b^2=4R^2\cos^2\left(\frac\alpha2-\frac\gamma2\right)=2R^2(1+\cos(\alpha-\gamma))$$
$$c^2=4R^2\cos^2\left(\frac\alpha2+\frac\gamma2\right)=2R^2(1+\cos(\alpha+\gamma))$$
$$b^2+c^2=4R^2+2R^2(\cos(\alpha-\gamma)+\cos(\alpha+\gamma))=4R^2(1+\cos\alpha\cos\gamma)$$
And this sum achieves maximum obviously for $\gamma=0$, or for $A\equiv A_1$. So for any given side $a$, $b$ and $c$ must be of equal. But you can look at the optimal triangle from sides $b$ and $c$ as well. The only triangle which has no better option is equilateral triangle.
EDIT 2: This “moving vertex” procedure can be repeated infinite number of times and the result is an equilateral triangle! Check excellent proof by Noah Schweber here.
• Note that your last sentence "The only triangle which has no better option is equilateral triangle." is insufficient to imply "The equilateral triangle is better than every other triangle.". See my answer for a sketch of how to do that part rigorously. – user21820 Sep 17 '18 at 17:45
• @Oldboy, I'm studying your topic and curiously I have a problem a little similar in here. The triangle's case was the most problematic for me too. – Na'omi Sep 18 '18 at 14:10
Yes, the maximal sum is the one of the equilateral triangle, that is $9R^2$. | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. Yes\n2. Yes",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9865717476269469,
"lm_q1q2_score": 0.8911645537605937,
"lm_q2_score": 0.903294216466424,
"openwebmath_perplexity": 224.18168856934906,
"openwebmath_score": 0.9784698486328125,
"tags": null,
"url": "https://math.stackexchange.com/questions/2919921/of-all-polygons-inscribed-in-a-given-circle-which-one-has-the-maximum-sum-of-squ"
} |
As far as I know, transitivity is usually the trickiest to prove and as such I shall try of be of use there. We must show: $xRy, yRz \implies xRz$.
${\bf Proof \; Of \; Transitivity::}$ If $xRy$ and $yRz$, then there are integers $a,b$ with $x^2-y^2=5a$ and $y^2-z^2=5b$. Then we have $(x^2-y^2)+(y^2-z^2)=5a+5b$, that is we have $x^2-z^2=5(a+b)$. Thus we have found an integer $c := a+b$ with $x^2-z^2=5c$ but this means $xRz$ ---as desired.
$\langle\langle$ Notice that the above proof made no use of any properties of the number 5. A nifty exercise would be to show the relation $x \ R_k \ y \;:\equiv\; (\exists a \in \mathbb{Z} :: x^2-y^2 = ka)$ is an equivalence relation, for any given $k \in \mathbb{Z}$.
Challenge: We abstracted away from the number 5, can we abstract away from the operation of subtraction? What about squaring and the multiplication?$\rangle\rangle$
Best regards,
Moses | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9752018419665618,
"lm_q1q2_score": 0.8083826568737627,
"lm_q2_score": 0.8289388125473628,
"openwebmath_perplexity": 152.8374561369519,
"openwebmath_score": 0.9192782640457153,
"tags": null,
"url": "https://math.stackexchange.com/questions/407006/5-mid-n2-m2-is-an-equivalence-relation"
} |
electromagnetism, electrostatics, electrons, dipole-moment
Title: Real QM cause of magnetic dipole moment I have read these questions:
Relation between magnetic moment and angular momentum -- classic theory
Why is the electron magnetic moment always parallel to the spin for an electron?
Does a magnetic field do work on an intrinsic magnetic dipole?
Isn't the spin only a synonym for the existence of a magnetic dipole moment and its direction?
Does a magnetic field arise from a moving charge or from its spin, or both?
Relationship Between Magnetic Dipole Moment and Spin Angular Momentum
where it says:
A spinning charged particle constitutes a magnetic dipole. Its magnetic dipole moment μ is proportional to its spin angular momentum S:
μ=γS
the proportionality constant γ is called the gyromagnetic ratio.
Is the magnetic field/force just a relativistic electric field/force or is there a fundamental difference?
where the comments say:
Because in a magnet, the atomic electrons are moving around their respective nuclei constituting a dipole and the dipoles are aligned in same direction to give net magnetic dipole moment.
So one is saying that magnetic dipole moment is caused by spin angular momentum, which is the intrinsic spin of an electron, the other one says that magnetic dipole is cause by electrons orbiting (orbital angular momentum) the nuclei (of course as per QM they are not classically orbiting).
So which one is right?
None of these questions says whether the magnetic dipole moment at QM level is caused by the intrinsic spin of electrons or the bound electrons' (OAM) orbiting (as per QM existing at a certain energy level) around the nuclei.
Question:
Which one is right, is the magnetic dipole moment as per QM caused by the intrinsic spin of electrons or by electrons orbiting (OAM) the nuclei existing around the nuclei at a certain energy level? Spin and orbital angular momentum are two independent contributions to the total angular momentum. The ratio between angular moment and magnetic moment is called the g-factor. For the magnetic moment operator one has $\vec M /\mu_B = g_L \vec L + g_S \vec S$. The electron spin contributes with g=2 and orbital moment with g=1. The expectation value of this operator gives the magnetic moment. $\mu_B$ is the Bohr magneton. | {
"domain": "physics.stackexchange",
"id": 50197,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "electromagnetism, electrostatics, electrons, dipole-moment",
"url": null
} |
optics, fourier-transform, diffraction
Now if we put a Gaussian intensity profile on, but we don't fill the whole grid (as I'm sure you're not, because this is a much more difficult error to not notice), with the $e^{-2}$ intensity contour having a radius of $\frac{1}{10}$ the grid, we get a near field intensity like this:
If you use the above phase and intensity, you get a far field like this (shown as $\sqrt{\mathrm{Intensity}}$):
This basically looks like a perfect diffraction limited spot! Why? Well look at the phase over the region occupied by the beam:
It's just tilt! and its P-V is way below 1 wave. So it won't really do much of anything to the far field.
Now, lets try again, but properly scale the $\rho$ axis when we compute the Coma:
Just what you expect. | {
"domain": "physics.stackexchange",
"id": 3447,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "optics, fourier-transform, diffraction",
"url": null
} |
also known as Inflation Linked fixed income. To understand the uses of the function, let’s consider an example: We can use the function to find out the yield. The current yield formula can be used along with the bond yield formula, yield to maturity, yield to call, and other bond yield formulas to compare the returns of various bonds.The current yield formula may also be used with risk ratings and calculations to compare various bonds. Bank discount yield (or simply discount yield) is the annualized rate of return on a purely discount-based financial instrument such as T-bill, commercial paper or a repo. This example using the approximate formula would be The forward rate formula helps in deciphering the yield curve which is a graphical representation of yields on different bonds having different maturity periods. Step 4: Finally, the formula for the bond price can be used to determine the YTM of the bond by using the expected cash flows (step 1), number of years until maturity (step 2) and bond price (step 3) as shown below. ≤ 0; redemption ≤ 0; frequency is any number other than 1, 2, or 4; or [basis] is any number other than 0, 1, 2, 3, or 4. Interest can be compounded daily, monthly, or annually. The yield of a bond is inversely related to its price today: if the price of a bond falls, its yield goes up. It is calculated to compare the attractiveness of investing in a bond with other investment opportunities. which would return a current yield … To learn more, check out these additional CFI resources: To master the art of Excel, check out CFI’s FREE Excel Crash Course, which teaches you how to become an Excel power user. Example. For example, you could assess an external agency’s services as a candidate source. The annual percentage yield formula would be applied to determine what the effective yield would be if the account was compounded given the stated rate. Step 2: Next, figure out the current market price of the bond. By rearranging the above expression, we can work out the formula for yield to maturity on a zero-coupon bond: $$\text{s} _ | {
"domain": "cig-beauty.com",
"id": null,
"lm_label": "1. YES\n2. YES\n\n",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.967899295134923,
"lm_q1q2_score": 0.8460187398095578,
"lm_q2_score": 0.8740772351648677,
"openwebmath_perplexity": 1506.9982128632864,
"openwebmath_score": 0.41934362053871155,
"tags": null,
"url": "http://www.cig-beauty.com/3zk0oib/icuity.php?id=6797f7-yield-rate-formula"
} |
Concluding:
$$u(x,y)=\frac{x^2y^2}{2} + {c_{1}xy}+c_{3}x+{c_{2}y}+c_{4}$$
Title: Re: Web Bonus Problem –– Week 1
Post by: Victor Ivrii on January 07, 2018, 09:43:14 AM
Wrong again. What are $f$ and $g$?
Title: Re: Web Bonus Problem –– Week 1
Post by: Jaisen Kuhle on January 07, 2018, 09:55:35 AM
Wrong again. What are $f$ and $g$?
Functions dependent on the variable y but constant with respect to x. Other than that, I'm unsure.
Title: Re: Web Bonus Problem –– Week 1
Post by: Victor Ivrii on January 07, 2018, 10:03:05 AM
So $f=f(y)$, $g=g(y)$ and
$$2x^2 + xg(y)+ h(y)=0$$
is an identity. Is it ever possible?
Title: Re: Web Bonus Problem –– Week 1
Post by: Adam Gao on January 07, 2018, 12:12:41 PM
The identity is impossible. In other words, there does not exist any $g(y)$ or $h(y)$ such that the equation $2x^2 + xg(y) + h(y) = 0$ is true for all $x$ and $y$ on the domain of $u(x,y)$.
Proof: | {
"domain": "toronto.edu",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.974042647323258,
"lm_q1q2_score": 0.8158775704842453,
"lm_q2_score": 0.8376199673867852,
"openwebmath_perplexity": 1337.1370880146567,
"openwebmath_score": 0.853485107421875,
"tags": null,
"url": "http://forum.math.toronto.edu/index.php?action=printpage;topic=882.0"
} |
classical-mechanics
Title: Is the principle of conservation of energy violated by a sponge ball When I compress a sponge ball, its potential energy changes. Now after releasing the ball, some of its potential energy [which was added to it during compression] changes to kinetic energy. When the ball comes back to its original position or shape, it stops and there doesn't seem any motion in it. So where does the kinetic energy of the ball go? [ here, I am talking of an ideal ball which is perfectly elastic] An ideal perfectly elastic ball would not stop oscillating between it's compressed and extended form. It will behave like an ideal spring, which as stretching and letting go will oscillate back and fourth until something external stops it - the ideal elastic ball is a 3D version of this.
What you describe is therefore not an ideal elastic ball. You are describing a very real sponge ball with soft tissue that will absorb the vibrations and convert them to heat as well as with surrounding air that will be put in motion and that way also absorbs energy gradually. Furthermore due to the porosity of such a sponge, air molecules will be filling up the gaps in the ball and their motion when they are sucked back inside the ball after it was compressed is also work done and thus energy spent.
All in all, the ball as well as it's contained air will heat up slightly every time you compress it and let it expand to initial state. | {
"domain": "physics.stackexchange",
"id": 45936,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "classical-mechanics",
"url": null
} |
## Definitions:
• $A$ is invertible if there exists a matrix $A^{-1}$ such that $AA^{-1} = A^{-1}A = I$
• The vectors $v_1,\dots,v_n$ are linearly independent if the only solution to $x_1v_1 + \cdots + x_n v_n = 0$ (with $x_i \in \Bbb R$) is $x_1 = \cdots = x_n = 0$.
## Textbook Proof:
Fact: With $v_1,\dots,v_n$ referring to the columns of $A$, the equation $x_1v_1 + \cdots + x_n v_n = 0$ can be rewritten as $Ax = 0$. (This is true by definition of matrix multiplication)
Now, suppose that $A$ is invertible. We want to show that the only solution to $Ax = 0$ is $x = 0$ (and by the above fact, we'll have proven the statement).
Multiplying both sides by $A^{-1}$ gives us $$Ax = 0 \implies A^{-1}Ax = A^{-1}0 \implies x = 0$$ So, we may indeed state that the only $x$ with $Ax = 0$ is the vector $x = 0$.
Fact: With $v_1,\dots,v_n$ referring to the columns of $A$, the equation $x_1v_1 + \cdots + x_n v_n = 0$ can be rewritten as $Ax = 0$. (This is true by definition of matrix multiplication)
Fact: If $A$ is invertible, then $A$ is row-equivalent to the identity matrix.
Fact: If $R$ is the row-reduced version of $A$, then $R$ and $A$ have the same nullspace. That is, $Rx = 0$ and $Ax = 0$ have the same solutions | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9603611563610179,
"lm_q1q2_score": 0.8143552914579283,
"lm_q2_score": 0.8479677526147223,
"openwebmath_perplexity": 114.87142275713684,
"openwebmath_score": 0.8724910616874695,
"tags": null,
"url": "https://math.stackexchange.com/questions/1925062/proof-that-columns-of-an-invertible-matrix-are-linearly-independent"
} |
. . . $=\; \frac{\dfrac{m\Omega^2}{k}} {\dfrac{\sqrt{(k-m\Omega^2)^2 + r^2\Omega^2}}{k}}$
. . . $=\;\dfrac{m\Omega^2}{\sqrt{r^2\Omega^2 + (k-m\Omega^2)^2}}$ | {
"domain": "mathhelpforum.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9881308779050737,
"lm_q1q2_score": 0.8212781157443501,
"lm_q2_score": 0.831143054132195,
"openwebmath_perplexity": 2116.4359016766484,
"openwebmath_score": 0.9445328712463379,
"tags": null,
"url": "http://mathhelpforum.com/algebra/150541-algebraic-manipulation.html"
} |
c#, performance, multithreading, sql-server, entity-framework
It was a bit confusing to me at first as I await practically in every place where the compiler allows it, but possibly the data gets seeded to fast.
I tried to overcome this by being less greedy and added the new ParallelOptions {MaxDegreeOfParallelism = 4} to that parallel loop, peasant assumption was that default connection pool size is 100, all I want to use is 4, should be plenty. But it still fails.
I have also tried to create new DbContexts inside the GetData method, but it still fails. If I remember correctly (can't test now), I got
Underlying connection failed to open
What possibilities there are to make this routine go faster?
var items = allConfigurations.AsParallel().Where(x =>
x.artifact_cleanup_type != null && x.build_cleanup_type != null &&
x.updated_date > DateTime.UtcNow.AddDays(-7)
).ToList();
For each Configuration the DateTime.UtcNow.AddDays() method will be called. By precalculating this value and storing in a variable it will perform better.
var updated = DateTime.UtcNow.AddDays(-7);
var items = allConfigurations.AsParallel().Where(x =>
x.artifact_cleanup_type != null && x.build_cleanup_type != null &&
x.updated_date > updated
).ToList(); | {
"domain": "codereview.stackexchange",
"id": 16477,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c#, performance, multithreading, sql-server, entity-framework",
"url": null
} |
algorithms, graphs, graph-traversal
Title: Mother vertex of a graph I am trying to find all mother vertex in a directed graph.
A mother vertex in a directed graph G = (V,E) is a vertex v such that all other vertices in G can be reached by a path from v.
My Approach:
Do DFS on each vertex and check if all the vertex are reached on each start node.
Time complexity : O(V*(V+E)).
I am looking for any better solutions with better complexity.
Any help would be appreciated. Find the strongly connected components. If the component graph has more than one source, then there are no mother vertices. Otherwise, the mother vertices are those that belong to the single source. | {
"domain": "cs.stackexchange",
"id": 10287,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "algorithms, graphs, graph-traversal",
"url": null
} |
ros, ros-controllers
Comment by philwall3 on 2018-01-05:
Yeah my Moveit config file looks like this. I managed to load the controller, but I can only move the gripper once. Which gripper are you using? Do you have your package available somewhere? I'd love to look at your launch file etc.
Comment by rfn123 on 2018-01-06:
@philwall3 I'm using a simple parallel gripper, and set one finger joint to mimic the other one. How did you move the gripper? I'll see if I can upload it, it's not publicly available in the moment.
Comment by philwall3 on 2018-01-06:
Thanks, that would be nice :)
I have a robotiq 2-finger gripper and I moved it through Rviz with Moveit. Here is a bit more information: https://groups.google.com/forum/#!topic/ros-sig-robot-control/j8hkJGdhNv4
Comment by AndreSpa on 2020-05-11:
I'm trying to make a Gazebo simulation but each time the gripper tries to grasp an object, it slips away form fingers and the grasp is not properly computed. Searching for a solution, i have found that it is necessary to use an effort controller at least for the gripper, and in this way together with the Gazebo Jennifer's grasp plugin, the problem should be fixed. Anyway i've tried this solution and the objects still slip off my gripper. If anyone have some good hints I would appreciate them. Now I'm using position_controllers for the gripper because using effort_controllers/GripperActionController cause the presence of not specified p gain for PID even if these values are specified and the gripper seems not to respond to any input, resulting in the following warning:
aborted solution found but controller failed during execution | {
"domain": "robotics.stackexchange",
"id": 23903,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "ros, ros-controllers",
"url": null
} |
ros, bashrc, shell, ubuntu, setup.bash
To fix this I was able to split the line in two and then restart (relog should work as well).
This seems to be a bug in either python os library or the ROS scripts usage of it as sourcing that file should work even if they are on a single line.
p.s. if your terminal can't find the commands again you can copy/paste PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" to get them back.
Originally posted by Michael Johnson with karma: 154 on 2017-01-11
This answer was ACCEPTED on the original site
Post score: 2
Original comments
Comment by rosrud on 2017-01-11:
Thanks a lot! It worked.
It was important to perform a reboot, after i seperated the line in two rows and everything went well. So was it the python split-function which couldn't handle this? | {
"domain": "robotics.stackexchange",
"id": 26682,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "ros, bashrc, shell, ubuntu, setup.bash",
"url": null
} |
If you are determined to use induction, you have already provided a base case.. the step shouldn't be too crazy, you just need to massage some terms around
Assume $\sum_{i=1}^nF_i = F_{n+2} - 1$, then $$\sum_{i=1}^{n+1}F_i =F_{n+1} + \sum_{i=1}^nF_i = F_{n+1} + \left(F_{n+2} - 1\right)$$ $$= \left(F_{n+1} + F_{n+2}\right) - 1 = F_{n+3} - 1$$
For the base case you will need to use $n=1$ if you wish to prove for all $n\in\mathbb{Z^+}$.
$$\sum_{i=1}^{n}{F_i} = \sum_{i=1}^{1}{F_i} = F_1 = 1$$ and $$F_{n+2}-1=F_3-1=2-1=1$$
Proving the base case.
For the induction step (weak induction suffices, note that weak induction is a special case of strong induction), you can assume the IH (induction hypothesis) for $n$ and prove the identity for $n+1$. Let $L(n)$ be the left-hand side of the identity for $n$ and let $R(n)$ be the right-hand side.
Then | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9728307708274402,
"lm_q1q2_score": 0.8229588409193431,
"lm_q2_score": 0.84594244507642,
"openwebmath_perplexity": 548.6196716321173,
"openwebmath_score": 0.9293877482414246,
"tags": null,
"url": "https://math.stackexchange.com/questions/1401868/fibonacci-proof-question-sum-i-1nf-i-f-n2-1"
} |
quantum-information, measurements, quantum-computer
Title: Understanding measurement based quantum computing I am currently reading M. A. Nielsen's review on Cluster-state Quantum Computation (Nielsen, Michael A. "Cluster-state quantum computation." Reports on Mathematical Physics 57.1 (2006): 147-161.).
My first question concerns the output of a one-bit teleportation, circuit (11) from the paper:
Where $|\psi \rangle=\alpha |0\rangle + \beta |1\rangle$ and $|+\rangle = (|0\rangle + |1\rangle)/\sqrt{2}.$
I don't see why the outcome after the controlled-phase and Hadamrad is equal to:
$$\alpha |++\rangle + \beta |--\rangle = (|0\rangle \otimes H|\psi\rangle+|1\rangle \otimes XH|\psi\rangle)/\sqrt{2}$$
Why isn't $X^m H|\psi \rangle$ the output of the first qubit?
I think if I understand the above I'll be able to see why the output of the following cluster state is $X^{m_2} HZ_{\pm \alpha 2} X^{m_1}HZ_{\alpha 1}|+\rangle$ where $m_1$ and $m_2$ are the outputs of the first and second qubit measurements in the circuits below:
Circuit (14) from Nielsen's paper:
equivalently as: (circuit 15):
Thanks for any clarification you may offer.
Why the outcome after the controlled-phase and Hadamrad is equal to:
$$\alpha |++\rangle + \beta |--\rangle = (|0\rangle \otimes H|\psi\rangle+|1\rangle \otimes XH|\psi\rangle)/\sqrt{2}$$ | {
"domain": "physics.stackexchange",
"id": 25412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "quantum-information, measurements, quantum-computer",
"url": null
} |
terminology, artificial-intelligence, neural-networks
Title: Differences between linear/nonlinear vs. deterministic/nondeterministic neural nets When speaking of neural networks, I don't get the difference between nonlinear and non-deterministic. Basically, both say that the output of something is not directly correlated to the input?
Hope someone can illuminate me. Non linear means that there may be a correlation with the input, but it is not a linear one. A function is say to be linear in some argument (the input) when the ratio result/argument is constant. In your case, it is the ratio output/input. Actually, the mathematical definition is a bit more general.
Non determinism is of a different nature. The input/output relation is said to be non-deterministic when one of several result may occur, without any a priori known cause. This is usually modelelled mathematically, either by using a relation rather than a function, of by considering a function from the input domain to the domain of subsets of the output domain.
For example: if you consider inputs and outputs in the domain of integer, for each integer input, you have a set of possible outputs that are all integers.
When this set always contains only a single element, the function is deterministic, and the set can be replaced by this unique element. | {
"domain": "cs.stackexchange",
"id": 4450,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "terminology, artificial-intelligence, neural-networks",
"url": null
} |
Such expressions can be given a rigorous algebraic interpretation by working in certain quotient rings,$\:\!$ i.e. modulo $\rm\:s^2 = 1.\:$ Namely $\rm\:R[s]/(s^2-1) \cong R[s]/(s-1) + R[s]/(s+1)\cong R^2.\:$ Hence arithmetic in $\rm\:R\:$ with adjoined sign $\rm\:s\:$ is isomorphic to arithmetic of pairs of elements of $\rm\:R,\:$ where the first component denotes the universe where $\rm\:s = 1\:$ and the second where $\rm\:s = -1.\:$
Beware, however, that sometimes such signed expressions denote the set of equations resulting from all possible combinations of signs. In this case one adjoins multiple sign indeterminates $\rm\:s_i\:$ such that $\rm\:s_i^2 = 1.\:$ One often needs to infer from the context which denotation is intended.
-
What's the difference between using $\pm$ and $\mp$ – John May 4 '12 at 11:35
@johnthexiii I've added a detailed explanation. – Bill Dubuque May 4 '12 at 16:55
that was very thorough – John May 4 '12 at 19:24
You can use the facts that $p-k \equiv -k \mod p$. Then you have to decide whether the product is invertible.
- | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9752018369215507,
"lm_q1q2_score": 0.8062108664278135,
"lm_q2_score": 0.8267118004748677,
"openwebmath_perplexity": 438.36423493015747,
"openwebmath_score": 0.9646246433258057,
"tags": null,
"url": "http://math.stackexchange.com/questions/140563/help-manipulating-wilsons-theorem"
} |
8. Solution to Question 8
$$f(x)$$ is continuous on the intervals $$(-\infty , 1)$$ , $$(1,2)$$ and $$(2 , +\infty)$$. We need to find $$a$$ and $$b$$ so that it is also continous at $$x = 1$$ and $$x = 2$$ and therefore continuous on $$(-\infty , +\infty )$$.
$$f(1) = 1$$
$$\lim_{x\to 1^-} f(x) = 1$$
$$\lim_{x\to 1^+} f(x) = a(1)^3+b = a + b$$
The limits from the left and right of $$1$$ must be equal
$$a + b = 1$$ (equation 1)
$$f(2) = 2 + 2 b$$
$$\lim_{x\to 2^-} f(x) = a(2)^3 + b = 8 a + b$$
$$\lim_{x\to 2^+} f(x) = 2 + 2 b$$
The limits from the left and right of $$2$$ must be equal
$$8 a + b = 2 + 2 b$$ (equation 2)
Solve equations (1) and (2) simultaneously to find
$$a = \dfrac{1}{3}$$ and $$b = \dfrac{2}{3}$$ | {
"domain": "analyzemath.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.987568350610359,
"lm_q1q2_score": 0.8186337400377203,
"lm_q2_score": 0.8289388167733099,
"openwebmath_perplexity": 196.91610830663123,
"openwebmath_score": 0.9391714930534363,
"tags": null,
"url": "https://www.analyzemath.com/calculus/practice-tests/calculus-1-questions-A.html"
} |
binary-arithmetic, arithmetic, floating-point, real-numbers, number-formats
Title: Represent a real number without loss of precision Current floating point (ANSI C float, double) allow to represent an approximation of a real number.
Is there any way to represent real numbers without errors?
Here's an idea I had, which is anything but perfect.
For example, 1/3 is 0.33333333...(base 10) or o.01010101...(base 2), but also 0.1(base 3)
Is it a good idea to implement this "structure":
base, mantissa, exponent
so 1/3 could be 3^-1
{[11] = base 3, [1.0] mantissa, [-1] exponent}
Any other ideas? It all depends what you want to do.
For example, what you show is a great way of representing rational numbers. But it still can't represent something like $\pi$ or $e$ perfectly.
In fact, many languages such as Haskell and Scheme have built in support for rational numbers, storing them in the form $\frac{a}{b}$ where $a,b$ are integers.
The main reason that these aren't widely used is performance. Floating point numbers are a bit imprecise, but their operations are implemented in hardware. Your proposed system allows for greater precision, but requires several steps to implement, as opposed to a single operation that can be performed in hardware.
It's known that some real numbers are uncomputable, such as the halting numbers. There is no algorithm enumerating its digits, unlike $\pi$, where we can calculate the $n$th digit as long as we wait long enough.
If you want real precision for things irrational or transcendental numbers, you'd likely need to use some sort of system of symbolic algebra, then get a final answer in symbolic form, which you could approximate to any number of digits. However, because of the undecidability problems outlined above, this approach is necessarily limited. It is still good for things like approximating integrals or infinite series. | {
"domain": "cs.stackexchange",
"id": 3081,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "binary-arithmetic, arithmetic, floating-point, real-numbers, number-formats",
"url": null
} |
$y = x$ if $x \geq -1$.
It also means
$y = -(x + 1) - 1$ if $x + 1 < 0$, i.e. $x < -1$
$y = -x - 2$ if $x < -1$.
So all the points which satisfy these two linear equations will be your solution. | {
"domain": "mathhelpforum.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9884918492405833,
"lm_q1q2_score": 0.8193992618108932,
"lm_q2_score": 0.8289388146603365,
"openwebmath_perplexity": 650.9058713081549,
"openwebmath_score": 0.9012326002120972,
"tags": null,
"url": "http://mathhelpforum.com/calculus/119477-implicit-differentiation-help.html"
} |
organic-chemistry, spectroscopy
Title: Is trans-2-butene IR active with regard to its C=C bond? To be IR active, the vibration of a bond must result in a substantial change in dipole moment. Since trans-2-butene is symmetrical, will the C=C stretch show up on IR?
Something tells me no because if the C=C bond vibrates, there will be no net change in the bond dipole moment, unlike in cis-2-butene. Any polarization one way in trans-2-butene is cancelled out by a polarization in the opposite direction in trans-2-butene. Cis-2-butene, however, has a permanent dipole and any vibration only exacerbates this dipole. The $\ce{C=C}$ stretch will not show in IR. The frequency is $\nu_{\ce{C=C}}=1700~\mathrm{cm^{-1}}$ and has A gerade symmetry (DF-BP86/def2-SVP). There is no change in the dipole moment.
However, some bending frequencies involving the $\ce{C=C}$ double bond will show up. For example $\nu_{\ce{HC=CH}}=963~\mathrm{cm^{-1}}$ with a medium intensity. | {
"domain": "chemistry.stackexchange",
"id": 1815,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "organic-chemistry, spectroscopy",
"url": null
} |
ros, message-filter, message-filters
<depend>sensor_msgs</depend>
<depend>message_filters</depend>
<depend>rclcpp</depend>
<buildtool_depend>ament_cmake</buildtool_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
CmakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(temp_sync)
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(message_filters REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
add_executable(syncer src/temp_sync.cpp)
ament_target_dependencies(syncer rclcpp sensor_msgs message_filters) | {
"domain": "robotics.stackexchange",
"id": 35806,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "ros, message-filter, message-filters",
"url": null
} |
atoms, electronic-configuration, magnetism
Title: What atom is always paramagnetic and why?
Regardless of its electron configuration, it must always be paramagnetic when it's a single, neutrally charged atom:
(A) Carbon (B)
Nitrogen (C) Oxygen (D) Neon (E) Argon | {
"domain": "chemistry.stackexchange",
"id": 8719,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "atoms, electronic-configuration, magnetism",
"url": null
} |
This is merely a definition, and can't be proved via standard algebra. However, two examples of places where it is convenient to assume this:
1) The binomial formula: $(x+y)^n=\sum_{k=0}^n {n\choose k}x^ky^{n-k}$. When you set $y=0$ (or $x=0$) you'll get a term of $0^0$ in the sum, which should be equal to 1 for the formula to work.
2) If $A,B$ are finite sets, then the set of all functions from $B$ to $A$, denoted $A^B$, is of cardinality $|A|^{|B|}$. When both $A$ and $B$ are the empty sets, there is still one function from $B$ to $A$, namely the empty function (a function is a collection of pairs satisfying some conditions; an empty collection is a legal function if the domain $B$ is empty).
• You don't need to appeal to the binomial formula. Anytime you write a polynomial as f(x) = sum a_i x^i you need x^0 = 1 to keep your notation consistent, so you need 0^0 = 1 so that f(0) = a_0. – Qiaochu Yuan Nov 21 '10 at 1:12
• Yes. I think it is reasonable to define $0^0=1$ (because that seems to be the most useful definition) with the caveat that the function $x^y$ on $\mathbb{R}^{+}\!\!\times\mathbb{R}$ is not continuous at $(0,0)$. – robjohn Nov 13 '13 at 11:28
$0^{0}$ is just one instance of an empty product, which means it is the multiplicative identity 1.
I'm surprised that no one has mentioned the IEEE standard for $0^0$. Many computer programs will give $0^0=1$ because of this. This isn't a mathematical answer per se, but it's worth pointing out because of the increasingly computational nature of modern mathematics, so that one doesn't run afoul of anything. | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9407897492587142,
"lm_q1q2_score": 0.8255211713969394,
"lm_q2_score": 0.8774767922879692,
"openwebmath_perplexity": 261.35728347915745,
"openwebmath_score": 0.8884240388870239,
"tags": null,
"url": "https://math.stackexchange.com/questions/11150/zero-to-the-zero-power-is-00-1/11211"
} |
However, if we use basis {[0 1],[1 0]}, that is the same vectors but in different order, that swaps the columns for A:
$$\left[\begin{array}{cc} -1 & 0 \\0 & -1\end{array}\right]$$
In the first example, e1= [1 0], e2= [0 1]. In the second example, e1= [0 1], e2= [1 0].
Same vector space, same linear transformation, same vectors in each basis but, because the order or basis vectors is different, different bases and so different matrices.
Last edited by a moderator: Nov 8, 2008 | {
"domain": "physicsforums.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9702399060540358,
"lm_q1q2_score": 0.8126923223992025,
"lm_q2_score": 0.8376199714402812,
"openwebmath_perplexity": 1022.6258160692017,
"openwebmath_score": 0.6710696220397949,
"tags": null,
"url": "https://www.physicsforums.com/threads/problem-finding-the-transformation-in-this-case.270380/"
} |
quantum-field-theory, supersymmetry, dirac-equation, spinors, dirac-matrices
Title: Converting two component product to four component notation Consider the product of two left Weyl spinors in the notation commonly found in supersymmetry,
\begin{equation}
\chi ^\alpha\eta_\alpha = \chi ^\alpha \epsilon _{ \alpha \beta } \eta ^\beta
\end{equation}
This is equal to,
\begin{equation}
\left( \begin{array}{c}
\chi ^\alpha \\
0
\end{array} \right) ^T\left( \begin{array}{cc}
\epsilon _{ \alpha \beta } & 0 \\
0 & \epsilon ^{ \dot{\alpha} \dot{\beta} }
\end{array} \right) \left( \begin{array}{c}
\eta ^\beta \\
0
\end{array} \right) = \bar{\eta} _L ^\ast \gamma _0 C \chi _L
\end{equation}
where I have used some common spinor identites and defined, $ \eta _L \equiv P _L \eta, \chi _L \equiv P _L \chi $ ($\eta $ and $ \chi$ are now four component spinors). I also use the defintion, $C \equiv i \gamma_0 \gamma _2 $. While I don't think anything is particularly wrong with this derivation, I have never seen a term like this in normal quantum field theory. It there a simpler way to reformulate this to correspond to common expression for such mass terms or is my uncomfort with this term due to my ignorance? Just realize that you can form ordinary Dirac spinors from 2-spinors by using charge conjugation, $i\sigma_2\eta^*$, that gives a right- handed field that can fit in the right-handed slot (forming a 4 component Majorana field)
$$
\Psi_1=\left(\begin{array}{c}\eta \\ i\sigma_2\eta^*\end{array}\right)
$$ | {
"domain": "physics.stackexchange",
"id": 16067,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "quantum-field-theory, supersymmetry, dirac-equation, spinors, dirac-matrices",
"url": null
} |
species-identification, entomology, wasps
Title: Is it possible to identify a worm being carried by a depicted wasp? Wikimedia has a picture of a Ancistrocerus trifasciatus / mason wasp carrying a kind of worm:
Is it possible to tell what exactly kind of worm it is, based only on the above image, number of worm's segments, dots on its skin and a correlation in size to wasp's size (or its feeding preferences)?
I am not the author of the picture, I was not present when it was captures, so I can't provide any more details that are usually helpful in species identification (like moment of day and year, geographic location etc.). The image itself doesn't contain any geolocation data, but from its German description in can be assumed that this was captured somewhere in Germany, Europe. Not too sure but by the general look of it, it seems to be the leaf beetle Chrysomela populi.
This is mostly from the idea that they are very common in Europe and the distribution of the spots on its body. If nothing else it is most likely from the Chrysomela genus.
Here is a link to a description of the species | {
"domain": "biology.stackexchange",
"id": 11878,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "species-identification, entomology, wasps",
"url": null
} |
electrostatics, electric-fields, charge, electromagnetic-induction
Title: Does any object placed in an electric field change the electric field? Lets say I have a point charge of magnitude $+q$, All around it I would have a symmetric radial electric field. Now if I place a neutral object lets say a sphere (doesn't matter insulating or conducting) in this field some distane away from the point charge. A negative charge will be induced on the object near the point charge and a positive charge on the opposite side.
No matter how small this induced charge is, due to the radial distance of the two (positive and negative) there must be an increase/decrease in net electric field on either side of the object and mostly everywhere else too !
I hope that what I am thinking is wrong, because we have not been taught that anything placed in electric field would affect the field itself regardless of it's nature. But I can't figure out what am I thinking wrong, how to solve this dilemma ? If the material placed in the field of the positive charge is a conductor, the field will be distorted and the method to see the field is the image charges method. It will depend on the boundary conditions.
For a grounded conducting sphere
Field lines outside a grounded sphere for a charge placed outside a sphere.
For a non grounded conductor:
This illustration shows a spherical conductor in static equilibrium with an originally uniform electric field. Free charges move within the conductor, polarizing it, until the electric field lines are perpendicular to the surface. The field lines end on excess negative charge on one section of the surface and begin again on excess positive charge on the opposite side. No electric field exists inside the conductor, since free charges in the conductor would continue moving in response to any field until it was neutralized.
If the field is created by a point charge the geometry will change but the physics is the same.
If you have a positive point charge and bring into its field a dielectric, then the field lines will change again depending on constants as :
Figure 6.6.6 Electric field intensity in and around dielectric rod of Fig. 6.6.5 for (a) e_b > a and (b) e_b< e_a.
One can again imagine the geometric changes for a field from a sphere.
In summary, the field distorts with the presence of matter, differently for a conductor or dielectric . | {
"domain": "physics.stackexchange",
"id": 38166,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "electrostatics, electric-fields, charge, electromagnetic-induction",
"url": null
} |
A follow-on question: Is the largest inscribed rectangle also the largest possible rectangle? I.e. could there be larger rectangles where every corner does not touch the sector?
Your result is correct, and leads to a maximum area equal to $\displaystyle{1-\cos(\alpha/2)\over\sin(\alpha/2)}$.
But with a different disposition of the rectangle one can get a greater area. If $\alpha<90°$ you can construct an inscribed rectangle as shown in diagram below on the left. Maximum area occurs when a vertex of the rectangle is at the midpoint of the arc. If $\alpha\ge90°$ you can construct an inscribed rectangle as shown in diagram below on the right. Maximum area occurs when the rectangle is a square.
A tedious calculation gives for maximum areas the expressions shown in the diagram (they should be correct but please check them if you have time). In the first case the area of the rectangle is always larger than your result. In the second case the area is larger only if $\cos(\alpha/2)<3/5$.
• Very nice! I agree with your result. I'm glad that my rectangle at least has some interval where it is the largest, i.e $\alpha > 106.26^\circ$. :) | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9910145733704833,
"lm_q1q2_score": 0.825836812148989,
"lm_q2_score": 0.8333245891029457,
"openwebmath_perplexity": 245.38458214242493,
"openwebmath_score": 0.8822910189628601,
"tags": null,
"url": "https://math.stackexchange.com/questions/2829710/largest-inscribed-rectangle-in-sector"
} |
concurrency, go, tcp
index := rand.Int31n(int32(len(message)))
_, err = conn.Write([]byte(message[index] + "\n"))
if err != nil {
return fmt.Errorf("error: %v", err)
}
buf, err := ioutil.ReadAll(conn)
if err != nil {
return fmt.Errorf("error: %v", err)
}
fmt.Printf("reponse for conn %v: %v", i, string(buf))
return nil
}
func main() {
var wg sync.WaitGroup
nbGoroutines := 3
wg.Add(nbGoroutines)
for k := 0; k < nbGoroutines; k++ {
go func() {
for i := 1; i <= 100; i++ {
err := sendMessage(i)
if err != nil {
fmt.Printf("fail: %v\n", err)
break
}
}
wg.Done()
}()
}
wg.Wait()
}
Other concern
Using redis could be a good idea if there is really a huge amount of entry in your map, but if you face performance issues, profile your code with pprof to make sure that map accessing is the bottleneck
if the client disconnect, you won't be able to send the response, so calling Write(...) will just return an error
Hope this helps ! | {
"domain": "codereview.stackexchange",
"id": 28388,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "concurrency, go, tcp",
"url": null
} |
human-biology, breathing
Our lungs work off of pressure. Specifically our lungs inflate by using "negative pressure" (a word I've always hated). The pressure is not actually negative it is simply lower than the surroundings. Since there is less air in your lungs the air from the atmosphere rushes in because the pressure is higher outside your lungs. This is Boyle's Law (not the pressure outside being higher, but what happens when your lungs expand). Where an increase in Volume means a decrease in Pressure (if all else remains unchanged). In fact plants pull water up using negative pressure.
However to push out the air from our lungs we supply pressure using our muscles that overcomes the outside pressure and forces the air out.
The reason you feel your breathing change is because when that train passes by you correctly observed the strong gust of wind. This gust of wind has some force behind it that normally is not in the air you are breathing from the atmosphere. It has more force which increases the air's velocity. This actually decreases the pressure, but there's no need to get into that here (Bernoulli's).
The reason it feels like your body is "fighting to breath" is because the air is traveling in a direction with some force that you need to overcome by opening up your lungs just enough to "suck" the air in with negative pressure. This is more than the pressure you usually need to produce in order to breath in air that is "still".
What is funny to think about is we don't really have a muscle that "pulls" air in, even though it feels like you are actively doing that. The air actually rushes in on its own. All you do is expand your rib cage, which your lungs are attached to (look up on how, it's actually pretty cool), thereby making inhalation occur.
Now an interesting question for you to ask yourself is why is cold air harder to breathe? | {
"domain": "biology.stackexchange",
"id": 4906,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "human-biology, breathing",
"url": null
} |
signal-analysis, continuous-signals, linear-systems, control-systems
Title: What is the physical interpretation of the dB scale on a bode plot and what is a negative dB? I have no physical interpretation of the Bode plot. What does it mean for a bode plot to have negative dB over its entire duration on the log-scale frequency? Decibels (dB) are used to represent a power ratio with a logarithmic scale. Specifically, a power ratio can be expressed in dB as follows:
$$
R|_{dB} = 10 \log_{10}R = 10 \ \log_{10}\frac{P_1}{P_2}
$$
What does a negative number of dB mean? Manipulate the above equation a bit:
$$
R|_{dB} = 10 \log_{10}R
$$
$$
\frac{R|_{dB}}{10} = \log_{10}R
$$
$$
10^{\frac{R|_{dB}}{10}} = R
$$
If the ratio measured in dB is less than zero, then the exponent on the left hand side will be negative. 10 raised to a negative power results in a number that is in the range $(0, 1)$.
Therefore, if a power ratio measured in dB is less than zero, this implies that, when measured on a linear scale, the ratio is less than one. For a Bode plot, that would mean that the frequency response in question has an amplitude response that is less than unity (for all frequencies, if the Bode plot measured in dB is less than zero everywhere). | {
"domain": "dsp.stackexchange",
"id": 2609,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "signal-analysis, continuous-signals, linear-systems, control-systems",
"url": null
} |
classical-mechanics, electrostatics, gauss-law
Title: Why does Gauss' Law appear to neglect charge outside the Gaussian surface in symmetrical special cases Suppose I have an infinitely tall solid cylinder with radius $R$ and charge density $\rho$.
Then, a portion of that cylinder is enclosed by a Gaussian surface, in this case another infinitely long cylinder with radius $r,\quad r<R$, as shown: | {
"domain": "physics.stackexchange",
"id": 76602,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "classical-mechanics, electrostatics, gauss-law",
"url": null
} |
human-anatomy
In the wrist, you can have palmar flexion, dorsiflexion (extension), ulnar flexion (abduction) and radial flexion (adduction) (Teachmeanatomy).
In the ankle, you can have plantar flexion, dorsiflexion (extension), inversion (inward rotation, adduction) and eversion (outward rotation, abduction). (ScienceDirect).
In the shoulder and hip, raising a limb to the same side as the limb is, is abduction (lateral extension) and raising it to the opposite side is adduction.
Moving the thumb toward the palm (in the same plane as palm) is flexion (adduction) and moving it away from it is extension (abduction).
You can read about flexion and extension and other movements here: Types of Body Movements (BCcampus) | {
"domain": "biology.stackexchange",
"id": 10018,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "human-anatomy",
"url": null
} |
Can the sum of two distinct factorizations of a number be equal?
Given two distinct factorizations of a positive integer with the same number of factors (not necessarily prime or all distinct), must the sums of the respective sets of factors also be distinct? This question arises frequently in puzzles of the KenKen or Killer Sudoku type. I have found no obvious counter examples searching by hand. For the purpose at hand, the numbers being factored may be limited to less than 1000, say.
• For example 1*2*2 = 1*4 or 1*1*2*3 = 1*6 – shadow Jul 13 '18 at 6:16
• @shadow (1) If we allow 1's, does that not make the problem trivial? (2) The question asks for the factorizations to have the same number of factors. – Therkel Jul 13 '18 at 6:44
• There is a well known puzzle based exactly on this fact. – Federico Poloni Jul 13 '18 at 7:16
• When restricted to just 2 factors, the sum is indeed unique, as $x + a/x$ is an increasing function for $a > 0, x > \sqrt a$ (which one of the factors has to be). But when 3 or more factors are allowed, this is broken, as dxiv has demonstrated. – Paul Sinclair Jul 13 '18 at 16:33
The sums can match, for example $\,144 = 8 \cdot 6 \cdot 3 = 4 \cdot 4 \cdot 9\,$ with $\,8+6+3=4+4+9\,$.
[ EDIT ] Also, $144 = 2\cdot8\cdot9 = 3 \cdot 4 \cdot 12$ with $\,2+8+9=3+4+12\,$, so multiple such factorizations may exist for the same number.
Morevover, there exist such with the same sum e.g. $\,1680 = 4 \cdot 20 \cdot 21 = 5 \cdot 12 \cdot 28 = 7 \cdot 8 \cdot 30\,$ with $\,4+20+21=5+12+28=7+8+30\,$. | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9532750387190132,
"lm_q1q2_score": 0.8044641290772687,
"lm_q2_score": 0.8438950947024556,
"openwebmath_perplexity": 865.4181661030708,
"openwebmath_score": 0.6150012612342834,
"tags": null,
"url": "https://math.stackexchange.com/questions/2849303/can-the-sum-of-two-distinct-factorizations-of-a-number-be-equal/2849312"
} |
python, performance, programming-challenge, python-2.x, palindrome
Title: Palindromes that are sum of consecutive squares I have been working on a Project Euler: 125, which took me ages to solve. The problem and source are cited below
The palindromic number 595 is interesting because it can be written as
the sum of consecutive squares: 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 +
12^2.
There are exactly eleven palindromes below one-thousand that can be
written as consecutive square sums, and the sum of these palindromes
is 4164. Note that 1 = 0^2 + 1^2 has not been included as this problem
is concerned with the squares of positive integers.
Find the sum of all the numbers less than 10^8 that are both
palindromic and can be written as the sum of consecutive squares.
I firstly tried to figure out if there were some pattern in the square sums, however i found none. My solution ended sadly up being brute force one.
1) Generate all possible palindromes
2) Generate all possible values
of square numbers
1) Is fairly fast however 2) takes (understandably) ages. The code works and gives the correct answer, but it takes ages. I think the problem is memory.
Is there any faster way of checking whether a palindrome can be written as a sum of consecutive squares?
Any other suggestions for my code are also welcome. Python 2.7
from math import floor
from itertools import count
def palindromic_square_summable(limit):
"""
Finds all numbers p, such that
p = n^2 + (n+1)^2 + ... + m^2
and p is a palindrome. Eg 595 or 55.
"""
dic = get_quadratic_sums(limit)
pal = all_palindromes(2, limit)
total = 0
for key in pal:
try:
dic[key]
total += key
except:
pass
return total | {
"domain": "codereview.stackexchange",
"id": 19978,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, performance, programming-challenge, python-2.x, palindrome",
"url": null
} |
ros
Title: how to use more than one marker types
I want to visualize 3 seperate markers to be visualized in rviz until same line group donot appear again. I found that by doing line_list.points.clear() and line_list.colors.clear() i can make given line visualize until another line donot appears so that at one time only one marker of that name exist. But i want to display more than one marker and line like that so that whenever the same name of marker arrives the previous marker is vanished. I tried below program but donot works:
void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
pcl::PointCloud<pcl::PointXYZRGB> output;
pcl::fromROSMsg(*input,output); | {
"domain": "robotics.stackexchange",
"id": 26878,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "ros",
"url": null
} |
of y(t). MATLAB has a built-in sinc function. Has the form [ry,fy,ffilter,ffy] = FouFilter(y, samplingtime, centerfrequency, frequencywidth, shape, mode), where y is the time. To illustrate determining the Fourier Coefficients, let's look at a simple example. Daileda Fourier transforms. The Fourier Transform is a method to single out smaller waves in a complex wave. A Phasor Diagram can be used to represent two or more stationary sinusoidal quantities at any instant in time. $\endgroup$ – Robert Israel Jan 19 '17 at 21:33. Basic theory and application of the FFT are introduced. 1 Frequency Analysis Remember that we saw before that when a sinusoid goes into a system, it comes out as a sinusoid of the same frequency,. The component of x ( t ) at frequency w , X ( w ) , can be considered a density: if the units of x ( t ) are volts, then the units of X ( w ) are volt-sec (or volt/Hz if we had been using Hz. The Fourier transform is sometimes denoted by the operator Fand its inverse by F1, so that: f^= F[f]; f= F1[f^] (2) It should be noted that the de. at the MATLAB command prompt. In practice, when doing spectral analysis, we cannot usually wait that long. The Fast Fourier Transform (FFT) is an efficient way to do the DFT, and there are many different algorithms to accomplish the FFT. The Discrete Fourier Transformation (DFT): Definition and numerical examples — A Matlab tutorial; The Fourier Transform Tutorial Site (thefouriertransform. The Laplace transform is used to quickly find solutions for differential equations and integrals. prior to entering the outer for loop. Always keep in mind that an FFT algorithm is not a different mathematical transform: it is simply an efficient means to compute the DFT. Amyloid Hydrogen Bonding Polymorphism Evaluated by (15)N{(17)O}REAPDOR Solid-State NMR and Ultra-High Resolution Fourier Transform Ion Cyclotron Resonance Mass Spectrometry. The coe cients in the Fourier series of the analogous functions decay as 1 n, n2, | {
"domain": "agenzialenarduzzi.it",
"id": null,
"lm_label": "1. Yes\n2. Yes",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.981735721648143,
"lm_q1q2_score": 0.8678929482289481,
"lm_q2_score": 0.8840392878563336,
"openwebmath_perplexity": 1078.9064028815767,
"openwebmath_score": 0.8407778143882751,
"tags": null,
"url": "http://qjsk.agenzialenarduzzi.it/fourier-transform-of-cos-wt-in-matlab.html"
} |
c++, c++11, template, constructor
Title: Simple c++ triple class to mimic pair for use with uniform initialization I'm trying to create a simple triplet class, but the more I look at the implementation of std::pair the more I feel like I'm missing important details. What I have feels "too simple". I am aware of std::tuple and other options, but the use case is to be able to use uniform initialization -- so we can make certain assumptions / ignore complications (?)
I am restricted to c++11, none of those beautiful c++14/17 magical unicorns added.
/// keeping class and test in self-contained file {test.cpp}
/// Compile: g++ -o test -std=c++11 test.cpp
#include <iostream>
#include <vector>
/// class definition
template <class T1, class T2, class T3>
struct triple {
/// q1
typedef T1 first_type;
typedef T2 second_type;
typedef T3 third_type;
T1 first;
T2 second;
T3 third;
/// q2
triple() : first(), second(), third() {}
triple(const T1 &f, const T2 &s, const T3 &t)
: first(f), second(s), third(t) {}
/// q3
template<class U1, class U2, class U3>
triple(const triple<U1, U2, U3> &t)
: first(t.first), second(t.second), third(t.third) {}
triple(const triple<T1, T2, T3> &t) = default;
triple(triple<T1, T2, T3> &&t) = default;
}; | {
"domain": "codereview.stackexchange",
"id": 26208,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, c++11, template, constructor",
"url": null
} |
newtonian-mechanics, energy-conservation, momentum, conservation-laws
When $m\ne M$ and $V_i=0$, the above solution gives $v_i=0$. While all the kinetic energy of $m$ is given to $M$ with this solution, it is the very boring trivial solution of transferring zero kinetic energy. So let's modify the situation I analyzed by making the very reasonable requirement that $m$ needs to start with some amount of kinetic energy. From above, this shows we cannot transfer 100% of the kinetic energy now (except for the $m=M$ case) and furthermore that this is the only case where we need to consider this modification, as the solution above shows $v_i$ will be non-zero if $V_i$ is non-zero).
$$ \frac{1}{2}mv_i^2 + 0 = \frac{1}{2}mv_f^2 + \frac{1}{2}MV_f^2 \quad \Rightarrow \quad V_f^2 = \frac{m}{M}(v_i^2 - v_f^2)$$
$$ mv_i + 0 = mv_f + MV_f \quad \Rightarrow \quad V_f = \frac{m}{M}(v_i - v_f)$$
combining, and using our new requirement $v_i \ne 0$ so that I can divide by it:
$$ \frac{m^2}{M^2}(v_i - v_f)^2 = \frac{m}{M}(v_i^2 - v_f^2) $$
$$ \frac{m}{M}\left(1 - \frac{v_f}{v_i}\right)^2 = 1 - \frac{v_f^2}{v_i^2} $$
Defining $A=\frac{v_f}{v_i}$, note that the fraction of kinetic energy transferred is | {
"domain": "physics.stackexchange",
"id": 16545,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "newtonian-mechanics, energy-conservation, momentum, conservation-laws",
"url": null
} |
newtonian-mechanics, energy, work, potential-energy, conventions
Title: Does energy have a sign? Quantities like position and time allow us to place our origin anywhere, but can the same be said for energy? I was thinking about the way we have defined the quantity gravitational potential, and for any finite distance from a 'planet' or a body, an abject would be said to have negative gravitational potential, conveying that a negative amount of work is done (in bringing the object from 'infinity' to that position, but this seems impossible as negative energy does not seem to physically exist (as far as I know). So, does negative energy really exist, or does it not (implying that negative work done is just another mathematical argument)?
Edit: The primary reason I ask this question is because I was wondering whether negative work done is fundamentally different from negative debts (when talking about money), or are they just the same - a mathematical convenience. To be honest, signs don't exist. Energies don't exist. They are merely methods or models or descriptions invented for us to describe forces, tendencies, absorption of radiation, impacts, vibrational motions, directions etc. So, does negative energy exist? We can just invent it, like you just described for the potential energy, so yes.
In some situations a sign describes nothing but the size of values (when it doesn't matter where the origin is, such as with potential energies with arbitrarily chosen reference points),
in other situations the sign describes the mathematical act of adding or subtracting (like heat absorbed or expelled),
while in yet other situations signs describe directions on a predefined axis (your axis defines forward, so a speed moving you backwards is negative).
Etc.
A sign is a mathematical invention that means different things in different contexts, depending on what we need to do.
conveying that a negative amount of work is done
A "negative amount of work" belongs to the 2nd bullet point above. Work being negative just means that energy is leaving (mathematically subtracted) the object. The negative sign is here nothing more than mathematical. | {
"domain": "physics.stackexchange",
"id": 50239,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "newtonian-mechanics, energy, work, potential-energy, conventions",
"url": null
} |
go, go-enrichment
Title: How to run enrichment analysis of protein functional annotation? I have a lot of protein clusters. I want to perform an enrichment analysis of their functional annotations, against reference datasets or list of genes I select.
More precisely: a method yields cluster of proteins. I want to decide, for each cluster (which is a set of proteins identifiers), if it holds meaning regarding the proteins it contains, by comparing the annotations found in the cluster and the annotations found in common or specific datasets.
Initially, I used DAVID, which compute the GO annotations from the protein list, then perform the enrichment analysis against common datasets.
However, DAVID suffer of the following drawbacks:
since I didn't find any other way to use it, I'm limited by the web interface and its limitations (number of genes, url size, number of request/day).
automation over the web interface is a hacky script.
The team behind seems to offer a way to run DAVID in-house (allowing, hopefully, to relax the limitations), but I can't find any way to download the database from their website.
What are the alternative ways to get enrichment analysis over proteins in a reliable and automated way ? DAVID depend on a couple of databases from the Gene Ontology Consortium, Reactome, KEGG,... most of them are accessible via Bioconductor. To perform an enrichment analysis you can have a look at the tutorial of the several packages in Bioconductor that do this.
Some of the most important for analyzing enrichment in GO terms are topGO, goseq, GOstats. I would also recommend GOSemSim if you want to compare between GO to focus on a specific GO terms.
Other important packages are the fgsea to test any kind of gene set (which is similar to the one hosted by the Broad Institute), gsva for enrichment analysis by sample, limma has some functions for functional enrichment too. Piano, GSCA, SPIA are also worth mentioning.
Bioconductor has "standard" data sets of the expressions of some cells, like airway and ALL frequently used in vignettes. They are not reference data sets because there isn't a reference expression for a cell of an organisms. It depends on the type of cell, the experiment, the conditions... | {
"domain": "bioinformatics.stackexchange",
"id": 216,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "go, go-enrichment",
"url": null
} |
java, performance, algorithm, ai, sudoku
/* Finds the next empty cell */
int[] nextCell = findNextCell();
/* checks if the cell is not empty, if so we have finished */
if (solution[nextCell[0]][nextCell[1]] != null) {
return true;
}
/**
* Converts the coords of the cell into a number between 1-81
* representing the cell then it uses that to get the ArrayList of
* domains from a HashMap, key = int of cell (1-81)
*/
int cell = (nextCell[0] * 9) + 1 + nextCell[1];
// for (int i=0;i<domains.size();i++){
// domainSave.put(i+1, domains.get(i));
// }
//domainSave.putAll(domains);
String mainDomain = domains[cell];
String domain = mainDomain;
/**
* Loops through all available domains in the ArrayList and attempts to
* use them calls isSafe to ensure that the value can be used in the row
* / column / box without clashing with constraints.
*
* If it can be used within constraints, assign it and then empty the
* relevant domains as long as the domains all have possible values,
* call this method to solve the next cell if not remove the value and
* start again.
*
* No remaining options = backtrack
*/
for (int i=0;i<domain.length();i++){
int value = Integer.valueOf(domain.substring(i, i+1));
if (isSafe((Integer) value, nextCell, solution)) {
String[] domainSave = domains.clone();
//domainSave = (HashMap) domains.clone();
solution[nextCell[0]][nextCell[1]] = value;
emptyDomains(nextCell); | {
"domain": "codereview.stackexchange",
"id": 13590,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, performance, algorithm, ai, sudoku",
"url": null
} |
reinforcement-learning, q-learning, sutton-barto, temporal-difference-methods
= \sum_{S_{t+1}} Q_t(S_{t+1},a) ~p(S_{t+1}|S_t,A_t)
$$
Thus, in expectation we have the sampling of $Q_t(S_{t+1},a)$ and $Q_t(S_{t+1},a)\frac{\delta_{a,A_{t+1}}}{b(a|S_{t+1})}$ under policy $b$ give the same result.
Thus we thus we see that in the special case of $n=1$ we in fact do not need to sample at all. Note that sampling unnecessarily we increase variance.
Furthemore, causality and the fact that
$$
\mathbb E_b [ \frac{\pi(A_k|S_k)}{b(A_k|S_k)}] = 1
$$
give us something more general. We have
$$
\mathbb E_b[ \rho_{t:T-1} R_{t+k}] =
\mathbb E_b[ \rho_{t:t+k-1} R_{t+k}]
$$
This can be used to modify the n-step off policy expression so as to only include sampling when necessary and reduce the variance. | {
"domain": "ai.stackexchange",
"id": 3629,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "reinforcement-learning, q-learning, sutton-barto, temporal-difference-methods",
"url": null
} |
statistical-mechanics, mathematics, approximations
As for why it works when $x$ is much smaller than $x_0$, even when $x$ is itself large: the first-term truncation of the Taylor series is considered to be accurate when $x_0-x\approx x_0$ (for functions that are locally analytic at $x_0$, the error on this approximation is given by Taylor's theorem). This is equivalent to saying that $x$ is much smaller than $x_0$. If it's not obvious to you why this is, consider rewriting $x_0-x$ as $x_0\left(1-\frac{x}{x_0}\right)$. If $x_0\left(1-\frac{x}{x_0}\right)\approx x_0$, then it follows that $1-\frac{x}{x_0}\approx 1$, meaning that $\frac{x}{x_0}\ll 1$.
As long as the radius of convergence of the Taylor series about $x_0$ is nonzero, there will always be some finite region around $x_0$ where the quadratic term is unimportant. This follows directly from the definition of differentiability.
The definition of the derivative is as follows:
$$f'(x_0)=\lim_{h\to0}\frac{f(x_0+h)-f(x_0)}{h}$$ | {
"domain": "physics.stackexchange",
"id": 65128,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "statistical-mechanics, mathematics, approximations",
"url": null
} |
recursion, rust, tail-recursion
If this is not tail recursive, can someone kindly explain why it is not, and how this could be made one?
I wrote this in Rust because I was following an algorithm tutorial made for Rust programming language, but my question is language agnostic.
Thank you. This is Not Tail-Recursive, Because You Recurse from a Closure
The return traverse_directory(...) statement would be tail-recursive from traverse_directory, but it is being called from a closure. That’s equivalent to calling from a named helper function. The function and the anonymous closure within it could still be mutually-recursive if the closure were tail-called, and get most of the same optimizations, but that is not the case. It is called from a for_each, and must create a new stack frame each time so that the loop can resume.
(I deleted my original first paragraph, because your use of return from a closure is correct, just not tail-recursion.)
Rust Does Not Guarantee Tail-Call Optimization Anyway
Tail-recursive algorithms in Rust might compile to unoptimized calls that eat up the stack, and you will not be warned when this happens. I’ve generally had good results with functions that have moved or dropped all their local values that aren’t references when they tail-recurse, and therefore have no need to keep anything alive during the tail-call and drop it after, but this will not be reliable in Rust, unless the language changes.
Indeed, testing with Godbolt shows that this call is not optimized as a tail-call.
Graydon Hoare has called his announcement “one of the saddest posts ever written on the subject,” and later said that this was one of the times he was outvoted on the design.
The List Should be the Return Value
It does not make much sense to require the caller to pass in &mut Vec::new() so the function can fill it. Just create the Vec yourself and pass it back. This allows callers to chain and compose this function, and is one less thing that can go wrong with the public API. | {
"domain": "codereview.stackexchange",
"id": 44752,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "recursion, rust, tail-recursion",
"url": null
} |
Section 23. • The theorem requires additional conditions. The two are separated by about 5 times the fundamental frequency , and for each we see clearly the shape of the Hann window's Fourier transform. Proof of Using Fourier Coefficients for Root Mean Square Calculations on Periodic Signals Sompop Poomjan, Thammarat Taengtang, Keerayoot Srinuanjan, Surachart Kamoldilok, Chesta Ruttanapun and Prathan Buranasiri Department of Physics, Faculty of Science King Mongkut's Institute of Technology Ladkrabang, Chalongkrung Rd. A Fourier transform is then used to convert the waveform of the reflected signal into its frequency domain, resulting in a reasonably accurate measurement of the reflection coefficient of an individual discontinuity, even in the presence of other discontinuities at other distances. Any temporal function can be represented by a multiplicity of basis sets. 875inincrementsof1=8. Usually the DFT is computed by a very clever (and truly revolutionary) algorithm known as the Fast Fourier Transform or FFT. The total running time is 5 seconds. I've coded a program, here is the details, Frequen. 1) 2 n =1 The coefficients are related to the periodic function f (x) by definite integrals: Eq. Signals and Systems 7-2 The continuous-time Fourier series expresses a periodic signal as a lin- ear combination of harmonically related complex exponentials. Electric circuits like that of Figure 1 are easily solved in the source voltage is sinusoidal (sine or cosine function). Consider a square wave with a period of T. Regression at the Fourier Frequencies. A Fourier transform is then used to convert the waveform of the reflected signal into its frequency domain, resulting in a reasonably accurate measurement of the reflection coefficient of an individual discontinuity, even in the presence of other discontinuities at other distances. Summary of Fourier Optics 1. Periodic Functions []. This means a square wave in the time domain, its Fourier transform is a sinc function. The complex exponentials can be represented as a linear combination of sinusoidals (Euler's Fo. Your solution (i) We have f (t)= 4 − π 2 0 C k with period T α. Skip navigation Fourier Transform, Fourier Series, and frequency spectrum - Duration: 15:45. | {
"domain": "svc2006.it",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9918120917924487,
"lm_q1q2_score": 0.8286426725613073,
"lm_q2_score": 0.8354835350552603,
"openwebmath_perplexity": 481.19136003622214,
"openwebmath_score": 0.8666015863418579,
"tags": null,
"url": "http://ihbk.svc2006.it/fourier-transform-of-periodic-square-wave.html"
} |
python, game
while True:
if P1_turn:
while not victory:
pos = input("Player 1, enter target: ")
row = pos[0]
row = ord(row)-65
if len(pos) > 2:
col = (pos[1]+pos[2])
else:
col = pos[1]
row = int(row)
col = int(col) - 1
target = opponnent_board[row][col]
ship_hit = target
target = str(ship_hit)
if target in check_ships:
print("Hit")
else:
print("Miss")
opponnent_board[row][col] = "X"
destroyed = True
for y in opponnent_board:
if destroyed:
for x in y:
if x == ship_hit:
destroyed = False
break
else:
break
if destroyed:
if target in check_ships:
print("{0} DESTROYED.".format(target))
victory = True
for y in opponnent_board:
if victory:
for j in y:
if j not in check_ships:
victory = True
else:
victory = False
break
if victory:
print("PLAYER 1 WINS")
sys.exit()
P1_turn = False
P2_turn = True
break
elif P2_turn:
while not victory:
pos = input("Player 2, enter target: ")
row = pos[0]
row = ord(row)-65
if len(pos) > 2:
col = (pos[1]+pos[2])
else:
col = pos[1]
row = int(row)
col = int(col) - 1
target = game_board[row][col]
ship_hit = target
target = str(ship_hit)
if target in check_ships:
print("Hit")
else:
print("Miss")
game_board[row][col] = "X"
destroyed = True
for y in game_board:
if destroyed:
for x in y:
if x == ship_hit:
destroyed = False
break
else:
break
if destroyed:
if target in check_ships:
print("{0} DESTROYED.".format(target)) | {
"domain": "codereview.stackexchange",
"id": 23877,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, game",
"url": null
} |
console, linux, assembly, x86
Understand environment variables
In Linux, there is a difference between shell variables and environment variables. Environment variables are what your program is searching, but the LINES and COLUMNS variables are shell variables that are set by the shell but typically not as environment variables. See this question for details.
Use an IOCTL
The reliable way to get the screen dimensions in Linux is to invoke the TIOCGWINSZ ioctl call. In C++ it would might look like this:
#include <sys/ioctl.h>
#include <unistd.h>
#include <iostream>
int main () {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
std::cout << "lines = " << w.ws_row << "\ncolumns = " << w.ws_col << '\n';
}
So we just need to put that into assembly language. First, some constants:
sys_ioctl equ 0x10
STDOUT_FILENO equ 1
TIOCGWINSZ equ 0x5413
Now the winsize structure:
struc winsize
.ws_row: resw 1
.ws_col: resw 1
.ws_xpixel: resw 1
.ws_ypixel: resw 1
endstruc
section .bss
w resb winsize_size ; allocate enough for the struc
Finally the call:
mov edx, w
mov esi, TIOCGWINSZ
mov edi, STDOUT_FILENO
mov eax, sys_ioctl
syscall
; do stuff with window size...
If the call was successful (that is, if eax is 0) then the winsize structure is filled in with the current dimensions. | {
"domain": "codereview.stackexchange",
"id": 36352,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "console, linux, assembly, x86",
"url": null
} |
cc.complexity-theory, np-hardness, quantum-computing, np
Title: If BQP contains NP, does this mean that P=NP? There is a question raised by Scott Aaronson in one of his papers [1]: "Could we show that if NP ⊆ BQP, then the polynomial hierarchy collapses?". Assuming the answer is yes, and it is also know that if P=NP then PH collapses to the 0th level.
Based on the above two statements, I would like to ask if BQP contains NP, does this imply that P=NP?
[1] http://www.scottaaronson.com/papers/bqpph.pdf No, $\mathrm{NP}\subseteq\mathrm{BQP}$ is not known to imply $\mathrm P=\mathrm{NP}$. Even the stronger assumption $\mathrm{NP}\subseteq\mathrm{BPP}$ is not known to yield a deeper collapse than $\mathrm{NP}=\mathrm{RP}$ and $\mathrm{PH}=\mathrm{ZPP^{RP}}=\mathrm{BPP}$; in particular, it is not even known to imply $\mathrm{NP}=\mathrm{coNP}$. (However, all these implications are likely true by virtue of their premises being false.) | {
"domain": "cstheory.stackexchange",
"id": 3291,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "cc.complexity-theory, np-hardness, quantum-computing, np",
"url": null
} |
supersymmetry, group-theory, lattice-model, poincare-symmetry
Title: Is it possible to put a supersymmetric theory on a lattice? Several lattice models have recently been shown to display emergent supersymmetry at length scales long enough that the lattice can be coarse-grained into a continuum (e.g. see here, here, and here). Could a lattice model display exact supersymmetry even at the lattice length scales? Clearly the answer is no, because the lattice breaks the Poincare subgroup of the supersymmetry group down to $S \times \mathbb{R}$, where $S$ is the lattice's space group and the $\mathbb{R}$ corresponds to time translational invariance.
According to this answer, the supersymmetry Lie supergroup $G$ corresponding to 3+1D SUSY with $N$ fermionic generators and no additional internal symmetries is Inonu-Wigner contracted $OSP(4/N)$. Does there exist a Hamiltonian, defined on a lattice with space group $S$, with a symmetry Lie supergroup $H < G$ such that the bosonic part of $H$ is $S \times \mathbb{R}$ and the fermionic part of $H$ is nontrivial? (In other words, I want to reduce the full supersymmetry supergroup $G$ down to a sub-supergroup $H$, such that the bosonic part of $G$ reduces from the Poincare group down to a lattice space group (times time translation), but without reducing the fermionic part all the way down to the identity, which would eliminate the supersymmetry entirely.) This seems to me like the natural way to restrict supersymmetry to a lattice. " Could a lattice model display exact supersymmetry even at the lattice length scales? Clearly the answer is no."
Yes, you are correct. In general, it is not possible. However, in some theories with extended supersymmetry, it is possible to maintain an exact nilpotent scalar supercharge exactly on the lattice. One can view this construction as follows - 1) take a continuum theory with sufficient number of supersymmetries, 2) twist the theory to get a topological field theory. | {
"domain": "physics.stackexchange",
"id": 96421,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "supersymmetry, group-theory, lattice-model, poincare-symmetry",
"url": null
} |
type-theory, ct.category-theory, dependent-type, equivalence, homotopy-type-theory
Theorem 9.4.16: If $A$ and $B$ are categories then the function $$(A = B) \to (A \simeq B)$$ (defined by induction on the identity functor) is an equivalence of types.
The theorem tells us that the Univalence Axiom gives us a sort of cateory theorist's dream: equivalent categories are equal.
You ask whether you can reduce the Univalence axiom to a statement about categories. Attempts using skeletons won't work because there isn't a good way to say "skeletal". We could ask whether Theorem 9.4.16 implies the Univalence axiom. This is not going to be the case, as far as I can see, because a category has a $1$-type (groupoid) of objects and a $0$-type (set) of morphisms, so theorem 9.4.16 amounts to something like the Univalence axiom for 1-types, only. | {
"domain": "cstheory.stackexchange",
"id": 2910,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "type-theory, ct.category-theory, dependent-type, equivalence, homotopy-type-theory",
"url": null
} |
Now in looking at the graph of ##f^{-1}\left(x\right)##, the range is restricted to the interval ##\left[0,∞\right)##, which is what makes it a function by having one input to exactly one output.
So my question: When we find the inverse relation of a function, there are no restrictions. The domains and ranges swap. When we find the inverse function of a function, restrictions apply which allow the inverse to be a function.
Where and how does this "restriction take place"? Does it happen because when we swap x and y then solve for y, we execute an operation that is the opposite of the main operation of ##f\left(x\right)##? And in this case, the main operation for ##f^{-1}\left(x\right)## is the square root, which in its nature has restrictions, so the inverse graph itself is then restricted by the main inverse function operator? Or does the restriction take place before we even find the inverse, by restricting the domain of ##f\left(x\right)##?
#### Attachments
• Screen Shot 2018-06-23 at 4.10.14 PM.png
22.2 KB · Views: 346
andrewkirk
Homework Helper
Gold Member
I like your analysis. It had not occurred to me that a function is a special case of a relation. I had thought of them as completely separate beasts.
I think the statement that starts 'When we find the inverse function of a function ...' causes trouble. The 'the' needs to be 'an', because a function that is not injective will have many inverse functions. An inverse function is a function that, when composed with the original in either order, gives the identity function on the relevant domain. It follows that any function that is non-injective on a subset of its domain that has an image of infinite cardinality has infinitely many different inverse functions. | {
"domain": "physicsforums.com",
"id": null,
"lm_label": "1. YES\n2. YES\n\n",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9553191284552529,
"lm_q1q2_score": 0.8119937281871696,
"lm_q2_score": 0.849971181358171,
"openwebmath_perplexity": 584.2387796509345,
"openwebmath_score": 0.8378942012786865,
"tags": null,
"url": "https://www.physicsforums.com/threads/inverse-functions-vs-inverse-relations.950182/"
} |
electrochemistry, electrolysis
Title: Calculating the energy used during electrolysis of NaCl Suppose we are getting the necessary $\ce{Na}$ for $\ce{HCl}$ out of $\ce{NaCl}$. We need to end up with $V = 100~\mathrm{m^3}$ of $\ce{HCl}$ at standard conditions. Assuming that $\ce{HCl}$ is an ideal gas, and using the ideal gas law, I found there are $$ n = 4272~\mathrm{mol}$$ of matter in those $100~\mathrm{m^3}$. The applied voltage to the cell is $$U = 3.6~\mathrm{V}$$ and the current utilization factor is $\mu=88\%$.
Then we also have Faraday's law of electrolysis:
$$\frac{m}{M}=\frac{q}{F}$$(the oxidation state of chlorine is $z=1$).
Since there is a constant voltage being applied to the cell, the energy used in this reaction is
$$E = \frac{UI \Delta t}{0.88} = \frac{Uq}{0.88} = 470~\mathrm{kWh}$$
However the correct answer is $$E=48.9~\mathrm{kWh}.$$ Where did I go wrong? Perhaps it's something blatantly obvious. Let's reformulate your equations a little bit.
The ideal gas law was just fine:
$$n = \frac{p V}{RT}$$
A problem lies in your formulation of Faradays law.
We are not interested in masses, but in moles. Of course it is interchangeable by using the molar mass, but why make things complicated. As a rule of thumb you can remember for such tasks: Convert from mass in the beginning and convert to mass in the end (if needed). Nearly all equations in "the middle" are based on the concept of fixed relationsships between the number of involved particles and all equations are much easier to understand if you use $n$.
Faradays law means that the overall charge is just the product of charge per particle times the number of particles: | {
"domain": "chemistry.stackexchange",
"id": 6359,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "electrochemistry, electrolysis",
"url": null
} |
Let $\mathcal{S}(n)$ be the running time of foo and $\mathcal{T}(n)$ be the running time of bar. We have the following system of recursive equations:
$$\left\{ \begin{array}{r c l} \mathcal{S}(n) & = & \mathcal{S}(n-1) + \mathcal{T}(n) + \Theta(1)\\ \mathcal{T}(n) & = & \mathcal{S}(n-1) + \mathcal{T}(n/2) + \Theta(1) \end{array} \right.$$
By isolating $\mathcal{T}(n)$ in the first and $\mathcal{S}(n)$ in the second, we obtain:
$$\left\{ \begin{array}{r c l} \mathcal{S}(n-1) & = & \mathcal{T}(n) - \mathcal{T}(n/2) + \Theta(1)\\ \mathcal{T}(n) & = & \mathcal{S}(n) - \mathcal{S}(n-1) + \Theta(1) \end{array} \right.$$
I will now solve for $\mathcal{T}$, with a similar reasoning holding for $\mathcal{S}$. Since:
$$\mathcal{S}(n-1) = \mathcal{T}(n) - \mathcal{T}(n/2) + \Theta(1)$$
We also have that:
$$\mathcal{S}(n) = \mathcal{T}(n+1) - \mathcal{T}((n+1)/2) + \Theta(1)$$
Therefore the first equation of our original system becomes: | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9697854138058637,
"lm_q1q2_score": 0.8123116286497583,
"lm_q2_score": 0.8376199694135332,
"openwebmath_perplexity": 544.2378339818264,
"openwebmath_score": 0.7040607333183289,
"tags": null,
"url": "https://cs.stackexchange.com/questions/68896/time-complexity-of-functions-that-call-each-other"
} |
python, pandas, machine-learning
I do thank you for the helpful reminder that ravel() means "flatten".
(Some other comments, like "fit scaler ... transform",
just say what the code says and could be elided.)
nit, typo: "expect" --> "except"
comment could be code
# Use a test size of 0.1665 as this will give us 380 test samples which is the same as the number of matches in a season
This is a helpful comment and I thank you for it.
(Oddly, final digit is 5 rather than 7.)
It makes an assertion about how our data relates to the real world.
Assertions are more believable when they are code instead of prose.
Usually comments start out being true, but then they bit-rot
as the code changes and the comments don't keep up.
Consider rephrasing this as
matches_per_season = 380
test_size = matches_per_season / len(y)
assert round(test_size, 4) == 0.1667
But wait!
Perhaps confusingly, perhaps conveniently,
train_test_split behaves differently according to
whether the parameter is in the unit interval or is a large integer.
We could more clearly convey Author's Intent by simply saying
matches_per_season = 380
assert len(y) == 6 * matches_per_season # dataset covers six seasons
..., ..., ..., ... = train_test_split(X, y, test_size=matches_per_season, ... )
magic number
skf = StratifiedKFold(n_splits=10) | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, pandas, machine-learning",
"url": null
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.