Questions tagged [programming]
For mathematical questions related to programming, and questions where a computer-aided solution is strongly suggested. A strong connection with a mathematical topic is needed to make programming questions on-topic. This should not be the only tag. Consider also using the tags (algorithms), (numerical-methods), or (linear-programming).
741 questions
2
votes
2
answers
216
views
Necessary and sufficient condition for a binary operation to be associative and commutative?
I'm implementing a type conversion routine for a programming language. Under arithmetic context, there can be 4 types: null, ...
0
votes
0
answers
244
views
Efficient algorithm for solving Diophantine equation $x ^ 2+y ^ 3+z ^ 5=w ^ 7$ with $\gcd (x, y, z)=1$.
My Mathematica Codes:
...
0
votes
1
answer
31
views
Separating Axis Theorem for 2 arbitrary convex polygons. cannot work out how to make axis for projection, do projections from vertices for testing
i have watched numerous tutorials on implementing the SAT, but i think the math eludes me (as it usually does). Say, theoretically, that you are looping over each edge in a programming language, now ...
0
votes
0
answers
51
views
Best tool for solving MINLP
I would like to consider a rocket impulse plan from Earth to Mars for my Personal Project (IB-MYP) I am currently working on, and I am a student in high school in Hiroshima, Japan. Could you please ...
0
votes
0
answers
79
views
Rewriting a n-dimensional matrix of dot products as a matrix multiplication
I am currently working on a Fortran codebase for numerical simulation, I have managed to simplify some loops to the following code
...
2
votes
1
answer
112
views
A LCM/coprime-related question (Codeforces Round 1037 (Div. 3) - E)
The context of this question is a competitive programming contest that occurred in July 2025. Solving this would allow me to understand the solution posted here. Indeed, that would allow to prove &...
1
vote
0
answers
69
views
Algorithms for factoring high degree polynomials
I have been reading the literature "Factoring very-high-degree polynomials" by G.A. Sitton, C.S. Burrus, J.W. Fox, and S. Treitel". This algortihm seems to be efficient for very high ...
2
votes
2
answers
117
views
How do I find and classify a stationary point of the function $5x^3 - 3yx - 6y^3 - 2$ using Newton's method and the Hessian eigenvalues?
Setup to the problem:
We are going to determine the stationary points of the function
$5x^3 - 3yx - 6y^3 - 2$
in the region $-1 \leq x \leq 1, \ -1 \leq y \leq 1$.
Calculate the gradient $\nabla f(\...
0
votes
1
answer
104
views
Fitting general but "smooth" convex shape to points
I am aware that there are algorithms to fit, say, an ellipse to a bunch of given points on a plane. For instance, this SO question has answers which feature both literature on the algorithms and ...
1
vote
1
answer
89
views
Hidden Markov model (HMM) for multiple time series
I have a question regarding training HMM and then applying it to new data:
Is it possible to train a HMM with several time series as inputs? My point here is that it'd be convenient to have a ...
0
votes
2
answers
145
views
I have a system of $6$ matrix equations, where the matrices are $64 \times 64$. How can I approach this problem in a more efficient way?
I think this question is more of a mathematics question rather than a programming question, read below for further details.
Goal
I have a system of somwehat big ($64 \times 64$) matrix equations of ...
2
votes
1
answer
65
views
How to convert the square root of an integer n to an array index in an array consisting only of primes? [closed]
I have a function in javascript that is supposed to calculate the nth prime.
...
0
votes
2
answers
160
views
What am I doing wrong implementing minimal residue method?
The given scheme $AU = F,$ where $A$ is an operator, and $U, F$ are the square $(N+1)\times(N+1)$-sized matrices. The action of operator $A$ is given by:
$$
-a \frac{U_{i-1,j}-2U_{i,j}+U_{i+1,j}}{h^2} ...
5
votes
1
answer
113
views
Sequences that are rearrangements of $\{1,2,2,3,3,\dots, n,n\}$ such that each pair $(i,i)$ are exactly $i$ apart (where $i\ge 2$)
This question is inspired by leetcode. Obviously, this is a math website, so I will ask math questions.
Given an integer $n\ge 1$, consider the set of all sequences with elements in the range $[1, n]$...
3
votes
2
answers
294
views
Project Euler: A Claim in Problem $759$
I am interested in problem 759 in Project Euler.
For those who don’t know, here’s the problem statement:
The function $f$ is defined for all integers as follows:
$$\begin{align}
f(1) &= 1 \\
f(2n)...
1
vote
1
answer
109
views
What does it mean to take a calculational approach in programming?
I'm trying to read Anne Kaldewaij's book Programming: The Derivation of Algorithms and he begins the first chapter on "Predicate Calculus" with:
In programming, predicate logic is used as a ...
1
vote
0
answers
53
views
Functional programming and algebraic structures
I have been looking at algebraic structures (in particular groups) in functional programming. I have been fascinated by how monoids in particular have a wide applicability to the functional ...
0
votes
0
answers
66
views
2D transformation matrix how to revert or dismiss scaling?
I'm working on a web application which uses fabric.js to make drawings on the web page's canvas.
I will tell you about some general properties of this tool for context:
Canvas is a space that has its ...
0
votes
0
answers
54
views
Optimizing code to find optimal value of integer polynomial
I'm writing a Python program to calculate the maximum value of a polynomial $p * (1 + (d * (1 + (o * (1 + g))))$, subject to the constraints that $p$, $d$, $o$ and $g$ are all positive integers, and $...
0
votes
0
answers
87
views
How to prove the correctness of a sorting program using Hoare logic?
I am working on a problem where I need to analyze a small sorting program using Hoare logic to formally verify its correctness. Here's the program:
...
1
vote
1
answer
180
views
Converting a Transform (position, rotation, and scale) from TouchDesigner Coordinate System to Unreal Engine's
I am trying to convert a transform from the Touch Designer Coordinate System to the Unreal Engine Coordinate System (and others).
Ideally, I want to take a position, rotation (in Euler angles), and a ...
11
votes
1
answer
530
views
What is the longest possible Cats & Boxes game?
I have enjoyed playing a puzzle game called "Cats & Boxes" published by Smart Games.
Briefly, the way the game is played is:
Place $5$ cat pieces and $4$ box pieces (one of which has $2$...
0
votes
0
answers
45
views
A systematic way for constructing a set of die.
This is a problem from Knuth's The Art of Computer Programming, Volume 4B, Mathematical Preliminaries Redux. The problem is to find three six sided dice named $A$, $B$ and $C$ respectively, with sides ...
2
votes
1
answer
115
views
Finding numbers that satisfy a cyclical identity between base 10 and base 16
A while back, I noticed an interesting identity that exists between two particular numbers, involving a cyclical shift of one number when represented in base $16$, so that it's equal to the cycled ...
2
votes
1
answer
92
views
Good, fast-implementation algorithms for quotienting a finite-dimensional vector space over the reals with its subspace?
After doing a bit of digging, I can't find any native method in Julia's linear algebra package that let's me quotient a vector by a subspace. The Wikipedia article seemed to mainly focus on the theory ...
1
vote
0
answers
255
views
How to download a "sequence" of elliptic curves on LMFDB database [closed]
I apologize if this question is not appropriate for this platform. I am working on specific problems involving elliptic curves and am looking for numerical examples. The LMFDB database has been quite ...
1
vote
1
answer
70
views
Deriving equation for a Dynamic programming Puzzle [closed]
I solved the following puzzle https://leetcode.com/problems/unique-paths/description/ here at leetcode using programming. It is not very difficult to reason about how to computationally get the answer....
0
votes
0
answers
30
views
Image of a system of nonlinear inequalities under a linear map
Suppose we have a nonlinear feasible set $F$ in $\mathbb R^8$ given by
all $(x_{11},x_{12},x_{21},x_{22}, y_{11},y_{12},y_{21},y_{22})$
satisfying
$x_{ij},y_{ij}\geq 0$ and
$x_{ij}^2+y_{ij}^2\leq 1$, ...
-3
votes
1
answer
109
views
I was coding the other day when it occurred to me that it could be possible to program Bernoulli numbers. Is this possible, and how so? [closed]
I wanted to try and get the first 20 Bernoulli numbers using Python. Recently, I've been researching about Ada Lovelace, and Note G was an algorithm for the Analytical Engine to compute Bernoulli ...
1
vote
1
answer
97
views
Commutativity for monads modelling computation
$\newcommand{\llbracket}{[\hspace{-0.5mm}[}$
$\newcommand{\rrbracket}{]\hspace{-0.5mm}]}$
$\newcommand{\sem}[1]{\llbracket #1 \rrbracket}$
I came across the paper Notions of computation and monads by ...
0
votes
0
answers
75
views
Optimal Value t for Subdivision of Cubic Bézier Curve and How to Calculate It
In Gabriel Suchowolski’s paper, “Quadratic bezier offsetting with selective subdivision”, he explains how the midpoint—or better said, a parameter $t$ of 0.5—is often not the optimal* point on a ...
3
votes
1
answer
283
views
In SageMath, how to use GF() on a very large finite field ? Or declare an elliptic curve without GF()?
As far I understand it correctly, GF(Integer) is used to declare a finite field which can for example be used for declaring an elliptic curve (this is what I want ...
0
votes
0
answers
89
views
confused with the notion of probability
I understand probability as two processes;
We "do" something (or something is "happening"). lets call it the random experiment, and
We "expect" something from this ...
1
vote
0
answers
75
views
Given two points on the Poincaré disk model, what is the formula for a hyperbolic line passing through the two points?
I'm trying to code a Scratch project where you can place two (or more) points in a Poincaré disk to create hyperbolic lines. So far, the engine is going pretty well, but the actual line in between the ...
1
vote
1
answer
150
views
How to draw more precise of iterations in this type of constructions?
In this question I made this construction
Given a non-regular pentagon $A_1B_1C_1D_1E_1$ with no two adjacent angle having a sum of 360 degrees, from the pentagon $A_nB_nC_nD_nE_n$ construct the ...
3
votes
1
answer
115
views
Why can Haskell lists be infinite in length whereas inductively defined sets must contain finite sized elements?
Sets that are defined inductively can only contain elements that finite in size (e.g., length, height, space). This can be intuitively proven by realizing that any element in such a set can be ...
2
votes
0
answers
131
views
Fractal Subdivision for Procedural Generation
This is my first attempt at creating a thread here, thus I'm not sure how much context I need to provide you. Please leave a commend if you need additional info. With that disclaimer out of the way, ...
4
votes
5
answers
1k
views
Book Recommendations for Learning Python for Mathematics.
Lately, I've been finding that I often need to compute various things and graph some pretty complicated functions. I've realized that learning to program, especially in Python, could be really helpful ...
0
votes
0
answers
85
views
How to solve a paths optimization problem in node-labeled and weighted graphs
I am having trouble finding a way to optimize this problem in Python. Even if it is not exact, I am trying some heuristics.
Let $G = (V,\mathbf{L}, E,\mathbf{W})$ be a graph where $V$ is the set of ...
2
votes
1
answer
99
views
How to Find Closest Average for a set of variables from Multiple Sets of Numbers
I'm working on a problem where I have several sets of numbers and I need to find the closest average for a set of target values by combining numbers from these sets.
For example, let's say I want to ...
0
votes
1
answer
62
views
How can I make a vector of the products of the elements $(a_0b_0,a_0b_1,a_1b_0,a_1b_1)$ from the vectors $(a_0,a_1)$, $(b_0,b_1)$?
Given the vectors
$$\bar{a}=\left(\begin{array}\\a_0\\a_1\end{array}\right), \hspace{5pt} \bar{b}=\left(\begin{array}\\b_0\\b_1\end{array}\right) \in \mathbb{R}^2,$$
is there any way to get the ...
2
votes
2
answers
255
views
Is everything an object in Math, just like in Objected-Oriented Programming? (Tao's Analysis I)
I am reading Tao's Analysis I, and there are a number of passages which seem to suggest an object-oriented point of view of mathematics reminiscent of the object-oriented programming with which I, as ...
0
votes
0
answers
60
views
Circular Breakout Game: time or collisions needed to reach nth layer
Shower thoughts...
A tiny ball starts inside a unit circle, surrounded by fixed concentric circles of increasing integer radius length. So it starts in is the 0-th "level".
The ball moves in ...
1
vote
0
answers
58
views
Rotation invariant representation of strings
I came across the following simple programming question:
You need to create a boolean function that will return True if you get String A by shifting the alphabets in String B.
Example:
...
12
votes
6
answers
2k
views
Book recommendations for Combinatorics for Computer Science Students
I am a computer science student with an interest in competitive programming. I am currently looking to deepen my understanding of combinatorics, as it is a crucial part of algorithm design and ...
7
votes
4
answers
2k
views
Is it possible to find sum of x^x from a to b without using summation but rather a less computationally heavy method?
I don't know if I have an odd question, or if this has been asked before (research has not provided me with an answer or question about this). But I have a large amount of summation I need to do, ...
1
vote
1
answer
89
views
Find the center point of ellipse by only 2 points on it and radiuses
For a project, I am requested to find the center point of an ellipse (not necessarily centered), by just 2 points on it and radiuses.
B and E are points on an ellipse (Begin and End of an elliptic arc)...
1
vote
2
answers
52
views
How to find both of the degrees and length of the hypotenuse in a circle if were stretched?
I'm trying to calculate the degrees of an angle and the length of the hypotenuse if they were stretched/scaled horizontally or vertically.
Here's a picture to demonstrate.
a = width
b = height
c = ...
2
votes
0
answers
136
views
Representing a Groebner basis decomposition in sympy
In Sympy package there is Groebner() function, which allows to find a Groebner basis={$g_1, g_2,..., g_k$} for an ideal I, generated by polynomials $\{f_1, f_2,..., f_n\}$.
I wonder if there is ...
1
vote
0
answers
31
views
Help - How to separate 4th order transfer function (Butterworth Approximation) into 2nd order using Python Control Library?
Previously I had the following coefficients in the program. In this program I want to create a transfer function of butterworth approximation (Figital Filter Fesign - Digital Signal Processing).
...