# 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).

696 questions
Filter by
Sorted by
Tagged with
26 views

### Create an algorithm to find powers using only addition and one factorial.

Why there is this kind of relation between power and factorial? I know that there is a way to use this pattern to generate powers using just addition and one factorial, but I can't wrap my puny brain ...
57 views

### How to find the time of a sine wave based on the y position?

I'm trying to find an equation that allows me to find the time of x of the sine wave based on the y position. For example: The y position of 0.25 on the sine wave should equal to 0.0804 in x time y0....
69 views

### Kuhn-Tucker conditions for inequality constraints

So, when we solve the optimization problem using Lagrange Multiplier method, I know that lambda can be positive or negative. Lambda is simply the rate of change in the optimal value when the ...
95 views

### How to calculate $N! \mod P$ fast?

Given numbers $N$ and $P$. Calculate $\:N! \mod P$. $N$ and $P$ are very large so that I can't calculate it by using Fermat's little theorem directly. But $|N - P|$ is small($\le 1000$) so I can solve ...
1 vote
17 views

### Are there any theorems that can be used to judge if an all-integer programming problem has a feasible solution?

Are there any theorems that can be used to judge if an all-integer programming problem has a feasible solution? I am NOT asking if we have any computational solvers that can be used to find a feasible ...
32 views

### Constructing complete lattices from total functions to posets

So I ran into this statement that says that the lowest upper bound of a set Y in L, a function space built like L = {f : S → L1 | f is a total function} is somehow related to the joins of the f(s)'s ...
82 views

### Calculating the exact square root of a complex number with rational components [duplicate]

Given a complex number with rational components, I want to check if its square root also has rational components, and if so calculate the value. For example, given $-\frac{119}{225}+\frac{8}{15}i$ I ...
27 views

### how to express solution only in terms of some variables in sympy.solve?

How to express this solution in terms of r, g, and phi? ...
18 views

### How to reverse differing of natural log in R? my attempts are not working

Simple inverse differencing is easy however, after differencing the natural log I cannot get the original data back. For instance, my data is in a timeseries: ...
1 vote
23 views

### Schedule recurrent tasks to match a desired frequency?

I'm trying to write a small task scheduling function that takes a list of tasks, each with an assigned priority. These tasks are meant to update some values in a database, and some need to run more ...
37 views

### Calculating $\sum_{k=1}^n \lfloor k * \sqrt 2\rfloor$ [duplicate]

This is a programming question I've come across recently and it requires me to find this sum as quickly as possible since n can become very large (up to 10100 ...
42 views

### Why are such two methods functionally equivalent from a mathematical perspective?

To program a function that tests whether all elements in an array are greater than 5, the straightforward way will be: ...
1 vote
64 views

### Numerical integration improves when step size is smaller, but in which direction?

I am implementing a double integration of a function; numerically in Matlab. What I basically do is: ...
23 views

### Modular square root function with Hensel's Stronger Lemma; algorithm for $\bmod 2^x$? Also $x^2 = a\pmod{p^n}$ when $\gcd(a,p) \neq$1

I'm programming a solution to HackerRank's Project Euler 100, which is a much stronger variant than the original question, so I have to essentially make a quadratic solver, which involves a lot of ...
23 views

### How to derive the formulas of the spin-weighted spheroidal eigenvalues (2.16a)-(2.16g) in arXiv:gr-qc/0511111?

I am reading the article "Eigenvalues and eigenfunctions of spin-weighted spheroidal harmonics in four and higher dimensions", which is on https://arxiv.org/abs/gr-qc/0511111. I want to ...
1 vote
27 views

### Effective algorithms for finite lattices of (higher-order) monotonous functions?

I am looking for references on effective algorithms on finite lattices or posets, and in particular on lattices of monotonous functions between two lattices, with higher-order structure -- monotonous ...
1 vote
57 views

### Is there an algorithm for finding every isolated singular point on an algebraic variety, or a programming language that implements this?

Suppose one wishes to test if a given algebraic surface f(x,y,z,w) = 0 in projective 3 space has singular points, that is df/dx = df/dy = df/dz = 0, and one also wishes to calculate these singular ...
1 vote
113 views

### Is it possible for integer division in C++ to express a compact mathematical condition, as for Euclidean division?

I am studying integer division in C++. At the same time, I read the wikipedia article 'Euclidean division'. In this article there is such a lemma: ...
46 views

### Calculate position of bouncing ball based on arbitrary time value

Usually, when you make a bouncing ball in any programming language, you have an X and Y value that updates over time, as well as an x velocity and y velocity, whose signs flip when the ball hits the ...
1 vote
26 views

### How to generate tangles?

In my research I need to generate tangle diagrams for with small number of crossings ($\leqslant 10$). By tangle I mean 2-tangle, that is an embedding of two arcs into a ball where endpoints of arcs ...
26 views

### How do I rotate an image onto any arbitrary plane

Given two references points $p_{1i}$ and $p_{2i}$ that lie on plane with normal $n_i = (0,1,0)$ and their corresponding points $p_{1f}$ and $p_{2f}$ on plane with normal $n_f$, how do I find the ...
1 vote
39 views

