New answers tagged math
Advice
0 votes
0 replies
0 views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
The reason I want to avoid references is because when I later try to navigate through geometric objects with various relations and constraints on them, my hope is that it will speed that process up. I ...
Advice
0 votes
0 replies
0 views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
Yes, in my question the terminology I used appears to make people think I'm talking about actual memory. You are right, I did mean that I do not want to assign it to both, if one is contained within ...
Advice
1 vote
0 replies
0 views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
I very much like this approach. This is in line with what I was originally envisioning. I was also inspired to make it so that if we had a LineSegment class, and two line segments overlapped on a line,...
Advice
1 vote
0 replies
0 views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
I think I see what you mean. You want to automatically infer when an object has to be on another, without having to declare it explicitly. In your example, since (R is on L) and (P is on R), then (P ...
Advice
1 vote
0 replies
0 views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
What do you mean store it separately in different places? Given your classes, its just a pointer to the point class? L.points[P.name] is just a pointer to the actual P class. no duplicated memory. ...
Advice
0 votes
0 replies
0 views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
Reference is the minimal way for represent connection between objects (in your case, a line and a point). Well, you may have an array of point objects, and make a line object to contain indexes of its ...
Advice
0 votes
0 replies
0 views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
I understand your point perfectly, and it makes sense. I can't say how much more memory having multiple * Point* with the same coordinates, and I don’t know what your program does, but in principle, I ...
Advice
0 votes
0 replies
0 views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
Please allow me to elaborate on my question. What I am really after is a way to not have to reference the point multiple times, as that many references seems unnecssary. I would like to make a point ...
Advice
0 votes
0 replies
0 views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
"I don't want to "store" it separately in multiple places" - Your current code already stores P in the single place. Both L.points[P.name] and R.points[P.name] refer to that place. ...
0 votes
I want to click a button in Google sheets that will increment cells that have a number by +1 each time it's pressed
click a button in Google sheets that will increment cells that have a number by 1 Buttons can be implemented as drawings in Google Sheets, but they aren't clickable in the mobile Sheets app. The ...
1 vote
I want to click a button in Google sheets that will increment cells that have a number by +1 each time it's pressed
the easiest incrementiation is done by enabling Iterative calculation. for that, go to: File > Settings > Calculation > Iterative calculation > On > Max. ...
0 votes
What to do with Java BigDecimal performance?
I participated in writing many systems intended for banks and insurance companies. In all of them, critical calculations were performed using double variables. However - and this is important - all ...
2 votes
Accepted
How can I programmatically derive Taylor series?
Yes, Taylor series are generally computationally expensive. If we're limited to a specific group of functions, we can sometimes find a nice enough representation that doesn't explode. If we're talking ...
1 vote
How can I programmatically derive Taylor series?
Performance of numpy.polynomial is fast enough. The code is as follows: from numpy import polynomial as poly def frac_poly_dif(poly_pair): num_poly, den_poly = poly_pair return (num_poly....
0 votes
Optimized low-accuracy approximation to `rootn(x, n)`
Mike Day (Generalising the Fast Reciprocal Square Root Algorithm (2023)) has a really neat attack on this problem. I recommend folks read it if they're interested as it is unusually clear for this ...
Advice
1 vote
0 replies
0 views
Math for incrementing a counter for a very large progress bar where total doesn't fit in an int
So the value should change past every multiple of T/100 where / is the exact division Let T=100*q + r The ith change of bar is when P >= i*q + (i*r)/100 You precompute 100 values i*q+ceil( i*r/100 )...
0 votes
Javascript: PI (π) Calculator
Here is an implementation that uses the Chudnovsky algorithm with binary splitting. On my computer it is able to calculate a million digits in ~870ms. function floorSqrt(n) { if (n <= Number....
Best practices
1 vote
0 replies
0 views
How do you calculate a row of Pascal's triangle, mod 10, in linear time?
In addition to the CRT, you should also look at [Lucas's Theorem](https://en.wikipedia.org/wiki/Lucas%27s_theorem).
Best practices
1 vote
0 replies
0 views
How do you calculate a row of Pascal's triangle, mod 10, in linear time?
I got this working after a while. Thanks!
Advice
0 votes
0 replies
0 views
How to compare 3d directions as equidistant on both diagonal and horizontal/vertical
Edit: Ok, now I get it. Vector(x, y, z) where x, y, z ∈ {-1, 0, 1} gives you 3^3 - 1 graph nodes (excluding Vector(0, 0, 0)) and you want them all to have edges to their neighbors. What a neighbor ...
Advice
0 votes
0 replies
0 views
How to compare 3d directions as equidistant on both diagonal and horizontal/vertical
"Up-UpRIght is 45 degrees, but Up-UpRightForward is ~54.7 degrees. Likewise going from UpRight-UpRightForward is ~35.3 degrees. I understand that this is normal maths but, for the purposes of ...
Best practices
1 vote
0 replies
0 views
How do you calculate a row of Pascal's triangle, mod 10, in linear time?
I think you can find the row mod 5 and mod 2, then use the Chinese Remainder Theorem to find the result you want.
0 votes
Representing 128-bit numbers in C++
Check out the cppalliance/int128 library that was released in 2025. Boost.Int128 is a portable implementation of a signed, and an unsigned 128-bit integer and related functionality (e.g. bit counting)...
0 votes
How can I make my tangent numbers generating class resumable?
Here is some C++ code to calculate A000182 using 'memoization' #include <string> #include <sstream> #include <iostream> #include <vector> #include "cRunWatch.h" ...
3 votes
Accepted
How can I make my tangent numbers generating class resumable?
I have solved the problem. I used the following code to analyze the process: DATA = [] def A000182_analysis(n): result = [1] * n last = 1 for i, k in enumerate(range(1, n), start=1): ...
3 votes
How can I make my tangent numbers generating class resumable?
I'm not familiar with that sequence, but the comments on that OEIS entry mention that this sequence can be derived from full binary trees, which indicated to me that the sequence can probably be ...
Advice
1 vote
0 replies
0 views
How to compare 3d directions as equidistant on both diagonal and horizontal/vertical
I think you cut down your example too much. I at least have no clue what you are actually trying to achieve and what your current solution does. It sounds like you want the diagonal of a unit square ...
Advice
0 votes
0 replies
0 views
How to compare 3d directions as equidistant on both diagonal and horizontal/vertical
I'm not sure I understand what you are actually trying to do here. Is the end goal to include directions while doing pathfinding? i.e. make turning more expensive than going straight ahead in an ...
Advice
2 votes
0 replies
0 views
How to compare 3d directions as equidistant on both diagonal and horizontal/vertical
It sounds like it would be easier to work with polar coordinates, or more specifically, spherical coordinates. r: The length of the vector, presumably 1 in your example. theta: The horizontal ...
0 votes
Sort points by angle from given axis?
Here is the fastest and precise way: (you can also cache b0k and bk0 firstly.) compare(v1, v2) b01 = (cross(v0, v1) >= 0) b12 = (cross(v1, v2) >= 0) b20 = (cross(v2, v0) >= 0) return ...
Best practices
0 votes
0 replies
0 views
how to calculate result of calculator in dart , button equal?
we would love to help you but the code you provided isn't really explainatory, and the question you gave us isn't much to work with :)
Best practices
0 votes
0 replies
0 views
How does spectral centroid behave? (breaking-wave / bubble noise)
The answer is dependant on what you are trying to observe/show through this chart. As long as you tell the viewer which frequency band you are using inyou computation, it's probably fine. Now, on to ...
Best practices
1 vote
0 replies
0 views
How does spectral centroid behave? (breaking-wave / bubble noise)
See also dsp.stackexchange.com.
Best practices
0 votes
0 replies
0 views
how to calculate result of calculator in dart , button equal?
It's hard to give suggestions without knowing what package you are using or what kind of calculator you are trying to make. For example, while a dynamic expression parsing package might be useful for ...
Best practices
0 votes
0 replies
0 views
How does spectral centroid behave? (breaking-wave / bubble noise)
This is probably better off on the sister site [stats.se]. It is about data modelling and interpretation - not a programming question.
Advice
0 votes
0 replies
0 views
Python algorithm to automatically propagate inequalities transitively
as stated by @Stef, I was wrong about the topological sorter, but I still think that the underlying graph structure is what you need. Here is an implementation that does what you want: from ...
Advice
0 votes
0 replies
0 views
Python algorithm to automatically propagate inequalities transitively
You are probably right now that I think about it. The topological sorter itself isn't exactly what is needed here, though the data structure might be pretty close to ideal.
Advice
0 votes
0 replies
0 views
Python algorithm to automatically propagate inequalities transitively
In addition to self.line_segments and self_inequalities, you could add two dicts self.smaller and self.greater that maps an item to the list of smaller items, and to the list of greater items. Then, ...
Advice
0 votes
0 replies
0 views
Python algorithm to automatically propagate inequalities transitively
Note that if ineq == (m, n): assert False, f"Inequality {m} < {n} already exists in the registry." can be replaced by assert ineq != (m, n), f"Inequality {m} < {n} already ...
Advice
0 votes
0 replies
0 views
Python algorithm to automatically propagate inequalities transitively
I don't think so? A topological sort gives you one order that respects all given inequalities, but "adds" new inequalities arbitrarily. The OP wants to propagate inequalities transitively ...
Top 50 recent answers are included
Related Tags
math × 46325python × 7209
algorithm × 6161
javascript × 5208
java × 4851
c++ × 3260
c# × 3107
geometry × 2346
c × 1901
php × 1720
arrays × 1264
matrix × 1160
3d × 1099
matlab × 1094
trigonometry × 1042
numpy × 1007
python-3.x × 927
random × 831
statistics × 828
vector × 822
function × 811
floating-point × 791
r × 724
android × 692
graphics × 645