Skip to main content

New answers tagged

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 ...
Jasper's user avatar
  • 101
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 ...
Jasper's user avatar
  • 101
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,...
Jasper's user avatar
  • 101
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 ...
MrXerios's user avatar
  • 507
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. ...
Jason Chia's user avatar
  • 1,175
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 ...
Tsyvarev's user avatar
  • 68k
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 ...
Marce Puente's user avatar
  • 1,198
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 ...
Jasper's user avatar
  • 101
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. ...
Tsyvarev's user avatar
  • 68k
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 ...
doubleunary's user avatar
  • 22.4k
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. ...
player0's user avatar
  • 132k
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 ...
przemek hertel's user avatar
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 ...
Xellos's user avatar
  • 1,111
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....
Stas Simonov's user avatar
  • 1,142
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 ...
Adam Hyland's user avatar
  • 1,077
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 )...
aka.nice's user avatar
  • 9,697
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....
Chris_F's user avatar
  • 5,879
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).
Dillon Davis's user avatar
  • 7,778
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!
little dutch boy's user avatar
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 ...
Stef's user avatar
  • 15.7k
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 ...
Stef's user avatar
  • 15.7k
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.
Gene's user avatar
  • 47.1k
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)...
Emile Cormier's user avatar
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" ...
ravenspoint's user avatar
  • 21.2k
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): ...
Ξένη Γήινος's user avatar
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 ...
Paul M.'s user avatar
  • 10.9k
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 ...
Good Night Nerd Pride's user avatar
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 ...
JonasH's user avatar
  • 39.4k
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 ...
Dean's user avatar
  • 1
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 ...
macomphy's user avatar
  • 371
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 :)
GiuseppeFn's user avatar
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 ...
MrXerios's user avatar
  • 507
Best practices
1 vote
0 replies
0 views

How does spectral centroid behave? (breaking-wave / bubble noise)

See also dsp.stackexchange.com.
Robert Dodier's user avatar
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 ...
Abion47's user avatar
  • 25.5k
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.
Martin Brown's user avatar
  • 3,895
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 ...
MrXerios's user avatar
  • 507
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.
MrXerios's user avatar
  • 507
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, ...
Stef's user avatar
  • 15.7k
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 ...
Stef's user avatar
  • 15.7k
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 ...
Stef's user avatar
  • 15.7k

Top 50 recent answers are included