### How does this code implement the gauss-siedel method?

I have been trying to port and understand the code used in the paper Real-Time Fluid Dynamics for Games. One function in the paper, the method to diffuse one of the vector fields is said to use the ...
448 views

### Taxi distance count to all lattice points at specified distance from the lattice origin and of a specified dimensionality?

Setup of the problem Description of the lattice The problem is stated on a non-negative integer ($ℤ_{\ge 0}$) lattice. The specification of distance is also a non-negative integer ($ℤ_{\ge 0}$). ... 20 views

### Modelling particle diffusion in a scalar potential field

I'm currently trying to write a program that models 1D particle diffusion in a potential field. The model itself consists of a 1D array of equally spaced cells where each cell has a (time-varying) ...
1k views

### Does the set of all programs form a group that acts on machine state (essentially, i.e. with a few exceptions)?

Since the only thing a computer can do is modify its machine state, and you can always change from one state into another state (there exists such a program) and so each program is invertible; and if ...
39 views

### Why modular exponentiations of random, coprime numbers equals to 1/3?

Why is the average of modular exponentiations of random, coprime numbers equal to 1/3 on average? A similar question for N random (not coprime) numbers, but 'Why ... equal to 1/2 on average'? C++ code ...
49 views

### Uniqueness of negative and positive digit representation of integers

The question is regarding to the python code for following problem. We consider two type of digits, negative and positive to represent integers in given base. We are presenting theorem (self made), ...
1 vote
44 views

### Optimization problem that is convex and bounded is said to be unbounded in implementation

I have an optimization problem that is convex and bounded: \begin{align*} \text{Minimize}_{\text{wrt} B_{\text{opt}}}\qquad &\frac{1}{2p\sigma^2}\|Y_{\text{opt}}-X_{\text{opt}}B_{\text{opt}}\|_2^2-...
44 views

### Faster primality testing? [closed]

I have to make a list of primes, and I found out that all primes are of the form 6n+1 or 6n+5 (however not all numbers of this form are prime). Thus, I use it to find primes more quickly as such: <...
32 views

### How to render .obj files in a non-euclidean way?

Apologies in advance if this question is misguided or foolish; I'm learning. My goal is to write a non-euclidean renderer in the Rust programming language, and I'm wondering if anyone could tell me if ...
34 views

### Where do I get started with rendering curved space?

I want to program interactive renderings of spaces of arbitrary curvature (such as spherical or hyperbolic), though I have no idea how to begin. For instance, I have no idea whether I should use ...
69 views

### Coding theory graduate text and programming

I begin a PhD in coding theory next fall, and it concerns coding over certain types of rings (e.g. finite chain rings) instead of fields, and in consequence submodule codes. I have a fair amount of ...
41 views

### What is the best way to manipulate probability expressions in code?

Suppose I want to write code to derive formulas using basic algebra and rules of probability theory (general multiplication rule, inclusion-exclusion, law of total probability, conversion to odds/...
47 views

### Signed distance functions to arbitrary implicit surfaces

I am working on something called a raymarcher. It's a type of 3D engine, and a rather peculiar one; it uses a signed distance function to describe a scene, which is surprisingly enough info to ...
1 vote
56 views

### How to convert a point on a tilted 3D plane to a point on a 2D plane?

I have an infinite plane in 3D that I only know the normal vector of. I also have a point, somewhere on this plane. Based on the normal of the plane, its center point and the coordinates of the point, ...
1 vote
17 views

### Intersecting two graphs of modulo functions with fractional coefficients

I'm currently working on something for audio programming and in order to avoid a long post i will boil the problem down to a mathematical one. I have one function of the form: ...
67 views

### Ray-cone and ray-cylinder intersections

I am writing a simple raytracer, and I want to be able to raytrace capped vertical cone and cylinder primitives. I need to be able to find intersection points and normals for use in lighting and ...
23 views

### Can the resolution algorithm be applied to any FOL formula?

I have been searching for an automatic method (a computer program) to evaluate any first-order logic (FOL) formula given some knowledge base. The most common approach to do this is to use PROLOG. The ...
74 views

### my function is skipping

I wrote a function in C code that calculates a polynomial value from a given array arr[] of arrsize size, where the elements are ...
21 views

33 views

### Given a 3D camera and a horizontal plane both at the origin, how can I determine the pitch of the camera to view the plane N units below the horizon?

Given a 480px x 480px screen, and a 3D camera at the origin, with a horizontal plane on the X-Z axis that cuts through it (seen as a horizontal line through the center of the screen), how can I ...
1 vote
56 views

### Cubic polynomials over finite fields

I was watching an introduction video on "Tangent conics and tangent quadrics" by Prof. Norbert Wildberger , where the following Taylor polynomial was introduced: p_r(x) = (a+br+cr^2 + dr^3)...
67 views

### Is it fair to say that Martin Löf Type Theory is doing the same for maths as what type theory did for programming languages?

Let me clarify what I mean. I am currently writing a dissertation on ML/Homotopy type theory as someone who is more of a theoretical computer scientist than an Algebraist. My dissertation is focused ...
1 vote