text stringlengths 49 10.4k | source dict |
|---|---|
c#, reflection, extension-methods, immutability
var immmutableUpdateCtor =
typeof(T)
.GetConstructor(new[] { typeof(ImmutableUpdate) });
var updates =
from property in obj.ImmutableProperties()
let getsUpdated = property.Name == selectedProperty.Name
select
(
property,
getsUpdated ? newValue : property.GetValue(obj)
);
return (T)Activator.CreateInstance(typeof(T), new ImmutableUpdate(updates));
}
public static void Bind<T>(this ImmutableUpdate update, T obj)
{
// todo - this could be cached
var isCalledByImmutableUpdateCtor = new StackFrame(1).GetMethod() == ImmutableUpdateConstructor(typeof(T));
if (!isCalledByImmutableUpdateCtor)
{
throw new InvalidOperationException($"You can call '{nameof(Bind)}' only from within an ImmutableUpdate constructor.");
}
foreach (var (property, value) in update)
{
GetBackingField<T>(property.Name)?.SetValue(obj, value);
}
}
private static FieldInfo GetBackingField<T>(string propertyName)
{
var backingFieldBindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;
var backingFieldName = $"<{propertyName}>k__BackingField";
return typeof(T).GetField(backingFieldName, backingFieldBindingFlags);
}
private static IEnumerable<PropertyInfo> ImmutableProperties<T>(this T obj)
{
return
typeof(T)
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.GetSetMethod() is null);
}
private static ConstructorInfo ImmutableUpdateConstructor(Type type)
{
return type.GetConstructor(new[] { typeof(ImmutableUpdate) });
}
} | {
"domain": "codereview.stackexchange",
"id": 32951,
"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#, reflection, extension-methods, immutability",
"url": null
} |
$$d_Y\bigl(g(x),g(x’)\bigr)\le d_Y\bigl(g(x),f(p_n’)\bigr)+ d_Y\bigl(f(p_n),f(p_n’)\bigr)+ d_Y\bigl(f(p_n’),g(x’)\bigr)<\varepsilon.$$ Hence $g$ is uniformly continuous on $X$. | {
"domain": "linearalgebras.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9822877044076956,
"lm_q1q2_score": 0.8053711363093135,
"lm_q2_score": 0.8198933293122506,
"openwebmath_perplexity": 31.14999051140337,
"openwebmath_score": 0.9794890284538269,
"tags": null,
"url": "https://linearalgebras.com/baby-rudin-chapter-4b.html"
} |
ros
Title: Basic Robot Methods? (turn_degrees, drive_cm, dist traveled)
How best to achieve the following basic robot methods in ROS2 (foxy and galactic both):
turn_degrees() --> pub /cmd_vel until /odom heading change achieved?
drive_cm() --> pub /cmd_vel until /odom x change achieved?
log distance traveled by robot --> (sum of absolute value of average of left and right encoder changes)?
Or are there ROS2 packages that implement these as services or actions?
Originally posted by RobotDreams on ROS Answers with karma: 327 on 2021-11-03
Post score: 0 | {
"domain": "robotics.stackexchange",
"id": 37084,
"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
} |
c#, strings, recursion, tree
var textLines = layout(element, depth).Split(new[] {Environment.NewLine }, StringSplitOptions.None);
var textIndent = string.Join(string.Empty, indent);
foreach (var textLine in textLines) {
builder.AppendLine(string.Format("{0}{1}", textIndent, textLine));
}
}
public class TreeNode<T>
{
private List<TreeNode<T>> children = new List<TreeNode<T>>();
public TreeNode(T value)
{
Value = value;
}
public static TreeNode<T> Empty { get { return new TreeNode<T>(default(T)); }}
public T Value { get; set; }
public IEnumerable<TreeNode<T>> Children { get { return children.ToArray(); }}
public TreeNode<T> Parent { get; private set; }
public TreeNode<T> Root { get { return Parent == null ? this : Parent.Root; }}
public static implicit operator T(TreeNode<T> node) { return node.Value; }
public static implicit operator TreeNode<T>(T value) { return new TreeNode<T>(value); }
public TreeNode<T> Add(TreeNode<T> child) {
// TODO check null, check family (is self, ancestor, descendant, or child of other parent) ..
children.Add(child);
child.Parent = this;
return child;
}
public TreeNode<T> Remove(TreeNode<T> child) {
// TODO check null, check family (is child) ..
if (children.Contains(child)) {
children.Remove(child);
child.Parent = null;
}
return child;
}
}
public static class TreeNode
{
public static TreeNode<T> Create<T>(T value) { return new TreeNode<T>(value); }
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; } | {
"domain": "codereview.stackexchange",
"id": 34518,
"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#, strings, recursion, tree",
"url": null
} |
javascript, html
Selector strings are terse, flexible, and correspond directly to CSS selectors, and so are probably the preferred method of selecting elements. (You can change to this method in other places in the code as well, such as when you define selectOption)
Since you want to check if any of the inputs have an empty value, rather than pushing unexamined values to an array, use Array.prototype.some instead:
if ([...document.querySelectorAll('#form input')].some(input => !input.value)) {
e.preventDefault();
document.getElementById("errors").innerHTML = '<div class="alert alert-danger" role="alert"><p><strong>Please complete all the Temperatures and Humidity Checks</strong></p></div>';
}
Variable names You have:
roomInputsId: This is an element, not an ID; better to remove the "Id" suffix. But since it's an element, not multiple elements: the s makes it sound plural when it's not. Maybe call it roomInputsContainer instead?
RoomSelectId: Similar to above, but it's also using PascalCase. Ordinary variables in JS nearly always use camelCase - reserve PascalCase for classes, constructors, and namespaces, for the most part.
roomOptions: Like the first - this is a single element, so it shouldn't be plural
Overall If this is for something professional that needs to be maintained, and you have to do this sort of thing frequently on pages (dynamically creating, appending, removing, validating elements), I'd consider using a standard framework instead; they're a bit more maintainable in the long run over multiple developers and multiple years. | {
"domain": "codereview.stackexchange",
"id": 39382,
"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": "javascript, html",
"url": null
} |
c, multithreading, dining-philosophers, c11
Title: Dining Philosophers using C11 threads I wanted to try multithreading out in C, so I did Dining Philosophers using C11 threads with the approach of having one of the philosophers left-handed. Any suggestions?
#include <stdio.h>
#include <threads.h>
#include <stdlib.h>
#define NUM_THREADS 5
struct timespec time1;
mtx_t forks[NUM_THREADS];
typedef struct {
char *name;
int left;
int right;
} Philosopher;
Philosopher *create(char *nam, int lef, int righ) {
Philosopher *x = malloc(sizeof(Philosopher));
x->name = nam;
x->left = lef;
x->right = righ;
return x;
}
int eat(void *data) {
time1.tv_sec = 1;
Philosopher *foo = (Philosopher *) data;
mtx_lock(&forks[foo->left]);
mtx_lock(&forks[foo->right]);
printf("%s is eating\n", foo->name);
thrd_sleep(&time1, NULL);
printf("%s is done eating\n", foo->name);
mtx_unlock(&forks[foo->left]);
mtx_unlock(&forks[foo->right]);
return 0;
} | {
"domain": "codereview.stackexchange",
"id": 17654,
"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, multithreading, dining-philosophers, c11",
"url": null
} |
evaporation
Title: How to calculate rate of evaporation of water? How can I calculate how fast water will evaporate, if I know its temperature, the relative humidity, temperature, and speed of air flowing over it? Or if that's not enough information, what formulas would I need to use? First, let me say that you should not use the formula on engineeringtoolbox. Indeed, you can write
$$J=K (c-c_s),$$
where $J$ is the evaporation flux, $c$ the concentration of water vapor in the air and $c_s$ the concentration of saturated water vapor at the given temperature.
The problem is that generally, $c$ will not be constant over the position (if you blow dry air into the $x$ direction, then $c=0$ at $x=0$ and $c\rightarrow c_s$ as $x$ increases. Moreover, the coefficient $K$ (the mass transfer coefficient) will generally be position-dependent as well, being larger at the leading edge of your surface than at the trailing edge.
Depending on the size of your system and exactly how you blow, the formula from engineeringtoolbox can be orders of magnitude off. Unfortunately, there is no simple answer; there are thick books with math and empirical formulas for all kinds of common cases. ETB does not tell you what assumptions were made, so do not use it.
The most import parameters are:
incoming air properties: humidity, temperature, speed (as you already mentioned);
length (in the flow direction) of the evaporating surface;
whether the surface is approximately a thin plate parallel to the incoming stream or a wet area on a larger surface. In the latter case, the air speed will depend on the distance to the surface, so you have to define where you measure the air speed.
whether the gas is flowing through a duct (e.g. between two parallel plates) or whether there is infinite space above the wet surface;
the temperature of the evaporating surface, which may cool down due to evaporative cooling. | {
"domain": "physics.stackexchange",
"id": 91402,
"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": "evaporation",
"url": null
} |
beginner, python-3.x, file-system
Similarly, child2.text = path.split('/')[-1] should become child2.text = path.name
find_directories_snapshots_rcs
Again, this will be cleaner with pathlib instead of os.
There's a lot of code here, and I'm hitting review fatigue, so I won't touch on everything:
This pattern (some_list = list[:list]) doesn't work - you can't slice using a list, unless there is something I'm missing about how you've defined this.
I suspect that you'll be better off not using list comprehensions and just looping over all_directories once to accumulate your other lists.
Avoid using the names of builtins (all) as variable names
Final thoughts
I don't think you need to use subprocess ("df -k | grep root | awk '{print $5}'"); I think you can just use os.statvfs (I'm on a Windows machine, so I can't test). | {
"domain": "codereview.stackexchange",
"id": 39652,
"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": "beginner, python-3.x, file-system",
"url": null
} |
prasadreddykotapati2 is waiting for your help. where ai is the component of vector a in the direction of ei. In the upcoming discussion, we will focus on Vector product i.e. If θ \ \theta θ is obtuse, then the dot product is negative. ) cosθ = OL/OB. The dot product gives us a very nice method for determining if two vectors are perpendicular and it will give another method for determining when two vectors are parallel. Review of Dot Product Properties. ‖ The Dot Product and Its Properties. = The length of a vector is defined as the square root of the dot product of the vector by itself, and the cosine of the (non oriented) angle of two vectors of length one is defined as their dot product. The Vector Product of two vectors is constructed by taking the product of the magnitudes of the vectors. The dot product is thus characterized geometrically by[6]. ⟩ This and other properties of the dot product are stated below. ^ 1. $\endgroup$ – hardmath Feb 24 '16 at 16:14 The norm (or "length") of a vector is the square root of the inner product of the vector with itself. Properties such as the positive-definite norm can be salvaged at the cost of giving up the symmetric and bilinear properties of the scalar product, through the alternative definition[13][3]. Scalar = vector .vector ⋅ u Tutorial on the calculation and applications of the dot product of two vectors. {\displaystyle \mathbf {a} \cdot \mathbf {a} } N(A) is a subspace of C(A) is a subspace of The transpose AT is a matrix, so AT: ! , CBSE Previous Year Question Papers Class 10, CBSE Previous Year Question Papers Class 12, NCERT Solutions Class 11 Business Studies, NCERT Solutions Class 12 Business Studies, NCERT Solutions Class 12 Accountancy Part 1, NCERT Solutions Class 12 Accountancy Part 2, NCERT Solutions For Class 6 Social Science, NCERT Solutions for Class 7 Social Science, NCERT Solutions for Class 8 Social Science, NCERT Solutions For Class 9 Social Science, NCERT Solutions For Class 9 Maths Chapter 1, NCERT Solutions For Class 9 Maths Chapter 2, NCERT Solutions For Class 9 Maths Chapter 3, NCERT Solutions For Class 9 Maths Chapter | {
"domain": "lockxx.com",
"id": null,
"lm_label": "1. YES\n2. YES\n\n",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9441768557238083,
"lm_q1q2_score": 0.804394116012974,
"lm_q2_score": 0.8519528000888387,
"openwebmath_perplexity": 568.259313630565,
"openwebmath_score": 0.8666537404060364,
"tags": null,
"url": "https://lockxx.com/xom8445/45af58-properties-of-dot-product"
} |
python, python-3.x, array, matrix
My command on terminal would just be:
python3 d11.py < d11_input.txt
Points that I suspect could have huge improvements:
1 - I treated the hourglass as a square and then, made two elements A21 and A23 zero. Maybe there is a more elegant way to do that.
2 - I used a three nested loop in order to generate all hour glasses a 6x6 matrix can have. Not good in terms of big O notation. Is there a way better?
3 - As you might see, when generating all possible hour glasses, each one was repeated three times which means I am calculating things that I do not need. Nonetheless, I was not able to fix this and also keep the rest of the code working. Here you see a picture of the "problem" involving repeated data that I am talking about:
I hope I will learn with your comments. Thanks in advance =) Generating all possible hourglasses
Don't :-) It's a lot of memory and processing churn.
A more efficient alternative is to write a function that takes as parameters a matrix and the starting position of an hourglass, and return the sum of values at the appropriate relative positions:
def compute_hourglass_sum(matrix, top, left):
return sum(matrix[top][left:left+3]) + ...
The caller is responsible for passing parameters to valid hourglasses.
As for the unnecessary recomputing of sums of overlapping hourglasses, given the small sizes of hourglass dimensions, I don't think it's worth it to come up with something more clever.
However, if the dimensions became significantly bigger, then that would indeed make sense. Perhaps prefix sums would be useful for that. I suggest to check out the concept, it's very interesting stuff.
Processing the input
In make_matrix it's not so great that the input parameter is named matrix when in fact it's just unprocessed text. I'd name it input. And then the local final_matrix variable could be renamed to simply matrix.
And I would rewrite the function with a list comprehension:
return [map(int, line.split()) for line in input] | {
"domain": "codereview.stackexchange",
"id": 27298,
"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, array, matrix",
"url": null
} |
error-correction, stabilizer-code
Title: How to understand the disjointness of a stabilizer code? I'm reading The disjointness of stabilizer codes and limitations on fault-tolerant logical gates and trying to understand the disjointness of a stabilizer code.
Does anyone have any intuition about or experience with the concept of disjointness of a stabilizer code?
For example, what is the disjointness of the Shor $ [[9,1,3]] $ code? I quickly threw together some code to play with this.
Define the Shor code and logical operator representatives
shorgen = np.array([
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
], dtype=int)
n = 9
m = 8 | {
"domain": "quantumcomputing.stackexchange",
"id": 4749,
"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": "error-correction, stabilizer-code",
"url": null
} |
python, python-2.x
Prob_S1_part1 = with_b(Muestra_part1[S1], Observa_part1[S1], s1)
Prob_S2_part1 = with_b(Muestra_part1[S2], Observa_part1[S2], s2)
Prob_S3_part1 = with_b(Muestra_part1[S3], Observa_part1[S3], s3)
Prob_S4_part1 = with_b(Muestra_part1[S4], Observa_part1[S4], s4)
Prob_S1_part2 = with_b(Muestra_part2[S1], Observa_part2[S1], s1)
Prob_S2_part2 = with_b(Muestra_part2[S2], Observa_part2[S2], s2)
Prob_S3_part2 = with_b(Muestra_part2[S3], Observa_part2[S3], s3)
Prob_S4_part2 = with_b(Muestra_part2[S4], Observa_part2[S4], s4)
Prob_S1_part3 = with_b(Muestra_part3[S1], Observa_part3[S1], s1)
Prob_S2_part3 = with_b(Muestra_part3[S2], Observa_part3[S2], s2)
Prob_S3_part3 = with_b(Muestra_part3[S3], Observa_part3[S3], s3)
Prob_S4_part3 = with_b(Muestra_part3[S4], Observa_part3[S4], s4) | {
"domain": "codereview.stackexchange",
"id": 23644,
"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-2.x",
"url": null
} |
string-theory, supersymmetry
Title: Is there a SQCD gluino string, similar to the gluon string? A gluon string is a particular kind of open string terminated in two particles which are the sources for the field. Is it possible to have a similar arrangement with gluinos? At first glance, it seems to me that such object could not exist, or at least not as an extended object: you need bosons to mediate between the two sources, and you need bosons to build a classical field extended in space.
On other hand, the fact that in the world-sheet such structure is just an object with fermionic coordinates --and without bosonic coordinates-- could be telling that you can build it, but it is not extended in space, just a point. But I have never read of such description, so surely intuition is failing here. In SQCD, you can get "gluino hadrons", mesons and baryons in which the gluino is one of the constituent fermions. (Also a gluinoball, a glueball with some gluinos mixed in.) So you could have a "gluino string", but in the opposite sense to what you want: it's two gluinos, at the ends of a gluon string.
Another possibility would be a topological defect in a gluino condensate. Maybe you could get this in N=2 SQCD, with monopoles at the ends. | {
"domain": "physics.stackexchange",
"id": 1381,
"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": "string-theory, supersymmetry",
"url": null
} |
ros, memory, roscpp
Title: Ros memory usage
I i'm trying to use an old c++ library of a task planner in ROS. I've tested the library outside ROS and it's works fine. Using Valgrind I can see a lot of memory leaks, but it's Ok, as I say everything works and pass sucessfully the test battery.
The problem is when I call the same functions in a ROS node: the program crashes when I delete the memory of a pointer
*** Error in `./devel/lib/task_executor/task_executor': free(): invalid next size (fast): 0x0000000001a0cf40 ***
Using Valgrind it gives me this last error before the stacktrace
valgrind: m_mallocfree.c:304 (get_bszB_as_is): Assertion 'bszB_lo == bszB_hi' failed.
valgrind: Heap block lo/hi size mismatch: lo = 160, hi = 0.
This is probably caused by your program erroneously writing past the
end of a heap block and corrupting heap metadata. If you fix any
invalid writes reported by Memcheck, this assertion failure will
probably go away. Please try that before reporting this as a bug.
And literally the only changes between the compilation that works and the other that crashes is that in the first I use Make manually and in the other I compile with catkin.
I'm missing something about ROS and his memory usage and I need some orientation.
Thanks.
ps. The code of the function that contains the delete
bool parse(string domain, string problem){
if(domain.length() == 0){
ROS_INFO_STREAM( "Error: Undefined domain file." << endl);
return true;
}
if(problem.length() == 0 ){
ROS_INFO_STREAM( "Error: Undefined problem file." << endl);
return true;
} | {
"domain": "robotics.stackexchange",
"id": 23479,
"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, memory, roscpp",
"url": null
} |
thermodynamics
From this we can conclude that for larger $m$ the rate of cooling will be slower. Note however that greater mass usually also implies greater $A$, thereby somewhat offsetting the mass-effect.
Following in the footsteps of @probably_someone (comments) I'll explore $\frac{A}{m}$ for the following shape:
With $m=\rho V$ and $\rho$ (density) a constant we can evaluate $\frac{A}{V}$ instead:
$$V=\frac{\pi D^2}{4}H+\frac12 \frac 43 \pi \Big(\frac{D}{2}\Big)^3=\frac{\pi D^2 H}{4}+\frac{\pi D^3}{12}=\frac{\pi D^2(3H+D)}{12}$$
$$A=\frac12 4\pi \Big(\frac{D}{2}\Big)^2+2 \pi \Big(\frac{D}{2}\Big)H=\frac12 \pi D^2+\pi D H=\frac{\pi D(2H+D)}{2}$$
This gives us a result for $\frac{A}{V}$ of:
$$\frac{A}{V}=\frac{6(2H+D)}{D(3H+D)}$$
Here $D$ is a constant and only $H$ increases with $m$. Because the coefficient $3$ in the denominator, instead of $2$ in the numerator, as $H$ increases $\frac{A}{V}$ does indeed decrease which points to lower cooling rate, as expected.
Another consideration. Assume we half-fill the flask with boiling water. Due to steam formation it is reasonable to expect the entire flask to reach approximately the same temperature. In that case, again as an approximation, the total surface area $A$ could be used. | {
"domain": "physics.stackexchange",
"id": 85703,
"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": "thermodynamics",
"url": null
} |
optimization, artificial-intelligence, approximation
One way to approximate a shape by a union of convex regions is by calculating a Voronoi diagram. There's undoubtedly a rich literature on this that I unfortunately don't know much about.
Another thing that might help is routing the agents to each Voronoi cell starting from the farthest, so that you can take advantage of the fact that they will cover cells on the way. A primitive that could help with this is creating a graph that has a node per cell and edges between neighboring cells representing straight line moves, which you then run Dijkstra's algorithm on. If a cell has already been visited, you remove that node from the graph.
Ultimately the best solution is going to be strongly dependent on the geometry of the region, the distance that the agents can move, and how many agents there are. For example, if the number of agents is very small compared to the number of cells to visit, the problem is relatively easy. | {
"domain": "cs.stackexchange",
"id": 19583,
"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": "optimization, artificial-intelligence, approximation",
"url": null
} |
slam, navigation, rosmake, ros-electric
Title: rgbdslam with electric install
I have used ROS fuerte and find it's too hard to make rgbdslam,so I use ROS electric now.
I follow the tutorial(http://www.ros.org/wiki/rgbdslam),and I use Ubuntu 11.10 OS.
From my first time to rosmake --rosdep-install rgbdslam,all package have compiled :
,but when start linking ,there are many error to remind me cannot find ***.so file
Linking CXX executable ../bin/rgbdslam
/usr/bin/ld: cannot find -lg2o_stuff/usr/lib/i386-linux-gnu/libQtOpenGL.so
so,I modify rgbdslam/CMakeFile.txt ,and set libs,finally CMakeFile.txt turn into this :
(line 177)
SET(LIBS_LINK rgbdslam GL GLU g2o_types_slam3d g2o_solver_cholmod g2o_solver_pcg g2o_solver_csparse g2o_core cxsparse g2o_stuff QtOpenGL ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY} ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${OpenCV_LIBS}) | {
"domain": "robotics.stackexchange",
"id": 10393,
"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": "slam, navigation, rosmake, ros-electric",
"url": null
} |
quantum-mechanics, quantum-information, algorithms
$$\scriptsize \frac{1}{2}((\frac{1}{\sqrt{2}}0 + \frac{1}{\sqrt{2}}1)(\frac{1}{\sqrt{2}}0 - \frac{1}{\sqrt{2}}1)-(\frac{1}{\sqrt{2}}0 + \frac{1}{\sqrt{2}}1)(\frac{1}{\sqrt{2}}0 + \frac{1}{\sqrt{2}}1)-(\frac{1}{\sqrt{2}}0 - \frac{1}{\sqrt{2}}1)(\frac{1}{\sqrt{2}}0 - \frac{1}{\sqrt{2}}1)+(\frac{1}{\sqrt{2}}0 - \frac{1}{\sqrt{2}}1)(\frac{1}{\sqrt{2}}0 + \frac{1}{\sqrt{2}}1)) $$
$$ = \frac{1}{2}(\frac{1}{2}(00-01+10-11)-\frac{1}{2}(00+01+10+11)-\frac{1}{2}(00-01-10+11)+\frac{1}{2}(00+01-10-11)) $$
$$ = \frac{1}{4}(00-01+10-11-00-01-10-11-00+01+10-11+00+01-10-11) $$
$$ = \frac{1}{4}(-11-11-11-11) $$
$$ = -11 ? $$ | {
"domain": "physics.stackexchange",
"id": 38455,
"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, quantum-information, algorithms",
"url": null
} |
a visual tool to help you investigate this question yourself. Interpolation par la méthode de Lagrange Liste des forums; Rechercher dans le forum. Akima1DInterpolator. Polynomial Interpolation; Piece-wise Interpolation; Spoiler: Natural Cubic Spline is under Piece-wise Interpolation. 1 Chapter 05. ; domain specifies the domain of the data from which the InterpolatingFunction was constructed. i think the bicubic interpolation is more likely 3rd-order Hermite polynomial than 3rd-order Lagrange polynomial interpolation. The function values and sample points , etc. derive Lagrangian method of interpolation, 2. Returns the same object type as the caller, interpolated at some or all NaN values. String interpolation is a process substituting values of variables into placeholders in a string. Purpose Native implementation of the Lagrange interpolation algorithm over finite fields. Shannon Hughes author of LAGRANGE'S INTERPOLATION METHOD FOR FINDING f(X) is from London, United Kingdom. rv variable stands for return value. The function utilizes the rSymPy library to build the interpolating polynomial and approximate the value of the function f for a given value of x. Try changing a data point in the data to see how the interpolation function changes. The call to test_p_L described in Exercise 25: Implement Lagrange's interpolation formula and the call to graph described above should appear in the module's test block. By construction, on. Interpolation is the process of deriving a simple function from a set of discrete data points so that the function passes through all the given data points (i. The Lagrange’s Interpolation formula: If, y = f(x) takes the values y0, y1, …, yn corresponding to x = x0, x1, …, xn then, This method is preferred over its counterparts like Newton’s method because it is applicable even for unequally spaced values of x. In the mathematical field of numerical analysis, a Newton polynomial, named after its inventor Isaac Newton, is the interpolation polynomial for a given set of data points in the Newton form. | {
"domain": "asainfo.it",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9759464513032269,
"lm_q1q2_score": 0.8408151546867461,
"lm_q2_score": 0.8615382058759129,
"openwebmath_perplexity": 897.424159526933,
"openwebmath_score": 0.5778627395629883,
"tags": null,
"url": "http://zgoe.asainfo.it/lagrange-interpolation-python.html"
} |
ros, force, uwsim
Originally posted by Javier Perez with karma: 486 on 2016-10-04
This answer was ACCEPTED on the original site
Post score: 0
Original comments
Comment by ZYS on 2016-10-05:
Hi,
I met a weird condition which is that while I give the thruster a constant input, for example, -25, the speed of the AUV along its trajectory will increase then decrease and then increase then decrease again.
Here are the speed of AUV:
0, 0.000812425, 0.357602, 1.42693, 1.48798, 0.739892, ....
Comment by ZYS on 2016-10-05:
Hi,
Follow the comment above
I use PID and found that it does not work.
While the difference between the current speed and desired speed > maximum error, PID output will be input for the thruster. Else, the output will be zero.
Comment by ZYS on 2016-10-05:
Hi,
Follow the comment above, problem is that while the PID output is zero (because the current speed is close enough to desired speed), the speed of AUV will decrease sharply due to friction force. Thus, I found that the performance of PID controlling speed is oscillated instead of steady state.
Comment by ZYS on 2016-10-05:
Hi,
So do you have some ideas about setting constant speed for AUV?
Comment by ZYS on 2016-10-06:
Hi,
I have deleted keyboard controller but the velocity is also oscillating under constant thruster input (for example 1). The normal condition should be: under the constant thruster input, the velocity is increasing until reach its maximum velocity. The PID does not work under this condition.
Comment by ZYS on 2016-10-06: | {
"domain": "robotics.stackexchange",
"id": 25882,
"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, force, uwsim",
"url": null
} |
If $X$ and $Y$ are independent, this is equal to $$Pr(X+Y=k)=\sum_{i=0}^kPr(Y=k-i)Pr(X=i)$$ which is \begin{align} Pr(X+Y=k)&=\sum_{i=0}^k\frac{e^{-\lambda_y}\lambda_y^{k-i}}{(k-i)!}\frac{e^{-\lambda_x}\lambda_x^i}{i!}\\ &=e^{-\lambda_y}e^{-\lambda_x}\sum_{i=0}^k\frac{\lambda_y^{k-i}}{(k-i)!}\frac{\lambda_x^i}{i!}\\ &=\frac{e^{-(\lambda_y+\lambda_x)}}{k!}\sum_{i=0}^k\frac{k!}{i!(k-i)!}\lambda_y^{k-i}\lambda_x^i\\ &=\frac{e^{-(\lambda_y+\lambda_x)}}{k!}\sum_{i=0}^k{k\choose i}\lambda_y^{k-i}\lambda_x^i \end{align} The sum part is just $$\sum_{i=0}^k{k\choose i}\lambda_y^{k-i}\lambda_x^i=(\lambda_y+\lambda_x)^k$$ by the binomial theorem. So the end result is \begin{align} Pr(X+Y=k)&=\frac{e^{-(\lambda_y+\lambda_x)}}{k!}(\lambda_y+\lambda_x)^k \end{align} which is the pmf of $Po(\lambda_y+\lambda_x)$. | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9755769078156283,
"lm_q1q2_score": 0.8670525627355514,
"lm_q2_score": 0.8887588008585925,
"openwebmath_perplexity": 1436.7829811806564,
"openwebmath_score": 0.9970618486404419,
"tags": null,
"url": "http://math.stackexchange.com/questions/221078/poisson-distribution-of-sum-of-two-random-independent-variables-x-y"
} |
php, comparative-review, validation
class validator{
protected $rules;
public function __construct($rules){
// check the rules real quick
foreach ($rules as $fieldName => $fieldRules){
foreach ($fieldRules as $ruleName => $ruleConfig){
// better to do this with a factory than directly: keeping it easy for the example
if (!class_exists("validation\rules\$ruleName"))
throw new \Exception("Invalid validation rule: could not find rule named $ruleName");
}
}
$this->rules = $rules;
}
public function check($userInput){
$errors = [];
foreach ($this->rules as $fieldName => $fieldRules){
foreach ($fieldRules as $ruleName => $ruleConfig){
// again, a factory would be perfect here, especially one that caches objects
$class = "validation\rules\$ruleName";
$ruleValidator = new $class();
$result = $ruleValidator->check($fieldName, $userInput, $ruleConfig);
if ($result === true)
continue;
// one error per field
$errors[$fieldName] = $result;
break;
}
}
}
}
This is fairly simplified of course. A lot of times you want to see not just the user input, but also the current model data (for instance, a required check can allow non-existent input for a field that is being updated when the model already has a value), possibly a database connection (needed for a unique check), and other details (user-controllable error messages). However, a system like this gives you a lot of flexibility to re-use validation rules to build validators quickly and easily. | {
"domain": "codereview.stackexchange",
"id": 28550,
"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, comparative-review, validation",
"url": null
} |
if (i >= j) {
break;
}
swap(sequence[i], sequence[j]);
}
swap(sequence[lo], sequence[j]);
return j;
}
### Quick Sort Improvements
• use insertion sort for small sub-arrays: Adding a cutoff size for which to apply insertion sort to small sub-arrays can improve the performance of the algorithm.
if (hi <= lo) return;
use:
if (hi <= lo + M) { insertionSort(sequence, lo, hi); return; }
where M is the cutoff. Recommended sizes are between 5 and 15.
• median-of-three partitioning: Choose a sample of size 3 from the sequence and choose the middle element as the partitioning element.
### Three-way Partitioning
Case Growth
Best $O(n)$
Worst $O(n\log{n})$
Space $O(\log{n})$
One problem with quick sort as it is implemented above is that items with keys equal to that of the partition item are swapped anyways, unnecessarily. Three-way partitioning aims to resolve this by partitioning into three separate sub-arrays, the middle of which corresponds to those items with keys equal to the partition point. E. W. Dijkstra popularized this as the Dutch National Flag problem.
Performance Factors: distribution of the keys
1. perform a 3-way comparison between element $i$ and $v$
1. $seq[i] < v$: swap $lt$ and $i$ and lt++ and i++
2. $seq[i] > v$: swap $i$ and $gt$ and gt--
3. $seq[i] = v$: i++
2. repeat step 1 until $i$ and $gt$ cross, i.e. while $i \leq gt$
3. recurse on the left and right segments
Quick sort performs a lot better than merge sort in sequences that have duplicate keys. Its time is reduced from linearithmic to linear for sequences with large numbers of duplicate keys.
template<typename T>
void sort(std::vector<T> &sequence, int lo, int hi) {
if (hi <= lo) {
return;
} | {
"domain": "jip.dev",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9867771759145342,
"lm_q1q2_score": 0.8113174618351043,
"lm_q2_score": 0.8221891239865619,
"openwebmath_perplexity": 1229.7954954713152,
"openwebmath_score": 0.49524566531181335,
"tags": null,
"url": "https://jip.dev/notes/algorithms/"
} |
c#, beginner, object-oriented, winforms, inheritance
the point of inheritance and abstract base classes or interfaces is to have a common API that each type implements in its own way. Your inhertiance model doesn't do that. Classes that are inherited from the PageModelBase add a lot new APIs like the SearchModel. Some of them like the FirstPage method even gets a new overload. This is very confusing. It's difficult to figre out how these models are used but they definitely shouldn't be based on PageModelBase.
the abstract class PagedModelBase doesn't have any abstract or virtual methods so there is not reason for it to be abstract because you don't override anything. It looks like it should be a PageNavigator that other classes use as a service/dependency. In other words, you cannot use the SearchModel where you currently use TableModel because even though they share a common base class, they are not exchangable as they use additionl and specialized APIs.
Repetitions
internal override List<ContractTableRow> LoadPage()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// do soemthing...
stopwatch.Stop();
logger.Debug("Поиск договора: {0}", stopwatch.Elapsed);
return list;
}
you use this pattern in a lot of places. It'd better to create a benchmark-helper or even a decorator for your models that would add this layer outside the core APIs.
you can instantly start with Stopwatch.StartNew()
there's no need to stop it, just call stopwatch.Elapsed
Misc | {
"domain": "codereview.stackexchange",
"id": 35380,
"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, object-oriented, winforms, inheritance",
"url": null
} |
energy, energy-conservation, work, centripetal-force
Title: Work done according to Newton's Principia
Actually I was going through the principia, reading Newton's derivations of the properties of ellipses. Suddenly I had this question which got stuck in my mind -
Throughout Principia Newton uses the diagrams that i have drawn above. He says that if the body is moving in any orbit under a central force then if it moves from P to Q then its actual dispacement is RQ. Chandreshakhar uses this fact ( even Newton ) has to get the formula for centrepetal force. Sorry for the bad digram but in a small time interval RQ is parallel to the radius vector (fig A). Since displacement is parallel to the radius vector then it is parallel to the centrepetal force. Hence work done in that time interval should not be zero. But work done in circular motion is zero ( by the central force). So is the work done zero in a complete circle because even for a quarter or half a circle it shouldn't be zero according to this logic. Is there some flaw in my question. Sorry that its a very basic question but I am unable to find the fault within it ,if it has. Notice that in the finite approximation the vector PR is not perpendicular to the radius, so work is done on it. By the drawing, this work is of the opposite sign that that in QR, so they both compensate to zero. I'll leave to you to compute both if you are really interested.
Another way to see it, the gravity force is derived from a conservative field, so the total work between two pints is independent of the path. If you follow the circular path it will be zero. If you follow the drawn path is should also be zero | {
"domain": "physics.stackexchange",
"id": 31023,
"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": "energy, energy-conservation, work, centripetal-force",
"url": null
} |
# Math Help - Function word problems
1. ## Function word problems
Hi, I need help on a couple of problems. I'll be having my math mid-terms on the 26th, which is a Friday, and we were told by the teacher that some of the questions appearing in the test would be similar to the problems below. Specifically, I need help on four of them.
1) 1000 copies of a souvenir program will be sold if the price is $50 and that the number of copies sold decreases by 10 for each$1 added to the price. Write a function that determines gross revenue as a function of x. What price yields the largest gross sales revenue and what is the largest gross revenue? How many copies must be sold to yield the maximum gross revenue? | {
"domain": "mathhelpforum.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9845754474655618,
"lm_q1q2_score": 0.8183230444300996,
"lm_q2_score": 0.831143054132195,
"openwebmath_perplexity": 1029.9667022245553,
"openwebmath_score": 0.454154372215271,
"tags": null,
"url": "http://mathhelpforum.com/pre-calculus/10388-function-word-problems.html"
} |
Let $$\displaystyle u=e^{-x}+1$$, to get :
$$\displaystyle - \int \frac{du}{u} = -ln|u|+C = -ln(e^{-x}+1) + C$$
$$\displaystyle =ln \left( \frac{1}{e^{-x}+1} \right) + C$$
#### Soroban
MHF Hall of Honor
Hello, Nas!
The General beat me to the solution . . . *sigh*
$$\displaystyle (b)\;\;\int\frac{dx}{e^x+1}$$
I have an equivalent answer: .$$\displaystyle -\ln\left(1 + e^{-x}\right) + C$$
And this answer can be simplified beyond all recognition . . .
$$\displaystyle -\ln\left(1 + \frac{1}{e^x}\right) + C\;=\;-\ln\left(\frac{e^x+1}{e^x}\right) + C$$
. . . . . . . . . . . . $$\displaystyle =\;-\ln(e^x+1) + \ln(e^x) + C$$
. . . . . . . . . . . . $$\displaystyle =\;-\ln(e^x+1) + x\underbrace{\ln(e)}_{\text{This is 1}} + C$$
. . . . . . . . . . . . $$\displaystyle =\;x - \ln(e^x+1) + C$$
Tweety
#### Nas
Thanks for all the help. | {
"domain": "mathhelpforum.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9859363733699887,
"lm_q1q2_score": 0.8216050232201944,
"lm_q2_score": 0.8333245891029457,
"openwebmath_perplexity": 845.0042669508513,
"openwebmath_score": 0.9922444820404053,
"tags": null,
"url": "https://mathhelpforum.com/threads/integrating-e-x.146643/"
} |
ros, navigation, ros-melodic, topics
I had considered this issue orthogonal to security
well, access control is what you are describing in your OP. That is a part of security and safety.
For the sake of simplicity I assume none of the nodes in the system are nefarious
they don't need to be bad actors. I've seen what you describe happen many times to users who did not configure their systems correctly. Nothing nefarious there, just simple misconfiguration.
As Steve says it already exists too in topic_tools!
I would still recommend the yocs versions -- they are not specific to the Turtlebot/Kobuki stacks and I believe are nicer in their implementation and ROS API. Be aware they got renamed, so it's yocs_cmd_vel_mux, not cmd_vel_mux.
The only feature it lacks is the ability for a publishing node to know when it hasn't got access to the hardware so it can respond accordingly.
this sounds like a coordination level task, which I would make the responsibility ..
Comment by gvdhoorn on 2020-04-14:
.. not of the nodes you are talking about, but of another node (or set of nodes) which are responsible for coordination of the application (at whichever level). yocs_velocity_smoother publishes the active input (on the private active topic), so whatever is coordinating your application should be able to take that into account and act accordingly (or make other nodes act accordingly).
Comment by ruffsl on 2020-04-21:
Just to confirm, the access control policy enforced in SROS2 with Secure DDS is in fact static, and must be defined at design time. I'd concur with @gvdhoorn suggestion of using a mux. One could perhaps modify the mux to publish a select topic that states the current input selected (based on input priority, or other logic, etc), that the input publishers could subscribe to and discern if they are currently being subsumed.
Comment by gvdhoorn on 2020-04-22:\
One could perhaps modify the mux to publish a select topic that states the current input selected
The yocs implementation of the mux does this. | {
"domain": "robotics.stackexchange",
"id": 34758,
"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, navigation, ros-melodic, topics",
"url": null
} |
ros, slam, localization, navigation, teb-local-planner
Originally posted by FelixF on ROS Answers with karma: 3 on 2017-01-16
Post score: 0
Original comments
Comment by gvdhoorn on 2017-01-17:
Not a navigation expert, but I see static TF publishers for important transforms such as /map to /odom and /odom and /base_footprint. That seems strange to me, because how do you expect your localisation (you are running one, right?) to update the position of your robot that way?
Comment by Procópio on 2017-01-17:
following on @gvdhoorn, are you running AMCL?
Comment by FelixF on 2017-01-17:
So I set the init pose and I set a goal, then the Path the Robot should drive appears. the echo of cmd_vel contains good values. But if I start moving arround the LiDAR the ArrowCloud won't get smaler and also the polygon of the robot does not move
Comment by FelixF on 2017-01-17:
I think I have to reconfigure my whole tf tree... But I don't get it :/
you should use AMCL.
it is THE node for localization in ROS.
And, as mentioned by @gvdhoorn, you should not publish the tf between /map and /odom, because that is exactly what you want to be published by a localization algoritm (follow the link above on AMCL and check the illustrations on the bottom of the page).
Originally posted by Procópio with karma: 4402 on 2017-01-17
This answer was ACCEPTED on the original site
Post score: 0 | {
"domain": "robotics.stackexchange",
"id": 26743,
"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, slam, localization, navigation, teb-local-planner",
"url": null
} |
In the small sample of compact non-metrizable spaces just highlighted, the failure of hereditary normality occurs in “dimension” 1 or 2. Naturally, one can ask:
Question. Is there an example of a compact non-metrizable space $X$ such that the failure of hereditary nornmality occurs in “dimension” 3? Specifically, is there a compact non-metrizable $X$ such that $X^2$ is hereditarily normal but $X^3$ is not hereditarily normal?
Such a space $X$ would be an example to show that the condition “$X^3$ is hereditarily normal” in Theorem 3 is necessary. In other words, the hypothesis in Theorem 3 cannot be weakened if the example just described were to exist.
The above list of compact non-metrizable spaces is a small one. They are fairly standard examples for compact non-metrizable spaces. Could there be some esoteric example out there that fits the description? It turns out that there are such examples. In [1], Gruenhage and Nyikos constructed a compact non-metrizable $X$ such that $X^2$ is hereditarily normal. The construction was done using MA + not CH (Martin’s Axiom coupled with the negation of the continuum hypothesis). In that same paper, they also constructed another another example using CH. With the examples from [1], one immediate question was whether the additional set-theoretic axioms of MA + not CH (or CH) was necessary. Could a compact non-metrizable $X$ such that $X^2$ is hereditarily normal be still constructed without using any axioms beyond ZFC, the generally accepted axioms of set theory? For a relatively short period of time, this was an open question. | {
"domain": "wordpress.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9817357195106374,
"lm_q1q2_score": 0.8049185740550521,
"lm_q2_score": 0.8198933359135361,
"openwebmath_perplexity": 100.52160425469535,
"openwebmath_score": 0.9672622084617615,
"tags": null,
"url": "https://dantopology.wordpress.com/tag/compact-space/"
} |
concurrency, go
var wg sync.WaitGroup
for scanner.Scan() {
var line string = scanner.Text()
var url string = fmt.Sprintf("https://apirequestmock?q=%s", line)
wg.Add(1)
go func(url string, c chan<- string) {
writeResponse(url, c)
wg.Done()
}(url, c)
}
wg.Wait()
}
func writeResponse(url string, c chan<- string) {
var filters = new(AvailableFilters)
getJSON(url, &filters)
var wg sync.WaitGroup
for _, filter := range filters.Available_filters {
wg.Add(1)
go func(filter Filter, c chan<- string) {
if isNumericFilter(filter) {
c <- filter.toString()
}
wg.Done()
}(filter, c)
}
wg.Wait()
}
func writeToFile(c <-chan string, outputpath string, wg *sync.WaitGroup) {
output, err := os.Create(outputpath)
check(err)
defer output.Close()
w := bufio.NewWriter(output)
for v := range c {
_, err := w.WriteString(v + "\n")
check(err)
}
fmt.Println("Writing output to file ", output.Name())
check(w.Flush())
wg.Done()
return
}
func getJSON(url string, target interface{}) error {
r, err := http.Get(url)
check(err)
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
check(err)
return json.Unmarshal(body, target)
} | {
"domain": "codereview.stackexchange",
"id": 26163,
"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",
"url": null
} |
# How many connected graphs over V vertices and E edges?
Is there a way to calculate the number of simple connected graphs possible over given edges and vertices?
Eg: 3 vertices and 2 edges will have 3 connected graphs But 3 vertices and 3 edges will have 1 connected graph
Then 4 edges and 3 will have 4 connected graphs
Till such values...it is easy to see its
V choose E
But what about when the number of vertices are less than number of edges...how to calculate then?
I am not able to visualize that
Can it be a variation of the Stars and Bars problem
Like...number of ways 7 edges(balls) can be connected to (kept in) 5 vertices(bags) such that no vertex(bag) is isolated (is empty)
Here maybe we might have to consider the number of edges twice as each edge needs two vertices...
• 3 vertices and 2 edges give 4 connected graphs? – Hagen von Eitzen Feb 25 '14 at 6:48
• Oops! My bad...mistype...i corrected it – Nishad Feb 25 '14 at 7:34
First of all, let me state my preconditions. Since you write that there are three graphs with two edges on three vertices it seems you are talking about the labelled case, which is what I will work with from now on. As this is truly a vast field of investigation I will just show you how to calculate these numbers (connected graphs on $$n$$ nodes having $$k$$ edges). This should enable you to consult the relevant entries of the OEIS and decide what course to take in your research.
Method I. Let $$\mathcal{Q}$$ be the combinatorial class of connected graphs and $$\mathcal{G}$$ the combinatorial class of labelled graphs, all of them. The relation between these two classes is the set-of relation: a graph is a set of connected components. This gives the relation between the two classes: $$\def\textsc#1{\dosc#1\csod} \def\dosc#1#2\csod{{\rm #1{\small #2}}}\mathcal{G} = \textsc{SET}(\mathcal{Q}).$$ | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9848109534209826,
"lm_q1q2_score": 0.8185187835691543,
"lm_q2_score": 0.831143054132195,
"openwebmath_perplexity": 1222.4374077834893,
"openwebmath_score": 0.6012434363365173,
"tags": null,
"url": "https://math.stackexchange.com/questions/689526/how-many-connected-graphs-over-v-vertices-and-e-edges"
} |
fourier-transform, time-frequency
Title: Fourier Transform with both Time Delay and Frequency Shift I know that the Fourier transform of a function with time delay can be written as: $$\mathscr{F}\big\{x(t-t_0)\big\}=X(f)e^{-j2\pi f t_0}$$
The Fourier transform of a function with frequency shift can also be written as: $$\mathscr{F}\Big\{x(t)e^{j2\pi f_0 t}\Big\}=X(f-f_0)$$
So what if we have both shift and delay at the time domain, what will be the result in the frequency domain? E.g.:
$$\mathscr{F}\Big\{x(t-t_0)e^{j2\pi f_0 (t-t_0)}\Big\}$$
Will the result be: $$X(f-f_0)e^{-j 2 \pi f (t-t_0)}$$
Also what will be the result of:
$$\mathscr{F}\Big\{x(t-t_0)e^{j2\pi f_0 t)}\Big\}$$
Is there an order to apply these properties? If you are ever unsure, just go back to the definition and work out the Fourier Transform property for the specific situation:
$$\begin{align*}\mathscr{F}\left\{x\left(t-t_0\right)e^{j2\pi f_0\left(t-t_0\right)}\right\} &= \int_{-\infty}^\infty x\left(t-t_0\right)e^{j2\pi f_0\left(t-t_0\right)} e^{-j2\pi f t}dt\\
\\ | {
"domain": "dsp.stackexchange",
"id": 7216,
"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": "fourier-transform, time-frequency",
"url": null
} |
It is very difficult to correct such an overcounting, so it's better to start counting the right way.
You may understand what's wrong if you think of the following example. Say you want to choose 2 boys out of 4.
Then the correct way is $\binom{4}{2}=6$. But if you do it the way you are suggesting it will be $\binom{4}{1}\binom{3}{1}=12$. In other words, you take into account the order, hence you have more ways to choose them.
Try this
Conditions: atleast 2 boys and atleast 2 girls and a team of 6 to be formed
Boys-2 ,girls -4 C(14,2) . C(12,4)=91 .495=45045
Boys-3, girls -3 C(14,3).C(12,3)=104 . 220= 80080
Boys-4,girls-2 C(14,4).C(12,2)=1001 . 66=66066 | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9850429156022934,
"lm_q1q2_score": 0.8076301264261929,
"lm_q2_score": 0.8198933403143929,
"openwebmath_perplexity": 769.6803254664406,
"openwebmath_score": 0.6257547736167908,
"tags": null,
"url": "https://math.stackexchange.com/questions/2291924/a-class-of-children-contains-14-boys-and-12-girls-how-many-ways-are-there-to-ch"
} |
kalman-filter
In short, you need to ask yourself: Is the map very good? Does it full cover the operational area (i.e., is it possible for the robot to take measurements of things not in the map)? Is it possible the map has changed? Does the sensor work well in different conditions? Is the data association algorithm reliable for different amounts of noise? Will the updates provided by the sensor be frequent enough based on how fast the robot is travelling? Etc. | {
"domain": "robotics.stackexchange",
"id": 606,
"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": "kalman-filter",
"url": null
} |
beginner, logging, powershell
But maybe you almost always want to use "yesterday" and it's too annoying to enter that value every time. You can provide your parameter with a default value instead:
[CmdletBinding()]
param(
$Computers,
$Logs,
$StartTime = $((Get-Date).AddDays(-1))
) | {
"domain": "codereview.stackexchange",
"id": 28174,
"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": "beginner, logging, powershell",
"url": null
} |
general-relativity, black-holes, metric-tensor
\end{align}
Ok very strictly speaking, we only know that this equality holds in region I of the spacetime, which is the common domain of definition of the two coordinate systems $(T,X,\theta,\phi),(t,r,\theta,\phi)$. But now, we observe that the vector field on the right of $(*)$ is well-defined and actually analytic with respect to the global (up to the usual caveats with spherical coordinates) $(T,X,\theta,\phi)$ coordinates. So, we shall use $(*)$ as our definition of the vector field $\xi$ on the maximally extended spacetime. Since the metric $g$ is also analytic, and we know for sure that $\xi$ is a Killing vector field in region I, it follows by uniqueness of analytic continuation that $\xi$ is a Killing field on the entire maximally extended spacetime (which vanishes if and only if $X=T=0$). I’m sure you could try to argue directly that the RHS of $(*)$ is indeed Killing everywhere, but using this analysis fact is much quicker.
Next, to prove collinearity, we need to use the metric-induced isomorphism. We have
\begin{align}
\begin{cases}
g^{\flat}\left(\frac{\partial}{\partial T}\right)&=g_{TT}\,dT+g_{TX}\,dX+g_{T\theta}\,d\theta
+g_{T\phi}\,d\phi=-\alpha(r)\,dT\\
g^{\flat}\left(\frac{\partial}{\partial X}\right)&=g_{XT}\,dT+g_{XX}\,dX+g_{X\theta}\,d\theta+g_{X\phi}\,d\phi=\alpha(r)\,dX,
\end{cases}
\end{align} | {
"domain": "physics.stackexchange",
"id": 92415,
"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": "general-relativity, black-holes, metric-tensor",
"url": null
} |
ros, ros-melodic, gazebo-ros-control
[INFO] [1608147464.197719, 11722.766000]: Calling service /gazebo/spawn_urdf_model
[INFO] [1608147464.229827, 11722.781000]: Spawn status: SpawnModel: Failure - entity already exists. | {
"domain": "robotics.stackexchange",
"id": 35878,
"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-melodic, gazebo-ros-control",
"url": null
} |
everyday-chemistry, food-chemistry, enzymes
Title: How do I eliminate the disagreeable odor of soy milk? I've was making tofu from soy-milk, but noticed this disagreeable odor produced during the process.
I conducted a string of internet searches in an attempt to find a method to eliminate this odor.
I learnt that the enzyme lipoxygenase is primarily responsible for this odor, and is activated upon grinding soy beans in water. Additionally, it appears that lipoxygenase is inactivated in the presence of D-glucose and the enzyme glucose oxidase.
Obtaining D-glucose is fairly simple, but I'm at odds as to where I can find glucose oxidase.
Further investigation suggests that commonly available honey contains glucose oxidase.
Armed with this knowledge, I want to know:
Can I add a measured quantity of dilute honey, along with some D-glucose, to the soy milk and inactivate the lipoxygenase enzyme this way? | {
"domain": "chemistry.stackexchange",
"id": 8470,
"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": "everyday-chemistry, food-chemistry, enzymes",
"url": null
} |
c++, performance, multithreading, bioinformatics
c['R'] = 'Y'; c['r'] = 'Y';
c['W'] = 'W'; c['w'] = 'W';
c['S'] = 'S'; c['s'] = 'S';
c['Y'] = 'R'; c['y'] = 'R';
c['K'] = 'M'; c['k'] = 'M';
c['V'] = 'B'; c['v'] = 'B';
c['H'] = 'D'; c['h'] = 'D';
c['D'] = 'H'; c['d'] = 'H';
c['B'] = 'V'; c['b'] = 'V';
c['N'] = 'N'; c['n'] = 'N'; | {
"domain": "codereview.stackexchange",
"id": 31671,
"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, bioinformatics",
"url": null
} |
• One more thing. The only thing you must avoid in a proof of $y=z$ is starting with $y=z$ and deriving $0=0$ or $1=1$. As long as your proof starts with assumptions you are given, follows logically valid steps, and ends up with what you want, then the proof is good. Many of my students try to show $x=y$ and argue "$x=y$ ... <operations> ... $0=0$, QED". What is most frustrating is that often if they just turned the proof up-side-down, then it would be valid, i.e, the operations they effect on the equation can be done backwards to start with $0=0$ and derive $x=y$. – James Aug 17 '18 at 18:35
• Those two proofs are exactly the same as far as I can tell. Or aren't significantly different. "Assuming arithmatic" is a meaningless thing to say. To prove this we must have a well defined set of axioms. "Assuming arithmetic" is simply referring to them. – fleablood Aug 17 '18 at 18:37 | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9861513901914406,
"lm_q1q2_score": 0.8998001945726162,
"lm_q2_score": 0.9124361670249624,
"openwebmath_perplexity": 830.331103338256,
"openwebmath_score": 0.9999711513519287,
"tags": null,
"url": "https://math.stackexchange.com/questions/2886048/two-alternate-proofs-that-x-neq-0-wedge-xy-xz-implies-y-z"
} |
python, pandas
example_data = StringIO(
"""open_local_data,country,competition,match_id,match_name,market_id,market_name,runner_id,runner_name,status,total_matched,odds,market_matched,percentage,above_odds,result
2022-08-24 15:00:00,UY,Uruguayan Segunda Division,31684262,Uruguay Montevideo FC v Progreso,1.202440748,Match Odds,11076801,Uruguay Montevideo FC,OPEN,197.2,2.88,448.52,43.96682422188531,9.24460199966309,WINNER
2022-08-24 15:00:00,AT,Austrian Matches,31685733,SV Gerasdorf Stammersdorf v Dinamo Helfort,1.202453470,Match Odds,10299781,SV Gerasdorf Stammersdorf,OPEN,15.99,3.05,27.12,58.96017699115043,26.17329174524879,LOSER
2022-08-24 15:00:00,UY,Uruguayan Segunda Division,31684267,Villa Espanola v Sud America,1.202440560,Match Odds,58805,The Draw,OPEN,458.35,3.5,651.11,70.39517132281796,41.82374275138939,LOSER
2022-08-24 15:00:00,UY,Uruguayan Segunda Division,31684266,Miramar Misiones v Central Espanol,1.202440654,Match Odds,5300627,Miramar Misiones,OPEN,642.05,2.1,1075.66,59.68893516538684,12.069887546339224,LOSER
"""
) | {
"domain": "codereview.stackexchange",
"id": 44138,
"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",
"url": null
} |
Lemma 2. Suppose $k_i:[-1,1]\to\mathbb R$, $i=1,2$ are any two functions such that $k_i(-1)=k_i(1)=0$ and $k_i(t)>0$ for $t\in(-1,1)$. Then $A(0,k_1)$ is homeomorphic to $A(0,k_2)$.
Proof. Again, we may define an explicit homeomorphism $h:A(0,k_1)\to A(0,k_2)$, this time by the formula $$h(x,y)=\left(x,\frac{k_2(x)}{k_1(x)}y\right)$$ for $x\in(-1,1)$ and $h(-1,0)=h(1,0)=0$. This is continuous for $x\in(-1,1)$, since $k_1$ and $k_2$ are continuous and products and quotients of continuous functions are continuous (the latter wherever the denominator is nonzero). But $h$ also continuous at the points $(\pm1,0)$, since $\frac{y}{k_1(x)}\in[0,1]$ for all $(x,y)\in A(0,k_1)$, while $k_2(x)$ goes to $0$ as $x$ approaches $\pm1$. So the two limits $\lim_{(x,y)\to(\pm1,0)}h(x,y)$ exist and equal the corresponding function values. By the same argument, the inverse $$h^{-1}(x,y)=\left(x,\frac{k_1(x)}{k_2(x)}y\right)$$ is continuous. So $h$ is indeed a homeomorphism. $\square$
Proposition. $A(f,g)$ is homeomorphic to $D$. | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9835969645988575,
"lm_q1q2_score": 0.8884774347323819,
"lm_q2_score": 0.9032942014971871,
"openwebmath_perplexity": 171.67332975702058,
"openwebmath_score": 0.8569528460502625,
"tags": null,
"url": "https://math.stackexchange.com/questions/1273151/circle-and-heart-homeomorphic"
} |
• (Should have absolute value) – user223391 Apr 4 '17 at 6:12
• done.. overlooked that. thanks – Hirak Apr 4 '17 at 6:13
Given $\displaystyle\int \dfrac{f'(x)}{f(x)}\,\mathrm dx$ we can make the substitution $u=f(x)$, giving $\mathrm du =f'(x)\,\mathrm dx$ and so $$\int \frac{f'(x)}{f(x)}\,\mathrm dx = \int \frac1u \,\mathrm du = \ln|u| + c = \ln |f(x)| + c$$
In your case, $f(x)=\cos x$, but you should always look out for this form.
In general, for any function of sines and cosines, $u=\sin x$ and $u=\cos x$ are worth investigating as substitutions.
Simply -
1.) $\int \frac {f'(x)}{f(x)} dx = \ln |f(x)| + c$
Other one is not used. But you should need to know.
2.) $\int f(x) \cdot f'(x) dx = \dfrac{[f(x)]^{n+1}}{n+1} + c$
So from,
$\int \frac{\sin(x)}{\cos(x)} dx= - \int \frac{-\sin(x)}{\cos(x)} dx=- \ln|\cos x| + c$ | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9706877667047449,
"lm_q1q2_score": 0.8002951102342627,
"lm_q2_score": 0.8244619306896955,
"openwebmath_perplexity": 713.0399126581692,
"openwebmath_score": 0.9983802437782288,
"tags": null,
"url": "https://math.stackexchange.com/questions/2217168/how-to-do-integration-of-%E2%88%AB-tan-x-dx"
} |
machine-learning, classification, dataset, matlab
Delete corrupted samples:
If you have a large dataset and there is not much data missing, you can simply remove those corrupted data points and go on with life
Recover the values:
Some problems will allow you to go back and get missing information.
We usually ain't that lucky, then you can
Educated Guessing:
Sometimes, you can infer what would be the feature value by simply looking their pears. That is a bit arbitrary but it might work.
Average:
This is the most common approach, simply use the average of that value whenever it is missing. This might artificially reduce your variance but so does using 0 or -9999... for every missing value.
Regression Substitution:
You can use a multiple regression to infer the missing value from the available values for each candidate.
Some references on missing data are:
Allison, Paul D. 2001. Missing Data. Sage University Papers
Series on Quantitative Applications in the Social Sciences.
Thousand Oaks: Sage.
Enders, Craig. 2010. Applied Missing Data Analysis.
Guilford Press: New York.
Little, Roderick J., Donald Rubin. 2002. Statistical Analysis
with Missing Data. John Wiley & Sons, Inc: Hoboken.
Schafer, Joseph L., John W. Graham. 2002. “Missing Data:
Our View of the State of the Art.” Psychological Methods.
About your experiment:
Adding -99... is creating outliers and that bit of information is heavy (numerically speaking, it is huge) and will affect parameter tuning. For example, suppose you have this data:
| Feature1 | Feature2 |
|----------|----------|
| 0 | 8 |
| -1 | 7 |
| 1 | - |
| - | 8 |
And you try filling the missing values with -99, now try to fit a linear regression trough the data. Can you see that you don't be able to fit it properly?
The line won't fit, and this will yield bad performance.
Adding 0 values on the other hand will give a slightly better line:
It is still not good, but slightly better since the scale of the parameters will be more realistic.
Now, using average, is this case will give you even better curve, but using regression will give you a perfect fitting line: | {
"domain": "datascience.stackexchange",
"id": 5011,
"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": "machine-learning, classification, dataset, matlab",
"url": null
} |
[ ] = ( ). Its graph on selected intervals ydx 2 that the second derivative test was a waste time... Sum ; Product ; Chain ; Power ; Quotient ; L'Hôpital 's rule ; Inverse ; given by notation. Definitions of 2, pronounced dee two y by d x squared.. Derivatives is a powerful and useful notation that makes the process of computing derivatives clearer than the notation... ( a ) = 0 while a negative second derivative of a function from... Of its graph on selected intervals of change negative second derivative means that section is up. Regression model ] = ( â ) â Related pages section is concave.! Note as well that the second derivative is the derivative ( dx ) in the denominator not! ; Product ; Chain ; Power ; Quotient ; L'Hôpital 's rule ; Inverse ; x ) is actually to... 2 is actually applied to second derivative notation derivative of that commonly used C ) the! Identities ; Sum ; Product ; Chain ; Power ; Quotient ; L'Hôpital 's ;., basically, that the second derivative is written d 2 ydx.. Commonly used 2 y/dx 2, pronounced dee two y by d x squared '' ) â Related.... Introductory article on derivatives looked at how we can calculate derivatives as limits of average rates change... A ) = 0 [ ] = ( â ) â = ( â ) â = â... Concavity and inflection points ( dx ) in the denominator, not just (! With respect to multiple variables when finding the estimates in a linear regression.! Na take the derivatives in is given by the notation for each these while a negative derivative! Determine where the graph is concave up, while a negative second derivative of the derivative Inverse ; as that. The x ⦠well, the superscript 2 is actually applied to ( dx ) in the denominator, just! Not just on ( x ) sense to me to think of it this.! ( 1736-1813 ) of derivatives is a powerful and useful notation that used... ; Chain ; Power ; Quotient ; L'Hôpital 's rule ; Inverse ; at how we can calculate derivatives limits. By the notation for each these applied to the derivative of a function changes from â¦! Actually applied to ( dx ) in the | {
"domain": "baroknikrajinou.cz",
"id": null,
"lm_label": "1. YES\n2. YES\n\n",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9833429624315189,
"lm_q1q2_score": 0.8129412267577049,
"lm_q2_score": 0.8267117962054048,
"openwebmath_perplexity": 687.9443177457151,
"openwebmath_score": 0.9352886080741882,
"tags": null,
"url": "http://baroknikrajinou.cz/8rofnx/debc88-second-derivative-notation"
} |
#### romsek
MHF Helper
Ah. I see. The book doesn't say that it equals 0.0333, as I mentioned in my OP, it just asks to find the decimal version to the fourth decimal. So instead of it repeating endlessly, it just stops at 0.0333. So the book's answers are "1/30; 0.0333."
What I didn't get, was how to make sense of the fact that 333/10000 and 1/30 both equal 0.0333, even though they aren't equivalent fractions, and if 333/10000 would be an incorrect answer for the fractional part of the question.
$\dfrac 1{30} \neq 0.0333$
$\dfrac 1{30} = 0.033333333333333333333333333333333333 \dots$ with 3's going on forever
1 person | {
"domain": "mathhelpforum.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9559813513911654,
"lm_q1q2_score": 0.804769623688951,
"lm_q2_score": 0.8418256512199033,
"openwebmath_perplexity": 553.760456675165,
"openwebmath_score": 0.8563199043273926,
"tags": null,
"url": "https://mathhelpforum.com/threads/converting-decimals-to-fractions-help.260259/"
} |
$$\begin{eqnarray}0 &=& xy''-y'+4xy\\ &=& \sum_{n=0}^\infty(n+2)(n+1)c_{n+2}x^{n+1}-\sum_{n=0}^\infty(n+1)c_{n+1}x^n+\sum_{n=0}^\infty 4c_n x^{n+1}\\ &=& -c_1+\sum_{n=0}^\infty(n+2)(n+1)c_{n+2}x^{n+1}-\sum_{n=1}^\infty(n+1)c_{n+1}x^n+\sum_{n=0}^\infty 4c_n x^{n+1}\\ &=& -c_1+\sum_{n=0}^\infty(n+2)(n+1)c_{n+2}x^{n+1}-\sum_{n=0}^\infty(n+2)c_{n+2}x^{n+1}+\sum_{n=0}^\infty 4c_n x^{n+1}\\ &=& -c_1+\sum_{n=0}^\infty\bigl[(n+2)(n+1)c_{n+2}-(n+2)c_{n+2}+4c_n\bigr]x^{n+1}\\ &=& -c_1+\sum_{n=0}^\infty\bigl[(n+2)nc_{n+2}+4c_n\bigr]x^{n+1}.\end{eqnarray}$$ Thus, $$c_1=0,$$ and $$(n+2)nc_{n+2}=-4c_n$$ | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9802808724687407,
"lm_q1q2_score": 0.8037257546606275,
"lm_q2_score": 0.8198933359135361,
"openwebmath_perplexity": 184.00159789867158,
"openwebmath_score": 0.9891518354415894,
"tags": null,
"url": "https://math.stackexchange.com/questions/3196252/series-solution-about-x-0-of-xy-y4xy-0"
} |
reductions, lambda-calculus
Rewrite the expression by substituting every free occurrence of $x$ in $e_1$ with $e_2$.
I've solved some exercise problems which seemed fairly simple to understand, but came across one that I couldn't understand the answer.
The expression in question is ($\lambda x.$($\lambda y.x$)) $y$, and after following the rules above I ended up with the result of $\lambda y.y$ after replacing the free occurrence of $x$ with $y$ in $\lambda y.x$. However, the correct answer seems to be $\lambda y.x$.
The rationale that I've been able to find is that before applying $\beta$-reduction, we have to change variables to be "unique."
Could someone explain the reasoning behind this for me please? When performing a $\beta$-reduction, there are cases in which an $\alpha$-conversion is needed first; otherwise, the $\beta$-reduction fails to preserve semantics. This is here the case: you are replacing the free variable $x$ with $e_2$ and $e_2$ contains free variables which are bound within $e_1$.
You can easily see why the semantics are not preserved: $(\lambda y.y)$ and $(\lambda y.x)$ are not equivalent expressions because $(\lambda y.y)z = z$ but $(\lambda y.x)z = x$. In order to preserve the semantics, you first need to perform an $\alpha$-conversion on $(\lambda y.x)$ so as to replace $y$ with something else which is not free in $e_2$ (thus achieving "uniqueness"—though IMO such a term should be frowned upon here). | {
"domain": "cs.stackexchange",
"id": 12784,
"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": "reductions, lambda-calculus",
"url": null
} |
# Minimal polynomial for $\alpha=\sqrt{3-2\sqrt{2}}$ over $\mathbb{Q}$
Find the minimal polynomial for $\alpha=\sqrt{3-2\sqrt{2}}$ over $\mathbb{Q}$
$\alpha=\sqrt{3-2\sqrt{2}} \implies -\alpha^2-3=2\sqrt{2} \implies (\frac{-\alpha^2-3}{2})^2-2=0$
$\implies (\frac{-\alpha^2-3}{2})^2-2=\frac{\alpha^4+6\alpha^2+9}{4}-2=\alpha^4+6\alpha^2+1=0$
So I believe $P=\alpha^4+6\alpha^2+1$ is a candidate for a minimal polynomial
Let $x=\alpha^2 \implies P=x^2+6x+1=(x+3)^2-8$
Could P be the minimal polynomial? It clearly has $\alpha$ as root, but I am not sure if there is another polynomial of lower degree also having $\alpha$ as a root
Would appreciate your guidance on this | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9817357221825193,
"lm_q1q2_score": 0.8116124980930365,
"lm_q2_score": 0.8267117919359419,
"openwebmath_perplexity": 253.79027218049745,
"openwebmath_score": 0.885458767414093,
"tags": null,
"url": "https://math.stackexchange.com/questions/1740564/minimal-polynomial-for-alpha-sqrt3-2-sqrt2-over-mathbbq"
} |
algorithms, algorithm-analysis, sorting, quicksort
Title: Why don't we use quick sort on a linked list? Quick sort algorithm can be divided into following steps
Identify pivot.
Partition the linked list based on pivot.
Divide the linked list recursively into 2 parts.
Now, if I always choose last element as pivot, then identifying the pivot element (1st step) takes $\mathcal O(n)$ time.
After identifying the pivot element, we can store its data and compare it with all other elements to identify the correct partition point (2nd step). Each comparison will take $\mathcal O(1)$ time as we store the pivot data and each swap takes $\mathcal O(1)$ time. So in total it takes $\mathcal O(n)$ time for $n$ elements.
So the recurrence relation is:
$T(n) = 2T(n/2) + n$ which is $\mathcal O(n \log n)$ which is the same as in merge sort with a linked list.
So why is merge sort preferred over quick sort for linked lists? The memory access pattern in Quicksort is random, also the out-of-the-box implementation is in-place, so it uses many swaps if cells to achieve ordered result.
At the same time the merge sort is external, it requires additional array to return ordered result. In array it means additional space overhead, in the case if linked list, it is possible to pull value out and start merging nodes. The access is more sequential in nature.
Because of this, the quicksort is not natural choice for linked list while merge sort takes great advantage.
The Landau notation might (more or less, because Quicksort is still $\mathcal O(n^2)$) agree, but the constant is far higher.
In the average case both algorithms are in $\mathcal O(n\log n)$ so the asymptotic case is the same, but preference is strictly due to hidden constant and sometimes the stability is the issue (quicksort is inherently unstable, mergsort is stable). | {
"domain": "cs.stackexchange",
"id": 12617,
"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, algorithm-analysis, sorting, quicksort",
"url": null
} |
special-relativity, photons, speed-of-light, momentum, acceleration
Title: If photons have no acceleration, how can they have energy and momentum? The change in speed of a photon with respect to time is 0 as photons travel at $c$ forever. If no change in speed exists, how can photons have momentum and acceleration? I guess they don't work like classical mechanics particles. Everything has momentum, even when acceleration is zero. Photons do not accelerate, they pop in and out of existence instantaneously and immediately travel at the speed of light. Their momentum and energy are proportional to their frequency. | {
"domain": "physics.stackexchange",
"id": 33843,
"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": "special-relativity, photons, speed-of-light, momentum, acceleration",
"url": null
} |
c++, linked-list
SinglyLinkedList(SinglyLinkedList const& copy)
: SinglyLinkedList()
{
for(Node* loop = copy.head; loop != nullptr; loop = loop->next) {
addTail(loop->data);
}
}
SinglyLinkedList& operator=(SinglyLinkedList const& rhs)
{
SinglyLinkedList copy(rhs);
swap(copy);
return *this;
}
SinglyLinkedList(SinglyLinkedList&& move) noexcept
: SinglyLinkedList()
{
swap(move);
}
SinglyLinkedList& operator=(SinglyLinkedList&& move) noexcept
{
swap(move);
return *this;
}
void swap(SinglyLinkedList& other) noexcept
{
using std::swap;
swap(head, other.head);
swap(tail, other.tail);
}
friend void swap(SinglyLinkedList& lhs, SinglyLinkedList& rhs)
{
lhs.swap(rhs);
}
void addTail(T const& value)
{
Node* newValue = new Node{value, nullptr};
if (tail != nullptr) {
tail->next = newValue;
}
tail = newValue;
if (head == nullptr) {
head = newValue;
}
}
void addHead(T const& value)
{
Node* newValue = new Node{value, head};
head = newValue;
if (tail == nullptr) {
tail = newValue;
}
}
// Assumes there is data in list.
// Users responsibility to validate by calling empty()
void deleteHead()
{
Node* old = head;
head = head->next;
delete old;
}
// Assumes there is data in list.
// Users responsibility to validate by calling empty()
void deleteTail()
{
Node* prev = nullptr;
Node* curr = head;
while(curr->next != nullptr) {
prev = curr;
curr = curr->next;
}
tail = prev; | {
"domain": "codereview.stackexchange",
"id": 30711,
"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++, linked-list",
"url": null
} |
formal-languages, regular-languages, regular-expressions
Title: Could we write $(a+b)^* = (\epsilon + a + b)^+$? I have read that $L^* = L^+ - \epsilon$, but if we write $(\epsilon + a + b)^+$, is it equivalent to $(a+b)^*$?
I have read that $L^∗=L^+−\epsilon$
That's definitely not true, since $\epsilon\in L^*$ but $\epsilon\notin [\text{anything}]-\epsilon$. If you still know where you read this, I suggest you check to see if you've misremembered what was written.
but if we write $(\epsilon+a+b)^+$, is it equivalent to $(a+b)^∗$?
Yes. The first regular expression matches any string that can be broken up into one or more units, where each unit is either empty, an $a$ or a $b$. That matches the empty string (every unit is empty) or any string of positive length containing only $a$s and $b$s (every unit is $a$ or $b$). The second regular expression matches any string that can be broken up into zero or more units, each of which is an $a$ or a $b$. That matches the empty string (no units at all) or any string of positive length containing only $a$s and $b$s (one or more units). | {
"domain": "cs.stackexchange",
"id": 7829,
"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": "formal-languages, regular-languages, regular-expressions",
"url": null
} |
### Show Tags
20 Oct 2010, 04:14
1
nonameee wrote:
Bunuel, is it necessary to count the number of trailing zeros? I have solved the problem by counting the number of 5's in N.
It's basically the same. Since there are at least as many factors 2 as factors of 5 in N, then finding the number of factors of 5 in N would be equivalent to the number of factors 10, each of which gives one more trailing zero.
_________________
Math Expert
Joined: 02 Sep 2009
Posts: 58988
If N is the product of all multiples of 3 between 1 and 100, what is [#permalink]
### Show Tags
14 Feb 2011, 06:34
1
11
Manager
Joined: 07 Jun 2010
Posts: 76
Re: If N is the product of all multiples of 3 between 1 and 100, what is [#permalink]
### Show Tags
15 Feb 2011, 20:36
7
2
N = The product of the sequence of 3*6*9*12....*99
N therefore is also equal to 3* (1*2*3*.....*33)
Therefore N = 3* 33!
From here we want to find the exponent number of prime factors, specifically the factors of 10.
10 = 5*2 so we want to find which factors is the restrictive factor
We can ignore the 3, since a factor that is not divisible by 5 or 2 is still not divisible if that number is multiplied by 3.
Therefore:
33/ 2 + 33/4 + 33/8 = 16+8+4 = 28
33/ 5 + 33/25 = 6 + 1 = 7
5 is the restrictive factor.
Here is a similar problem: number-properties-from-gmatprep-84770.html
Manager
Joined: 05 Nov 2012
Posts: 138
Re: If N is the product of all multiples of 3 between 1 and 100, what is [#permalink]
### Show Tags | {
"domain": "gmatclub.com",
"id": null,
"lm_label": "1. Yes\n2. Yes",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9697854199186668,
"lm_q1q2_score": 0.8373045950326766,
"lm_q2_score": 0.8633916099737806,
"openwebmath_perplexity": 1101.4882821330661,
"openwebmath_score": 0.8408488035202026,
"tags": null,
"url": "https://gmatclub.com/forum/if-n-is-the-product-of-all-multiples-of-3-between-1-and-100-what-is-101187.html"
} |
lagrangian-formalism, renormalization, fourier-transform, variational-calculus, functional-derivatives
Hence, it seems that the functional derivative is
$$\frac{\delta^2 \Gamma_k}{\delta \varphi(p) \delta \varphi(q)} = \frac{1}{(2\pi)^4} p^2 \delta^{(4)}(p+q) + \frac{1}{(2\pi)^4} m_k^2 \delta^{(4)}(p+q) + \frac{\lambda_k}{2 (2\pi)^{12}} \int \tilde{\varphi}(r)\tilde{\varphi}(-p-q-r) \textrm{d}^4 r. \tag{2}$$
I can't understand how Eqs. (1) and (2) can coexist. They appear to give vastly different expressions for the same thing, especially due to the integral. The factors of $(2\pi)^4$ everywhere seem to be wrong, but I can't figure out why. In short, what is the correct manner of taking the functional derivative on momentum space and why do Eqs. (1) and (2) (seem to) disagree? References and further comments are welcome, but not necessary for the answer to be accepted.
Edit: I removed the mention of taking $\tilde{\varphi}(p) = \tilde{\varphi}_0$, as I recalled this is incorrect. We in fact take $\varphi(x) = \varphi_0$, in position space. Nevertheless, the main points of the question remain. After a while, I noticed that, if we set $\varphi(x) = \varphi_0$, the last term of Eq. (2) can be written as
$$
\begin{align} | {
"domain": "physics.stackexchange",
"id": 84474,
"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": "lagrangian-formalism, renormalization, fourier-transform, variational-calculus, functional-derivatives",
"url": null
} |
c++, c++14, vectors, benchmarking
template <typename F>
struct testfunc {
F *fn;
const char *name;
};
#define TEST(x) { x, #x }
template <typename T>
void vectest(unsigned n)
{
std::vector<T> arr(n, false);
unsigned remaining = n;
static constexpr unsigned incr = 13;
for (unsigned j = 0; j < incr; ++j) {
for (unsigned i = j; i < n && remaining; i += incr) {
if (!arr[i]) {
arr[i] = true;
--remaining;
}
}
}
}
#define SHOW(x) std::cerr << #x << " = " << x << "\n"
int main(int argc, char *argv[])
{
const testfunc<decltype(vectest<bool>)> test[]{
TEST(vectest<char>),
TEST(vectest<bool>),
};
if (argc < 4) {
std::cerr << "Usage: booltest minsize maxsize steps\n";
return 0;
}
unsigned min = std::stod(argv[1]);
unsigned max = std::stod(argv[2]);
unsigned steps = std::stod(argv[3]);
double logmin = std::log10(min);
double logmax = std::log10(max);
double step = (logmax - logmin)/steps;
SHOW(min);
SHOW(max);
SHOW(steps);
// print header data
std::cout << "\"n\"";
for (const auto t : test) {
std::cout << ", \"" << t.name << "\"";
}
std::cout << "\n"; | {
"domain": "codereview.stackexchange",
"id": 18162,
"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++14, vectors, benchmarking",
"url": null
} |
c++, reinventing-the-wheel, vectors
static void deallocate(pointer buffer)
{
delete static_cast<void*>(buffer);
}
std::size_t m_size;
Ty* m_buffer;
};
template<class Ty>
inline void swap(memory_block<Ty>& a, memory_block<Ty>& b)
{
a.swap(b);
}
template<class Ty>
class vector
{
public:
using size_type = std::size_t;
using value_type = Ty;
vector();
explicit vector(size_type count);
vector(size_type count, const value_type& val);
vector(const vector& other);
vector(vector&& other);
~vector();
void swap(vector& other);
vector& operator=(const vector& other);
vector& operator=(vector&& other);
size_t size() const;
size_t capacity() const;
void push_back(const value_type& val);
void pop_back();
private:
static const size_type M_INITIAL_SIZE = size_type{ 10 };
size_type m_size;
memory_block<Ty> m_buffer;
void grow(size_type amount);
void reallocate(size_type min_size);
void construct(size_type index, const value_type& value);
void destruct(size_type index);
void destruct_all();
};
template<class Ty>
inline void swap(vector<Ty>& a, vector<Ty>& b)
{
a.swap(b);
}
template<class Ty>
vector<Ty>::vector():
m_size(0u),
m_buffer(M_INITIAL_SIZE)
{
}
template<class Ty>
vector<Ty>::vector(size_type count):
m_size(count),
m_buffer(m_size)
{
std::uninitialized_value_construct_n(m_buffer.data(), m_size); // value construct each element w/ placement new (C++17)
} | {
"domain": "codereview.stackexchange",
"id": 33146,
"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++, reinventing-the-wheel, vectors",
"url": null
} |
php, laravel
/**
* @param $templateSettings
* @return bool
*/
private function areSettingsValid($templateSettings) {
$message = '';
if(empty($templateSettings)) {
throw new OutOfBoundsException('No settings specified.');
}
if(!is_array($templateSettings)) {
throw new OutOfBoundsException('Expected array, received ' . get_class($templateSettings) . ' Object');
}
if(is_null($templateSettings['templateName'])) {
$message .= 'Template Name value cannot be null.' . PHP_EOL;
}
if(is_null($templateSettings['companyName'])) {
$message .= 'Company Name value cannot be null.' . PHP_EOL;
}
if(is_null($templateSettings['projectName'])) {
$message .= 'Project Name value cannot be null.' . PHP_EOL;
}
if(is_null($templateSettings['projectId'])) {
$message .= 'Project ID value cannot be null.' . PHP_EOL;
}
if(!empty($message)) {
throw new OutOfBoundsException($message);
}
return true;
}
/**
* @param $templateSettings
*/
private function setSettings($templateSettings) {
$this->template = $templateSettings['templateName'];
$this->companyName = $templateSettings['companyName'];
$this->projectName = $templateSettings['projectName'];
$this->projectId = $templateSettings['projectId'];
} | {
"domain": "codereview.stackexchange",
"id": 21001,
"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, laravel",
"url": null
} |
python, multithreading, python-2.x, python-requests
while True:
threading.Thread(target=download, args=(raw_input(),)).start()
if __name__ == '__main__':
sessions_queue = Queue.Queue()
KB = 1024
MB = 1024*KB
# TODO: optimal size?
chunk = 100*KB
main()
I am using it with about 100 IP addresses on my Ethernet -- each with about 100 KB/s speed. What'd be optimal configuration? (numbers of threads, chunk size) You could rewrite your get_IPs function to be a list comprehension instead:
return [i.rsplit(' ', 1)[-1] for i in map(str.strip, os.popen('ipconfig'))
if i.startswith('IP')]
map will call strip on all of the results from 'ipconfig' and then you can iterate over that, ignoring any values that don't start with "IP".
In worker you're using a loop to retry after timeouts. But you're just using 2 arbitrarily. Use a constant here so it's clear what you're doing, and easy to change later:
You also multiple times open files, but you should always try to use with, known as the context manager. It automatically closes the file even in the event that an error is raised. It's the safest way to open a file.
with open(filepath) as filename:
execute_code_with(filename)
print("Done with filename")
Once you leave that indented block, the file is automatically closed. No need to even call filename.close(). | {
"domain": "codereview.stackexchange",
"id": 18633,
"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, multithreading, python-2.x, python-requests",
"url": null
} |
homework-and-exercises, general-relativity, black-holes, metric-tensor, geodesics
which is the $r$-component of the geodesic equation
$$\frac{d^2x^\mu}{d\tau^2}+\Gamma^\mu_{\alpha\beta}\frac{dx^\alpha}{d\tau}\frac{dx^\beta}{d\tau}=0 \tag{6}$$
in the case of a purely radial geodesic, with the equation
$$1=\left(1-\frac{2M}{r}\right)\left(\frac{dt}{d\tau}\right)^2-\left(1-\frac{2M}{r}\right)^{-1}\left(\frac{dr}{d\tau}\right)^2, \tag{7}$$
which comes from the expression for the proper time as given by the metric,
$$d\tau^2=\left(1-\frac{2M}{r}\right)dt^2-\left(1-\frac{2M}{r}\right)^{-1}dr^2. \tag{8}$$
Eliminating $dt/d\tau$ between the (5) and (7) gives (3).
With the $G$'s and $c$'s restored, $r(\tau)$ is
$$r(\tau)=\left[\frac{9GM(\tau_0-\tau)^2}{2}\right]^{1/3}. \tag{9}$$
The derivation of (1) is only a bit more complicated. From (4) one has
$$\left(\frac{dr}{d\tau}\right)^2=\frac{2M}{r}. \tag{10}$$
Substituting this into (7) gives
$$\left(\frac{dt}{d\tau}\right)^2=\left(1-\frac{2M}{r}\right)^{-2} \tag{11}$$
Thus | {
"domain": "physics.stackexchange",
"id": 54203,
"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, general-relativity, black-holes, metric-tensor, geodesics",
"url": null
} |
terminology-and-notation
Title: What is meant by "local isometry" in this paper? I apologize for such a basic question here. I've been reading this paper, and I am wondering what is the usage of the term "local isometry" in the paper? The paper is open access, so you can access it and search with CTRL+F for "isometry" and "isometries" for context. In particular, they say,
Recall that the set of Schmidt coefficients of a state is preserved under local isometries.
By "local isometries" do they just mean bijective linear maps $\mathcal{H}\rightarrow\mathcal{H}'$ that preserve the inner-product? If so, why do we say they are "local?" Why not just call them isometries?
I can understand that unitary isn't the right word, because unitary transformations have the same domain and codomain. Is my understanding here correct, or am I way off? If you're interested in Schmidt coefficients it means you have a bipartite structure to your Hilbert space. Then local just means that the isometry is of the form $V_1\otimes V_2$ where $V_1$ is an isometry acting locally on the first system in the bipartition and similarly $V_2$ acts only on the second system.
Operationally the isometey can be performed by two separated parties who only have access to the their respective local systems. | {
"domain": "quantumcomputing.stackexchange",
"id": 3618,
"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-and-notation",
"url": null
} |
php, security, validation, form
if(isset($_POST['lastName'])){
if (!preg_match("/^[A-Za-z\\- \']+$/",$_POST['lastName'])) {
$errormsg[] = 'Last name may only contain letters,a hyphen or a single quote';
}
}
if(isset($_POST['busName'])){
if (!preg_match("/^[0-9A-Za-z\\- \&\.\\']+$/",$_POST['busName'])) {
$errormsg[] = "Business name may only contain letters, numbers and . & ' -";
}
}
if(isset($_POST['title'])){
if (!preg_match("/^[0-9A-Za-z\\- \&\.\\']+$/",$_POST['title'])) {
$errormsg[] = "Business name may only contain letters, numbers and . & ' -";
}
}
if(isset($_POST['bio'])){
if (!preg_match("/^[0-9A-Za-z\\- \&\.\,\(\)\$\?\%\\']+$/",$_POST['bio'])) {
$errormsg[] = "Bio name may only contain letters, numbers and ?$%&()-,.";
}
}
if(isset($_POST['question'])){
if (!preg_match("/^[0-9A-Za-z\\- \&\.\,\(\)\$\?\%\\']+$/",$_POST['question'])) {
$errormsg[] = "Question name may only contain letters, numbers and ?$%&()-,.";
}
} | {
"domain": "codereview.stackexchange",
"id": 16690,
"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, security, validation, form",
"url": null
} |
c++, io, windows, serial-port
// event flag
dcb.EvtChar = '\0';
// set suitable flow control settings
switch (settings_.flowcontrol_) {
case FLOWCONTROL_HARDWARE_RTSCTS: // most common hardware flow control
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
dcb.fOutxCtsFlow = 1;
dcb.fOutxDsrFlow = 0;
dcb.fOutX = 0;
dcb.fInX = 0;
break;
case FLOWCONTROL_HARDWARE_DTRDSR: // not very common hw flow control
dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
dcb.fRtsControl = RTS_CONTROL_ENABLE;
dcb.fOutxCtsFlow = 0;
dcb.fOutxDsrFlow = 1;
dcb.fOutX = 0;
dcb.fInX = 0;
break;
case FLOWCONTROL_XONXOFF: // software flow control
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fRtsControl = RTS_CONTROL_ENABLE;
dcb.fOutxCtsFlow = 0;
dcb.fOutxDsrFlow = 0;
dcb.fOutX = 1;
dcb.fInX = 1;
break;
case FLOWCONTROL_OFF: // no flow control
dcb.fDtrControl = DTR_CONTROL_ENABLE;
dcb.fRtsControl = RTS_CONTROL_ENABLE;
dcb.fOutxCtsFlow = 0;
dcb.fOutxDsrFlow = 0;
dcb.fOutX = 0;
dcb.fInX = 0;
break;
} | {
"domain": "codereview.stackexchange",
"id": 42150,
"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++, io, windows, serial-port",
"url": null
} |
algorithm, scala
Title: Distinct sums of integers I need to get the distinct sums of naturals of a natural
What I came up with is:
type Sum = Stream[Int] //should maintain the invariant that
//* all Ints are positive
//* is non-strictly decreasing
//* is non-empty
def makesums(i: Int): Stream[Sum] = {
/* Schmear will try to "schmear" a sum by decreasing the first number by one,
and adding one again in the first position that won't violate the above invariants.
This is possible when the stream is not all 1's, and the above invariants are met for
the argument.
returns an Option[Sum], which is Some(schmeared) if the above is possible,
and None otherwise.
*/
def schmear(sum: Sum): Option[Sum] = sum match {
//if we can decrease the head and increase the next element while
//staying ordered, do that
case head #:: s #:: tail if (head - 1 >= s + 1) =>
Some((head - 1) #:: (s + 1) #:: tail)
//otherwise, if the head is only one larger than the second element, do the same,
//but smear the tail, restoring the invariant
case head #:: s #:: tail if head > s =>
schmear((s + 1) #:: tail).map(nt => (head - 1) #:: nt)
//otherwise, if there are at least two elements, just schmear the tail,
//and keep the orignal head
case head #:: s #:: tail =>
schmear(s #:: tail).map(nt => head #:: nt)
//otherwise, if the head is larger than 1, decrease by 1, and put a 1 at the end
case head #:: tail if (head > 1) =>
Some((head - 1) #:: tail #::: Stream(1))
//otherwise, it's not possible.
case _ => None
} | {
"domain": "codereview.stackexchange",
"id": 18228,
"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": "algorithm, scala",
"url": null
} |
machine-learning, nlp, word2vec, word-embeddings
Title: Do repeated sentences impact Word2Vec? I'm working with domain-oriented documents in order to obtain synonyms using Word2Vec.
These documents are usually templates, so sentences are repeated a lot.
1k of the unique sentences represent 83% of the text corpus; while 41k of the unique sentences represent the remaining 17% of the corpus.
Can this unbalance in sentence frequency impact my results? Should I sub-sample the most frequent sentences? Are the sentences exactly the same, word to word? If that is the case I would suggest removing the repeated sentences because that might create a bias for the word2vec model, ie. repeating the same sentence would overweigh those examples single would end with higher frequency of these words in the model. But it might be the case that this works in your favor for find synonyms. Subsample all the unique sentences, not just the most frequent ones to have a balanced model.
I would also suggest looking at the FastText model which is built on top of the word2vec model, builds n grams at a character level. It is easy to train using gensim and has some prebuilt functions like model.most_similar(positive=[word],topn=number of matching words) to find the nearest neighbors based on the word embeddings, you can also use model.similarity(word1, word2) to easily get a similarity score between 0 and 1. These functions might be helpful to find synonyms. | {
"domain": "datascience.stackexchange",
"id": 6308,
"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": "machine-learning, nlp, word2vec, word-embeddings",
"url": null
} |
homework-and-exercises, newtonian-mechanics, spring
Title: 2D Mass Spring System - Where does $m_3$ go to? I am struggling to frame proper equations for the following two-dimensional mass spring System:
1D Model
Basics first:
I started with a simple one-dimensional mass-spring System to model something like a Crash of two rail vehicles:
The two masses m1 and m2 are the Center of Gravities of the two rail vehicles, while the two springs with their corresponding stiffnesses k1 and k2 model the differences in stiffness of the two colliding wagons.
By assuming the mass m3 to be 0, the displacement $S_{M}$ of m3 can be calculated as:
$$
S_{M}=\frac{k_{1}S_{1}+k_{2}S_{2}}{k_{1}+k_{2}}
$$
2D Model
Now I was wondering how this model applies to oblique Scenarios and whether we could consider longitudinal and lateral stiffnesses rather than the 1D springs. | {
"domain": "physics.stackexchange",
"id": 25028,
"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, newtonian-mechanics, spring",
"url": null
} |
c#, performance, array, collections, enum
Title: Poker app in C# I am developing a poker application using C#. It is almost done, and I'm looking for improvements. One of the things I wonder is whether I should change my method that checks if the player has a flush. It's quite big compared to the others but it works just fine, however, something can be improved. Maybe put some of the stuff in collections, but I am not sure if that's going to hurt the overall performance.
In the following code, I'm using the % operator and dividing by 4 because there are 4 cards of the same type but with different colors. The deck of cards for playing poker consists of 52 cards. I start to count them from 0. If we take the cards starting from ace up to king we will have 0-51 what we can do from here is assume that each Ace (0,1,2,3) has result when divided by 4 , 0 (0 /4 = 0, 1 / 4 = 0) so on.
But in the current method, I am using the % operator. This helps me determine what's the current color of the card because the clubs are 0-4-8-12-16. When we divide 0,4,8,12,16 by 4 (4 % 4) we get result 0. These are the Clubs and Diamonds: 1-5-9-13-17 and 1 % 4 = 1. That's what we are getting from the f1,f2,f3,f4 arrays. How many cards of each color we have on the table.
//straight1[] contains info about the five cards on the table | {
"domain": "codereview.stackexchange",
"id": 18829,
"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, array, collections, enum",
"url": null
} |
ros, joint, moveit, ros-industrial
My controllers.yaml file:
controller_list:
- name: ""
action_ns: joint_trajectory_action
type: FollowJointTrajectory
joints: [cart1_joint, main1_joint, elbow1_joint, forearm1_joint, wrist1_joint, gripper1_joint]
So, how do I get this done? Is it still possible with MoveIt planning groups, or is there another way in which this should be done? I also need this in order to be able to control the different parts of the gripper at the end of the arm.
Originally posted by BvOBart on ROS Answers with karma: 61 on 2018-01-09
Post score: 2 | {
"domain": "robotics.stackexchange",
"id": 29701,
"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, joint, moveit, ros-industrial",
"url": null
} |
acceleration, relativity, time-dilation
Title: As a ship accelerates to relativistic speeds, would its fuel consuption appear to speed up due to time dilation? Given a ship under constant acceleration toward relativistic speed, for example 0.9c...
(a) Is it safe to assume the fuel consumption is constant over distance travelled? and if so...
(b) Would fuel consumption appear to the pilot to increase over time due to dilation effects?
(a) Is it safe to assume the fuel consumption is constant over distance travelled?
No. As fuel is burned, the spacecraft decreases in mass. If we're saying the spacecraft has a constant acceleration, this means that its thrust (and thus fuel consumption rate) must decrease in time to maintain a constant acceleration with a lower mass.
(b) Would fuel consumption appear to the pilot to increase over time due to dilation effects?
No. The pilot and the spaceship are in the same frame of reference, so there is no time dilation effects between the two. The fuel consumption rate the spacecraft sees is exactly what the pilot will see as long as the pilot is on the spacecraft. Time dilation only affects things moving at different speeds relative to each other.
Bonus: for an outside observer
No. Even if it were the case that fuel consumption were constant in the frame of the spacecraft, to an outside observer the time dilation effects means that the apparent passage of time on the spacecraft is slower than for the observer. Thus, fuel consumption would be observed to decrease with time due to the time dilation. | {
"domain": "physics.stackexchange",
"id": 47327,
"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": "acceleration, relativity, time-dilation",
"url": null
} |
quantum-gate, quantum-state, error-correction, quantum-memory
$$|\psi_1\rangle = \frac{1}{2}(|000\rangle + |001\rangle + |010\rangle + |111\rangle)$$
Now, if we desire to find out if $q_1q_0 = 11$, we can measure only $q_2$ in the $Z$ basis. If $1$ is obtained - done. If $0$ is obtained - that means $q_1q_0 \neq 11$, and the quantum statevector evolves to:
$$|\psi_2\rangle = \frac{1}{\sqrt{3}}(|000\rangle + |001\rangle + |010\rangle)$$ | {
"domain": "quantumcomputing.stackexchange",
"id": 4641,
"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-gate, quantum-state, error-correction, quantum-memory",
"url": null
} |
magnetic-fields
Title: Magnetic field from a point charge: in which reference frame is the velocity vector defined? The magnetic field generated by a point charge is given by
$\vec B =\frac{\mu_0}{4\pi}\frac{q \vec v \times \hat r}{r^2}$
I understand that $\hat r$ denotes the unit position vector with the point charge as the origin. However I don't understand in what reference frame is the velocity vector $\vec v$ defined? It's the inertial frame in which you wish to find the magnetic field.
update
It might help to make the definition more general. Consider an arbitrary origin in an inertial reference frame, the frame you wish to find the magnetic field. Let $\vec{r_0}$ be the position vector to the field point (referenced from the origin), and $\vec{r_1}$ the position vector of the charged particle. Let $$\vec{r}_{01} = \vec{r_0}-\vec{r_1}$$ then $$\vec{B} = \frac{\mu_0}{4\pi} \frac{q\,\vec{v}\times\hat{r_{01}}}{|\vec{r}_{01}|{}^2}$$
Now the locations of the source and field points are explicit. It also removes the charged particle from the origin. Nature doesn't care where we place the origin. Perhaps that helps. | {
"domain": "physics.stackexchange",
"id": 21561,
"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": "magnetic-fields",
"url": null
} |
pcl, rosmake, pcl-ros
[rosmake-2] Starting >>> xmlrpcpp [ make ]
[rosmake-3] Starting >>> rosunit [ make ]
[rosmake-0] Starting >>> roscpp_serialization [ make ]
[rosmake-2] Finished <<< xmlrpcpp ROS_NOBUILD in package xmlrpcpp
[rosmake-1] Starting >>> pluginlib [ make ]
[rosmake-3] Finished <<< rosunit ROS_NOBUILD in package rosunit
[rosmake-2] Starting >>> bond [ make ]
[rosmake-0] Finished <<< roscpp_serialization ROS_NOBUILD in package roscpp_serialization
[rosmake-2] Finished <<< bond ROS_NOBUILD in package bond
[rosmake-1] Finished <<< pluginlib ROS_NOBUILD in package pluginlib
[rosmake-3] Starting >>> cminpack [ make ]
[rosmake-0] Starting >>> roscpp [ make ]
[rosmake-0] Finished <<< roscpp ROS_NOBUILD in package roscpp
[rosmake-2] Starting >>> flann [ make ]
[rosmake-3] Finished <<< cminpack [PASS] [ 0.02 seconds ]
[rosmake-1] Starting >>> common_rosdeps [ make ]
[rosmake-0] Starting >>> rosout [ make ]
[rosmake-1] Finished <<< common_rosdeps ROS_NOBUILD in package common_rosdeps
[rosmake-3] Starting >>> bondcpp [ make ]
[rosmake-0] Finished <<< rosout ROS_NOBUILD in package rosout
[rosmake-0] Starting >>> roslaunch [ make ]
[rosmake-3] Finished <<< bondcpp ROS_NOBUILD in package bondcpp
[rosmake-3] Starting >>> nodelet [ make ] | {
"domain": "robotics.stackexchange",
"id": 10088,
"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": "pcl, rosmake, pcl-ros",
"url": null
} |
classical-mechanics
Title: Does the normal reaction on pull up bar change during the pull ups? Intuitively, I know the answer but I can't think of the right math.
I found this question but none of the answers were satisfying enough for me. Human body is not a rigid body so do how do we even apply $\Sigma F=ma_{net}$ over it?
Does normal reaction on pull up bar changes during the pull ups?
The normal reaction of the bar changes while the body moves upwards (or downwards) because body does not move at a constant acceleration. You are right to say that human body is a complex system which cannot be modelled as a simple particle, but Newton's laws of motion still apply. For the body to accelerate there must be a net force which will provide the acceleration. In your example this comes from the bar
$$F_\text{bar} = m(a + g)$$
where $m$ is total mass of the body, and $a$ is its vertical acceleration.
Another interesting example similar to this would be doing squats on a scale. As body accelerates downwards the scale shows lower weight, and as the body slows down to rest the scale shows larger weight. Once the body is at rest, the scale shows the normal weight.
Although human body is a complex system that has many particles, it can be considered as a particle with all the mass concentrated at the center of mass.
When a collection of particles is acted on by external forces, the center of mass moves as though all the mass were concentrated at that point and acted on by the net external force. | {
"domain": "physics.stackexchange",
"id": 86508,
"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
} |
ros
[ rosmake ] Output from build of package roscv written to:
[ rosmake ] /home/admin-pc/.ros/rosmake/rosmake_output-20131207-114326/roscv/build_output.log
[rosmake-4] Finished <<< roscv [FAIL] [ 2.82 seconds ]
[ rosmake ] Halting due to failure in package roscv.
[ rosmake ] Waiting for other threads to complete.
[ rosmake ] Results:
[ rosmake ] Built 39 packages with 1 failures.
[ rosmake ] Summary output to directory
[ rosmake ] /home/admin-pc/.ros/rosmake/rosmake_output-20131207-114326 | {
"domain": "robotics.stackexchange",
"id": 16361,
"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
} |
linear-systems, estimation, system-identification, least-squares, linear-algebra
$$
$$
\underline{v}_k = X^H_k\underline{y}_k
$$
$$
\underline{v}_{k+L} = \underline{v}_k + \tilde{X}^H_{k+L}\underline{\tilde{y}}_{k+L}
$$
I would keep state for the latter intermediates and for $(X^H_{k}X_{k})^{-1}$. The expensive part here is usually the calculation of $(I+\tilde{X}_{k+L}\tilde{X}^H_{k+L})^{-1}$, since it is a rank $L>1$ update.
Apologies if I have typos above. I was deriving as I typed, and eventually I couldn't see the wysiwyg output anymore. ;) Hopefully, you can see the jist of the approach, nonetheless. There certainly could be further intermediate and state optimization. I didn't go back to RLS to remind me of how it was wrung to minimize operations, but it probably goes somewhere along these lines.
Finally, given the above block update approach, the question for you is - which is preferred: $L$ rank 1 updates (RLS) or 1 rank $L$ ("block RLS" as above) update? This depends on your situation and environment. A block approach may be better if the rank-1 updates would be done in an interpreted loop (e.g. Matlab), and one may be better than the other for accumulated precision errors. | {
"domain": "dsp.stackexchange",
"id": 6267,
"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": "linear-systems, estimation, system-identification, least-squares, linear-algebra",
"url": null
} |
electrostatics, photons, quantum-electrodynamics, coulombs-law, virtual-particles
The actual plugging-and-chugging of this is a bit tedious, so I will skip it. it is more or less straight-forward; one must keep various factors and signs straight, that's all.
Now for the funny part: nothing above has been actually "quantum" in any way. The notation is suggestive, with the bra-ket notation reminiscent of S-matrix notation, and the $1/(k^2\pm i\epsilon)$ recognizable as the Feynman propagator for a photon. But all manipulations are classical, and its still a stretch to imagine "a bath of photons" in the above.
To get to "quantum", one instead starts with the QFT vacuum state $|0\rangle$. A single-photon state can be obtained by applying a raising operator to it: $|1\rangle = a^\dagger|0\rangle$ To maintain contact with scattering, momenta should be attached, and so one writes
$$| \vec k\rangle = a^\dagger_{\vec k} |0\rangle$$
as a single photon state. To get to the multi-photon state, one has to insert the raising operator $a^\dagger$ into eqn (1) and (2) to now get operator equations that correspond to an electrostatic field for a charged capacitor. The sum over charges $\sum_n q_n$ becomes a product. Again, this involves more painful plugging-and-chugging.
To make it clear what the final result is, it is easiest to write it as a Feynman diagram, which is, of course, the whole point of these diagrams: to avoid the pain of writing the long integral expressions. The diagram is obviously at tree-level, and it is manifestly multi-photon. | {
"domain": "physics.stackexchange",
"id": 94423,
"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, photons, quantum-electrodynamics, coulombs-law, virtual-particles",
"url": null
} |
homework-and-exercises, electrostatics, stability
Hence by the partial derivative test for stability I have a stable equilibrium. A local minimum of potential.
Now starts my confusion. According to what I learnt in Laplace's equation $\Delta V=0$ for potential, in a charge free region(I take the region without charges with origin in it) there can never have a local minima or maxima within the boundary. This contradicts with the above conclusion that we have a minimum of potential.
Please help me, to see the cause of this contradiction. The Coulomb Potential is a solution to Laplace's equation in 3 dimensions. In 2 dimensions the equivalent solution is a logarithmic potential. You have written down the Coulomb potential for 4 charges but then treat the problem as 2 dimensional, which is causing your problems. To resolve this you need to add a load of $z^2$s to your potential.
If you consider placing a fifth charge at the origin it will be repelled by each of the 4 original charges, so it is not surprising that the forces acting on it in the xy plane push it back to the centre. It is, however, clearly unstable in the z direction as it is repelled by the entire existing arrangement of charges. | {
"domain": "physics.stackexchange",
"id": 23876,
"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, electrostatics, stability",
"url": null
} |
thermodynamics, statistical-mechanics, entropy, information
The Shannon entropy (per oscillator) is then:
$$S = -\sum\limits_{n = 0}^\infty p(n) \log p(n) = \frac{\beta\,\hbar\,\omega\,e^{\beta \,\hbar\,\omega}}{e^{\beta\,\hbar\,\omega}-1} - \log \left(e^{\beta\,\hbar\,\omega}-1\right)$$
so the thermodynamic temperature is then given by (noting that the only way we change this system's energy is by varying $\beta$):
$$T^{-1} = \partial_{\left<E\right>} S = \frac{\mathrm{d}_\beta S}{\mathrm{d}_\beta \left<E\right>} = \beta$$
but this temperature is not equal to the mean particle energy at very low temperatures; the mean particle energy is:
$$\begin{array}{lcl}\left<E\right> &=& \frac{1}{\beta}+\frac{1}{12}\,\beta\,\hbar^2\omega^2-\frac{1}{720}\,\beta^3 \,\hbar^4\,\omega^4+\frac{\beta^5\,\hbar^6\,\omega^6}{30240}+O\left(\beta^7\right) \\
&=& T+\frac{1}{12}\,T^{-1}\,\hbar^2\,\omega^2-\frac{1}{720}\,T^{-3}\,\hbar ^4\, \omega^4+\frac{T^{-5}\,\hbar^6\,\omega^6}{30240}+O\left(T^{-7}\right)\end{array}$$ | {
"domain": "physics.stackexchange",
"id": 9531,
"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": "thermodynamics, statistical-mechanics, entropy, information",
"url": null
} |
c++, ros-foxy, gazebo-11
class ReBroadcaster : public rclcpp::Node
{
public:
ReBroadcaster() : Node("rebroadcaster"), count_(0)
{
subscription_ = this->create_subscription<custom_type_one>(topic_one, 10,
std::bind(&ReBroadcaster::topic_callback_one, this, _1));
subscription_two = this->create_subscription<custom_type_two>(topic_two, 10,
std::bind(&ReBroadcaster::topic_callback_two, this, _1));
RCLCPP_INFO(this->get_logger(), "Constructed subscribers!");
}
private:
void topic_callback_one(const custom_type_one::SharedPtr msg) const
{
const custom_type_one::SharedPtr a = msg; // just so there is no unused var warning
RCLCPP_INFO(this->get_logger(), "Got one!");
}
void topic_callback_two(const custom_type_one::SharedPtr msg) const
{
const custom_type_two::SharedPtr a = msg; // just so there is no unused var warning
RCLCPP_INFO(this->get_logger(), "Got ---TWO!");
}
size_t count_;
rclcpp::Subscription<custom_type_one>::SharedPtr subscription_;
rclcpp::Subscription<custom_type_two>::SharedPtr subscription_two;
}; // end of class
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<ReBroadcaster>());
rclcpp::shutdown();
return 0;
}
Originally posted by reza on Gazebo Answers with karma: 11 on 2020-09-28
Post score: 1 | {
"domain": "robotics.stackexchange",
"id": 4547,
"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++, ros-foxy, gazebo-11",
"url": null
} |
ros, navigation, transforms, iai-kinect2, move-base
Title: Filtering depth data of the form sensor_msgs/Image from Kinect 2
Hi all,
--See Update 1--
I am using iai_kinect2 to get a depth cloud in the form sensor_msgs/Image. Now, I want to filter this depth cloud (like remove points on the ground, outliers, etc.). I can use a Pass-through filter but it works only on sensor_msgs/PointCloud2 whereas I have sensor_msgs/Image. Now, my question is :
I can convert sensor_msgs/Image to sensor_msgs/PointCloud2 using depth_image_proc and do filtering but then, how can I convert the filtered Pointcloud (in form sensor_msgs/Pointcloud2) back to depth cloud (in form sensor_msgs/Image) to use it with depthimage_to_laserscan ?
Or, How can I directly filter depth_cloud in the form sensor_msgs/Image using pass-through filters, etc.. ?
I know I can use pointcloud_to_laserscan to convert filtered_pointcloud to laser scan but it will be less efficient and therefore, I want to know how can I do the above conversion or directly filter the depth_cloud?
Update 1 :
As suggested by @Akif, I used pcl:toROSMsg to convert sensor_msgs/PointCloud2 to sensor_msgs/Image. It compiled properly but during run time, when I try to visualize it in RVIZ, I get the following :
MessageFilter [target=kinect2_link ]: Discarding message from [unknown_publisher] due to empty frame_id. This message will only print once. | {
"domain": "robotics.stackexchange",
"id": 23324,
"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, navigation, transforms, iai-kinect2, move-base",
"url": null
} |
java, sql, sql-server
In JDBC, the default state of a connection is getAutoCommit() == true.
you keep changing this to be false, then running some selects, and then setting it back to true.
if it was true when you came in, then you set it to false. No problem, you then return it to true when you leave... but, if it was false, you keep it as false, then, when you leave, you commit the transaction that may have been open when your method was called.... this is probably not what you want.
It is possible that there are other areas in your code where you are doing data changing statements, but, it is not apparent where. In your code, all the SQL statements are selects, and you are not changing anything, so your you are not doing any fancy locking. Why change the state of autoCommit at all?
you are not closing your ResultSets.
you have a very nice, neat final block which closes rs, rs1, and rs2, but, there are many, many rs1 and rs2 instances. You need to be closing them inside the inner rs loop:
rs = getItemBatch.executeQuery();
while (rs.next()) {
getForArtNr.setInt(1,rs.getInt("Cartnr"));
try {
rs1 = getForArtNr.executeQuery();
getItemHgrupp.setInt(1,rs.getInt("Hgrupp"));
rs2 = getItemHgrupp.executeQuery();
if (rs1.next() && rs2.next()) {
ret_xml += "<item><Hgrupp>" + rs2.getString("Namn") + "</Hgrupp><Price>" + rs.getInt("Prisgrupp") + "</Price><Moms>" + rs.getInt("Moms") + "</Moms><Cartnr>" + rs.getInt("Cartnr") + "</Cartnr><Artnr>" + rs1.getInt("Artnr") + "</Artnr></item>";
} | {
"domain": "codereview.stackexchange",
"id": 6398,
"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, sql, sql-server",
"url": null
} |
huffman-coding
a_3a_0 & 0.025 & \texttt{01111} \\ \hline
a_3a_1 & 0.015 & \texttt{011011} \\ \hline
a_3a_2 & 0.0075 & \texttt{01100100} \\ \hline
a_3a_3 & 0.0025 & \texttt{01100101} \\ \hline
\end{array}
$$
This has an average code length of $3.3275$, whereas the double-output source has an entropy of $3.30$ for an efficiency of $99.04\%$.
If you continued this process to 3 symbols at a time, you'd be able to get a $99.24\%$ efficient code. To 4 symbols, $99.43\%$ efficient. | {
"domain": "cs.stackexchange",
"id": 12228,
"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": "huffman-coding",
"url": null
} |
performance, matlab, signal-processing
For the short example input, these functions both run too fast for accurate timing. I see 3.1 μs and 1.4 μs, my version is only twice as fast as yours. But for larger inputs the differences become more important (I figured that the cumulative sum of a random process would imitate appropriately your drifting variable):
ts = cumsum(randn(1,1000));
0.29 ms and 8.33 μs, an order of magnitude difference.
ts = cumsum(randn(1,100000));
Now I see 1.66 s and 0.812 ms, 3 orders of magnitude difference.
Because method1 is quadratic in the input length, and method2 is linear, the time difference grows quadratically. | {
"domain": "codereview.stackexchange",
"id": 30298,
"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": "performance, matlab, signal-processing",
"url": null
} |
php, security, email
?>
I ended up using the ValidForm Builder because it has better security, great customizability, and an easy implementation — quoting from their site:
The API generates XHTML Strict 1.0 compliant code.
Field validation on the client side to minimize traffic overhead.
Field validation on the server side to enforce validation rules and prevent tempering with the form through SQL injection.
Client side validation displays inline to improve user satisfaction. No more annoying popups that don't really tell you
anything.
Easy creation of complex form structures.
Uses the popular jQuery Javascript library for DOM manipulation.
Completely customizable using CSS.
Automatic creation of field summaries for form mailers in both HTML and plain text.
Quoting other benefits:
First of all, it's open source and therefore completely free!
Super fast web form creation.
Get rid of SQL injection problems.
Create standards based CSS forms. No tables inside.
Make form entry fun for the user. More feedback from your website. As far as I think, your script is good and will achieve the required task. But before finalising on this script, you should read about PHPMAILER. It is easy to implement and will provide you many features like to add CC, BCC, and attachments. The mail() function is the easiest way, but as far as I think, it is a bit limited. Also, PHPMailer is easily available on the Internet. | {
"domain": "codereview.stackexchange",
"id": 2814,
"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, security, email",
"url": null
} |
exoplanet, n-body-simulations, raw-data
Title: Where to find data on orbits of exoplanetary systems? I hope this is the correct place to ask this question which entails asking if there is a database much like the JPL NASA one for the solar system, but for exoplanetary systems? I am conducting an n body simulation as in the assignment it states "Study the stability of known exoplanetary data. You will need to look up the available planetary data." But from what I have seen there is no such data easily accessible. For my simulation, I input the mass, initial position and initial position. Is there a website or database that could help, I have seen data on these systems such as mass and the radius of the orbit, but that would be estimating the initial velocity and starting positions which I didn't deem the most scientific. Any thoughts or ideas are much appreciated. One of, if not the most comprehensive exoplanet table is found at exoplanet.eu which also lists the angle of the ascending node and the time of perihelion, time-of-transit, stellar data etc as far as these data are available including references to the papers the data are taken from.
You can download that convenient as csv for processing. | {
"domain": "astronomy.stackexchange",
"id": 5730,
"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": "exoplanet, n-body-simulations, raw-data",
"url": null
} |
optics, everyday-life, reflection, vision
Title: How do car rear-view mirrors work? I wonder, how does a car rear-view mirror work?
When there is a car behind me with high-beam, all I do is flip a tong at the bottom of the mirror to relax the lights!
Are there two mirrors in it, one darker than the other? For manual anti-glare mirrors, the glass is actually a prism with the silvered rear surface not parallel to the front surface
In day-time position, drivers are seeing reflections from the rear surface with large amounts of reflected light reaching their eyes
In night-time anti-glare position, drivers are seeing reflections from the front surface of the glass, with much less light going into their eyes; the brighter rear reflection goes elsewhere. This is still enough to distinguish headlights behind, but not much else, and substantially less than if the day-time position was used at night, so reducing the contrast which could be blinding if the following vehicles were foolish enough to use full-beam headlights
See https://en.wikipedia.org/wiki/Rear-view_mirror#Anti-glare for more (and the automated alternative) which has these two diagrams | {
"domain": "physics.stackexchange",
"id": 58050,
"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, everyday-life, reflection, vision",
"url": null
} |
feature-selection, pca, matlab
Title: Does PCA decrease the feature on my Data set or just decrease the dimension? I'm new in AI and sorry if my question is simple. I have a data set and want to use PCA to decrease the feature but after some research on the internet I'm confused about decreasing dimensions and features.
As an example I have a data set with 50 rows and 10 columns, if I use PCA it will reduce a data set with 50x5 (as an example) or 50x10 and just removed some dimensions?
I want to do it in MATLAB and want to use PCA function and don't want to write PCA function by myself.
What is the PCA parameters in MATLAB to decrease the feature? It's a lot of parameters and confused me. From the documentation:
coeff = pca(X) returns the principal component coefficients, also known as loadings, for the $n$-by-$p$ data matrix X. Rows of X correspond to observations and columns correspond to variables. The coefficient matrix is $p$-by-$p$. Each column of coeff contains coefficients for one principal component, and the columns are in descending order of component variance. By default, pca centers the data and uses the singular value decomposition (SVD) algorithm.
The values in coef represent the transformation from the original features (rows of coef) to the principal components (columns of coef). You'll want to keep only the first $k$ columns, then multiply your data matrix by this matrix.
Your features are the dimensions that your data lives in, so number of features and dimension are the same. Very roughly speaking, PCA rotates the the feature axes to align to the most significant directions rather than the original feature directions, then selects only the most significant directions to keep, thus reducing the dimensionality of your problem. But it also means your new columns won't represent pure features anymore, but linear combinations of them.
If you keep all of the new columns, you won't reduce dimensionality; but your new features will be ordered in such a way that the first ones capture the most variance of your data. | {
"domain": "datascience.stackexchange",
"id": 5065,
"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": "feature-selection, pca, matlab",
"url": null
} |
c++, template
//// ////////////////////////////////////////////////
// Throws an exception if the index is too large. //
//////////////////////////////////////////////// ////
template<typename index_type,
typename element_count_type>
static void throw_index_too_large(index_type index,
element_count_type size)
{
std::stringstream ss;
ss << "index(" << index << ") >= elem_count(" << size << ")";
throw std::runtime_error{ss.str()};
}
template<typename IteratorElem,
typename IteratorIndex>
static void check_indices(IteratorElem elem_begin,
IteratorElem elem_end,
IteratorIndex index_begin,
IteratorIndex index_end)
{
// Find the length of the element sequence:
typename std::iterator_traits<IteratorElem>
::difference_type elem_count = std::distance(elem_begin,
elem_end);
using IndexType =
typename std::iterator_traits<IteratorIndex>::value_type;
// Check that each index does not refer outside the element sequence:
std::for_each(index_begin, index_end, [elem_count](IndexType index) {
if (index < 0) { throw_index_negative(index); }
if (index >= elem_count) { throw_index_too_large(index,
elem_count);}
});
} | {
"domain": "codereview.stackexchange",
"id": 29016,
"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++, template",
"url": null
} |
• @Lawrence no, different teams do have different opponents. Notice, however, that the opponent of the opponent of a team is not (quite) the original team, so you can't "pair them off" in the way you seem to be imagining. – Ben Millwood May 26 '15 at 14:35 | {
"domain": "stackexchange.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9873750510899382,
"lm_q1q2_score": 0.8680475844852755,
"lm_q2_score": 0.8791467675095294,
"openwebmath_perplexity": 536.0966710893548,
"openwebmath_score": 0.6815144419670105,
"tags": null,
"url": "https://puzzling.stackexchange.com/questions/15412/99-bags-of-apples-and-oranges?noredirect=1"
} |
c, strings
// verify allocation was successful before using buffer
if (ReturnStr != NULL)
ReturnStr[0] = '\0';
// return buffer
return(ReturnStr);
}
This could also be condensed a little more:
char *InitStr(){
char * ReturnStr;
if ((ReturnStr = malloc(1)) != NULL)
ReturnStr[0] = '\0';
return(ReturnStr);
}
Here is another example of checking your allocation using your AddStr() function:
char *AddStr(char *StrObj1,char *StrObj2){
void * ptr;
ptr = realloc(StrObj1,(strlen(StrObj1) + strlen(StrObj2) + 1));
if (ptr == NULL)
return(StrObj1);
StrObj1 = ptr;
strcat(StrObj1, StrObj2);
return(StrObj1);
}
You can slightly improve the runtime efficiency of this function be reducing the number of times you need to find the terminating NULL character in your strings:
char *AddStr(char *StrObj1,char *StrObj2){
void * ptr;
size_t len1;
size_t len2;
// determine length of strings
len1 = strlen(StrObj1);
len2 = strlen(StrObj2);
// increase size of buffer
if ((ptr = realloc(StrObj1, (len1 + len2 + 1))) == NULL)
return(StrObj1);
StrObj1 = ptr; | {
"domain": "codereview.stackexchange",
"id": 1877,
"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, strings",
"url": null
} |
particle-physics, energy, atomic-physics
I worked out that $E_3-E_1=12.1$ and $(E_3-E_2)+(E_2-E_1)=12.1$.
What I really want to know is what happens when the electron collides with the atom. I would really appreciate if someone can give a detailed description of this in simple language. My attempt would be:
The electron collides with the atom and goes to one of the energy levels. Since only $E_3-E_1$ and $(E_3-E_2)+(E_2-E_1)$ have a value of $12.1$ it follows that the electron can either have ended up in $n=3$ and then dropped to $n=1$, or it could have ended up in $n=3$ then dropped to $n=2$ then to $n=1$.
Is this correct? If so, how does the electron escape from the atom? It can't stay in the ground state $n=1$ after emitting the photon(s) because that is already "full".
Please correct me on anything incorrect that I said.
Thanks Your assessment of the transitions which can occur, and hence the photons which can be emitted, is correct. However, the colliding electron does not go to one of the energy levels in the atom (as Sebastian already correctly pointed out). What happens is that the colliding electron can deposit its energy in the bound electron, 'promoting' it from the ground state to the $n=3$ level. It is the subsequent decay of this electron, which remains bound throughout the whole process, which leads to photon emission. The incoming electron remains free, albeit with zero kinetic energy. | {
"domain": "physics.stackexchange",
"id": 21881,
"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": "particle-physics, energy, atomic-physics",
"url": null
} |
0. And y = d/2 at the tip. A three-hinged arch is said to be : a) statically determinate structure b) statically indeterminate structure c) a bent beam d) none of these 1. The minimum shaft diameters calculated by the torque transmission and torsional deflection methods are essentially the same for Examples 1 and 2. – A hollow cylindrical steel shaft is 1. SHAFTS: TORSION LOADING AND DEFORMATION (3. Express the inner radius to three. Shaft BC is hollow with inner and outer diameters of 90 mm and 120 mm, respectively. Calculate the minimum shaft diameter for a solid cylindrical shaft. 2 Shear Stresses Due to Torsion In a rectangular solid section, assuming elastic behavior, the shearing stresses vary in magnitude from zero at the centroid to a maximum at midpoints of the long sides as shown in Figure 5. a) the maximum and minimum shear stress in shaft BC, b) the required diameter d of shafts AB and CD if the allowable shear stress in these shafts is 65 MPa. WORKED EXAMPLE No. 5-133: If the step shaft is elastic-plastic as shown, determine the larges. As we understand, if the stress distribution is uniform, the maximum shear stress will be equal to the average stress. For solid or hollow shafts of uniform circular cross-section and constant wall thickness, the torsion relations are: where: · R is the outer radius of the shaft i. The material is 1020 hot-rolled carbon steel. Allowable Shear Stress:Applying the torsion formula. my text book has the following max shear stress due to bending for the following x-sec profiles: Solid rectangle tao(max)=(3V)/(2A) Solid circular tao(max)=(2V)/A Hallow Circular tao(max)=(4V)/(2A) By comparison, there is a higher max shear stress in the hallow circular compared to the solid circularhowever, when i tried to calculate out the max shear of a hallow squre tube, i got a value. Shafts AB and CD are solid of diameter d. The bearings shown allow the shaft to turn freely. Effects of Torsion: The effects of a torsional load applied to a bar are. From the graphs determine: • Proportional shear stress (τp) for the hollow shaft. CO 2 Estimate the shear stress due to torsion for solid | {
"domain": "foresteria-lacura.it",
"id": null,
"lm_label": "1. YES\n2. YES\n\n",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9744347868191549,
"lm_q1q2_score": 0.8141242283557442,
"lm_q2_score": 0.8354835432479663,
"openwebmath_perplexity": 1072.6670445682296,
"openwebmath_score": 0.7154282927513123,
"tags": null,
"url": "http://foresteria-lacura.it/rjry/maximum-and-minimum-shear-stress-in-hollow-circular-shaft.html"
} |
special-relativity, velocity, inertial-frames, differentiation, calculus
Please help! The particle is moving in the 1+1-dimensional Minkowski space-time on a (world-line) curve which could be represented as function of the parameter $\,\tau$, the proper time. More precisely $\,s=c\,\tau\,$ is the relativistic $''$arc length$''$, a scalar invariant under Lorentz transformations. It corresponds to the arc length (natural) parameter $\,s\,$ of Euclidean curves, a scalar invariant under space transformations.
So, for the parametric representation of the curve we have
\begin{align}
\texttt{in system } \mathrm S & : \mathbf X\left(\tau\right)\boldsymbol{=}\left[x\left(\tau\right),t\left(\tau\right)\right]
\tag{01a}\label{01a}\\
\texttt{in system } \mathrm S'\! & : \mathbf X'\!\left(\tau\right)\boldsymbol{=}\left[x'\!\left(\tau\right),t'\!\left(\tau\right)\right]
\tag{01b}\label{01b}
\end{align}
The space-time coordinates are related by a Lorentz boost transformation with velocity $\,\upsilon \in \left(-c,c\right)\,$ along the common $\,x,x'-$axis in differential form
\begin{align}
\mathrm dx' & \boldsymbol{=} \gamma_v\left(\mathrm dx\boldsymbol{-}\upsilon \mathrm dt\right)
\tag{02a}\label{02a}\\
\mathrm dt' & \boldsymbol{=}\gamma_v\left(\mathrm dt\boldsymbol{-}\dfrac{\upsilon}{c^2} \mathrm dx\right)
\tag{02b}\label{02b}\\ | {
"domain": "physics.stackexchange",
"id": 78872,
"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": "special-relativity, velocity, inertial-frames, differentiation, calculus",
"url": null
} |
discrete-signals, fourier-transform, dft, transform
and
$$Y^*(\omega)e^{-2j\omega}\Longleftrightarrow x[n]\tag{2}$$
I.e.,
$$Y^*(\omega)e^{-2j\omega}=X(\omega)\tag{3}$$
and
$$Y(\omega)=\Big[X(\omega)e^{2j\omega}\Big]^*=X^*(\omega)e^{-2j\omega}\tag{4}$$
So you got the sign of the exponent wrong. This is a common problem with this type of exercises, so just work through them systematically, and cross-check your result. | {
"domain": "dsp.stackexchange",
"id": 10415,
"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": "discrete-signals, fourier-transform, dft, transform",
"url": null
} |
ruby, functional-programming
each_with_object({}) do |element, result|
key = yield element
result[key] = result.fetch(key, []) << element
end
end
Monkey patching core classes / modules
Monkey patching core modules is generally frowned upon. If you do it, it is good practice to put your monkey patches in a separate mixin with a clear name, and mix that into the class or module you want to monkey patch. That way, it shows up in the inheritance chain, and people can use the name in the inheritance chain to make a guess at the filename, when they find this strange method in their array that they have no idea where it comes from.
Refinements
NOTE! This advice is controversial.
When monkey patching, it is a good idea to wrap your monkey patch into a Refinement, so that consumers can only pull it in when they need it, and it doesn't pollute other parts of your code.
Unfortunately, most Ruby implementations don't implement Refinements, so as nice as the benefits are, it essentially makes your code non-portable.
The Result
If we put all of the above together, we end up with something roughly like this:
module EnumerableGruppiereExtension
def gruppiere
return enum_for(__callee__) { size if respond_to?(:size) } unless block_given?
each_with_object({}) do |element, result|
key = yield element
result[key] = result.fetch(key, []) << element
end
end
end
module EnumerableWithGruppiere
refine Enumerable do
include EnumerableGruppiereExtension
end
end
using EnumerableWithGruppiere
puts [1, 2, 3, 4].gruppiere(&:even?)
#=> { false => [1, 3], true => [2, 4] } | {
"domain": "codereview.stackexchange",
"id": 38338,
"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": "ruby, functional-programming",
"url": null
} |
java, security, android, aes
/*public static byte[] hexToBytes(String str) {
if (str == null) {
return null;
}
else if (str.length() < 2) {
return null;
}
else {
int len = str.length()/2;
byte[] buffer = new byte[len];
for (int i = 0; i < len; i++) {
buffer[i] = (byte) Integer.parseInt(str.substring(i*2,i*2+2),16);
}
return buffer;
}
}*/
}
Thanks a lot in advance!
Edit: The code throws an exception because Android can't find "PBEWithSHA256And256BitAES-CBC-BC". This is when I run the code on my phone, at least. What algorithm can I take now to replace this unknown one? The algorithm for SecretKeyFactory must be compatible to AES and the key size, right? I observe the following deficiencies:
Use of strings to store the key, which is then extracted using getBytes(). This has multiple problems:
The character encoding used to convert the string to bytes can vary between Java implementations (so while the Android spec forces UTF-8 to be the default character encoding, your code won't be portable to J2SE, even though it will compile - dangerous). String.getBytes() should be deprecated if it isn't already; you should always supply an argument specifying the character encoding to use (and 99% of the time it should be "UTF-8").
Certain character encodings (including UTF-8) place additional constraints on the valid values of bytes which mean that you lose some of the keyspace. It would be better to base-64 encode it (and use android.util.Base64 to decode) or hex-encode it (using the static methods which you've posted - although see below). | {
"domain": "codereview.stackexchange",
"id": 16218,
"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, security, android, aes",
"url": null
} |
October 21, 2019, at 02:17 AM by 136.36.211.159 -
Changed lines 15-19 from:
<td><b>Value</b></td><td align="center" color="red">11</td><td align="center">8</td><td align="center">3</td><td align="center">6</td>
to:
<td><b>Value</b></td> <td align="center" bgcolor="#fb946d">11</td> <td align="center" bgcolor="#fbc76d">8</td> <td align="center" bgcolor="#bafb6d">3</td> <td align="center" bgcolor="#fbf96d">6</td>
Changed lines 22-26 from:
<td align="center"><b>Weight</b></td><td align="center">3</td><td align="center">5</td><td align="center">7</td><td align="center">4</td>
to:
<td align="center"><b>Weight</b></td> <td align="center">3</td> <td align="center">5</td> <td align="center">7</td> <td align="center">4</td>
October 21, 2019, at 02:12 AM by 136.36.211.159 -
Changed line 15 from:
<td><b>Value</b></td><td align="center">11</td><td align="center">8</td><td align="center">3</td><td align="center">6</td>
to: | {
"domain": "apmonitor.com",
"id": null,
"lm_label": "1. YES\n2. YES",
"lm_name": "Qwen/Qwen-72B",
"lm_q1_score": 0.9728307747659751,
"lm_q1q2_score": 0.8249291238839015,
"lm_q2_score": 0.8479677506936878,
"openwebmath_perplexity": 5331.895211944927,
"openwebmath_score": 0.4002639949321747,
"tags": null,
"url": "https://apmonitor.com/me575/index.php/Main/KnapsackOptimization?action=diff&source=n&minor=y"
} |
algorithms
$$...$$
Until
$\Gamma(d)$
$L\leftarrow a$
which leads to the components we didn't searched for:
$\Gamma(a) ∩ (X \backslash M)=bcd \ne0$
$ \ \ \ \ \ \ \ \ \ M\leftarrow {a,b,c,d,f,g,h,e}$ we add b to the visited list
$ \ \ \ \ \ \ \ \ \ L\leftarrow {a,c}$ Still, wher the hell does this e comes in the algorithm?
$\Gamma(c) ∩ (X \backslash M)=bcd \ne0$
$ \ \ \ \ \ \ \ \ \ M\leftarrow {a,b,c,d,f,g,h,e}$ we add b to the visited list
$ \ \ \ \ \ \ \ \ \ L\leftarrow {a}$ I'm okay with its disparition
$\Gamma(a) ∩ (X \backslash M)=bcd \ne0$
$ \ \ \ \ \ \ \ \ \ L\leftarrow {\emptyset}$ I'm okay with its disparition
III. My ideas to make it works
if ever it doesn't work!
I wonder if something is not lacking in the algorithm, if we shouldn't add an Explore within the 'if' loop.
EXPLORE (S:sommet, Γ, visited)
var LIST;
i,j:vertices
visited[S] ←true;
LIST ←{S};
WHILE LISTE ≠ 0
selectionner i ∈ LISTE
IF ∃ j ∈ D[i] , not visited[j]
visited[j]←true;
**EXPLORE(j,Γ,visited)**
ELSE LISTE←LISTE - {i} This might be a bit too much, but I tried the best I could to condense it. Unfortunately, Java doesn't allow one to write concise code... So, here's breadth-first and depth-first traversal of a graph (I used JGraphT) library for graph implementation. This should better illustrate the idea.
package tld.se.doodles; | {
"domain": "cs.stackexchange",
"id": 5277,
"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",
"url": null
} |
classical-mechanics, rigid-body-dynamics, stress-strain
Title: Why is the force on a cross section of a rigid body equal to the force over the entire body? If we have a block of mass $m$ (distributed uniformly) and a force $F$ acting on it, the block would begin to accelerate with an acceleration $a$. Obviously, the mass of half of the block is $\frac{m}{2}$. But wouldn't this imply, by newtons second law, that the force on half the block is $\frac{m}{2}a = \frac{F}{2}$ since the half block is accelerating at the same rate as the entire block?
If this is the case, then why is it that, in a rigid body, the force acting on a cross section of the block perpendicular to $F$ is $F$? I would instead expect it to be an infinitesimal force $dF$ since we are dealing with an infinitesimal mass (because the depth of the cross section is infinitesimal).
This question is coming from wikipedias explanation of stress here. In particular, this picture:
Notice how the force on the entire body is equal to the force on each of the cross sections "...wouldn't this imply, by newtons second law, that the force on half the block is ma/2 = f/2?"
Yes. The picture is different than your scenario. The mass in the picture has two equal and opposite forces acting on it, so it does not accelerate. Note that the picture has no gravity.
Also, the force on a cross section in your scenario drops off linearly (given uniform cross section) from F at the end the force is applied, to zero at the far end, as you seem to have thought. | {
"domain": "physics.stackexchange",
"id": 47158,
"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, rigid-body-dynamics, stress-strain",
"url": null
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.