# Questions tagged [mathematics]

For code that aims to solve problems in all branches of mathematics. (Please do NOT use this tag for incidental trivial use of arithmetic. A simple test to apply is: would an amateur or professional mathematician take an interest in the question?)

629 questions
Filter by
Sorted by
Tagged with
85 views

### Toom-3 big-integer multiplication algorithm

I am developing a C++ big integer library for C++11, 14, 17, 20, etc., as an exercise. The Toom-3 algorithm is resisting me a little bit. AFAICT, it does produce the right results but not as fast as I ...
• 201
59 views

### Array Math to Calculate Ice Thickness -- Need Help Simplifying

I posted this on Stack but since it's working code, it was suggested I post it here. I wrote this code to calculate ice thickness using the following equation from Stephenson, 2011. It's a daily ...
90 views

### Efficiently generate a random position inside an outer rectangle but outside an inner rectangle

It should be a uniform distribution (ie: every point is equally as likely). I also don't want to use the simple solution of: "in a loop check to see if the current generated point is within the ...
• 213
71 views

### Can I make my percolation in python function more efficient?

We've been tasked with finding out how many randomly distributed discs with radius = 1 it takes to form a chain of discs from the left side to the other of a square with side length = sqrt(n), and ...
• 23
121 views

### Multithreaded sparse linear solver in Python

I would like to know if there are any multithreaded sparse linear solvers for LU decomposed sparse matrices. I want to increase the solving speed of a system like: ...
• 29
435 views

### Optimal Solution for the Four Divisors Problem on LeetCode

I recently encountered the Four Divisors problem on LeetCode and managed to achieve a 100% beat rate with my solution. I'd like to share it with you all and gather feedback on its effectiveness and ...
74 views

### Sine function guessing cognitive app

Please help with improving this application. It is a guessing game, for learning the values of the sine function, and boosting brain power in the process. ...
• 299
104 views

### Combinations of elements in array

I wrote this code to get all possible arrangements for an array containing 3 elements: ...
• 49
205 views

### Taking array of numbers, having a max weight, and distributing excess weight to ln max weight numbers

The goal is to take an array of numbers, have a max weight (saying 40%), and if any number above the max_num = sum * weight is present, remove the excess and ...
• 131
2k views

### A simple Vector library in C

I recently started working on my own vector library for a project and I thought it would be a good idea to get some insight on the code that I have written so far. It's very simple as I'm new to C. ...
• 79
85 views

### Rating math quality via unit-in-the-last-place (ULP) differences

Goal Please review code in fp.h and fp.c to index and compare floating point values. Background C code can perform floating ...
1 vote
258 views

I have implemented the Preconditioned Conjugate Gradient (PCG) method for solving a system of linear equations in Python and I would appreciate it if someone could verify its correctness since I am ...
• 29
254 views

### Python integer optimization with PuLP involving polynomials that I think can be faster

I have a problem where we are given multivariate polynomials in variables like y_i and z_j and the goal is to express them as sums of products of terms of the form y_i-z_j with nonnegative integer ...
• 225
89 views

### A Java program interfacing with Gnuplot for generating triangle wave plots

Intro I have this repository. Given this command ...
• 28.7k
1 vote
84 views

### Mapping composition in Java - v2

This post is the continuation of Mapping composition in Java. This time, I: Disallowed the null values as the range value. Simplified the ...
• 28.7k
2k views

### Plotting the Mandelbrot set efficiently

This is my Mandelbrot set program - it includes Smooth Coloring, perodicity checks, and my approach to biomorphs. I know of Edge Detection, but I couldn't find a simple explanation that I can ...
132 views

### Mapping composition in Java

(See also the continuation of this post.) This time, I have a mapping type: com.github.coderodde.mapping.Mapping.java: ...
• 28.7k
69 views

### Find perfect and amicable numbers

I've been playing with perfect, amicable and social numbers lately, and created a class for investigating these. At present, it has functions to return the perfect and amicable numbers in a specified ...
• 77.1k
348 views

### Python function to find the count of digits of numerals in base n up to a given limit

This is a simple exercise to find the count of digits of all numerals in a given base up to a given limit (not including the limit), I wrote it to determine the ratio of bytes saved when the numbers ...
• 3,158
259 views

### C# console app that computes the Jaccard Index

So I wrote a basic C# console application that computes the Jaccard Index. This has its applications in cybersecurity and machine learning. Given two sets X and Y, the basic formula is:  J(X, Y) = \...
• 173
1 vote
147 views

### Interleave Bits Generically

This commonly referenced "bit twiddling" site has an interesting algorithm for interleaving the bits of two 32-bit integers. Here is my attempt at completely generalizing the algorithm using ...
• 1,940
183 views

### Design an algorithm to predict words based on a skeleton from a given dictionary

The model I'm building first selects a secret word at random from a list. The model which uses an API then returns a row of underscores (space separated)—one for each letter in the secret word—and ...
• 232
133 views

### generate prime factors via wheel factorization

I want to factor random values of n that range from uint.MinValue to uint.MaxValue as ...
• 1,940
204 views

### 32-bit deterministic Miller-Rabin primality test

Are there any ways in which this code could be improved? I'm particularly interested in the ModularExponentiation function as it is the primary bottleneck during ...
• 1,940
2k views

### Newton Fractal writen in C

The code has no errors, it is just slow. It takes 1.19s to start. How can I reduce runtime without using threads or multiple processes? I have tried compiler optimization ...
285 views

### Identify distance degeneracies on square and hexagonal lattices

I have an interest in how the number of ways you can reach from the origin to a certain distance on both square and hexagonal lattices. If L is the square of the distance and integer pairs (i, j) are ...
• 473
130 views

### Improving execution time of physics, data acquisition triggering system simulation

Background I'm attempting to write a physics simulation code, one portion of which involves simulating the triggering system of some equipment. The equipment works as follows: environmental noise (...
80 views

### Python script that generates images using Thue-Morse sequence

In mathematics, the Thue–Morse sequence, or Prouhet–Thue–Morse sequence, is the binary sequence (an infinite sequence of 0s and 1s) obtained by starting with 0 and successively appending the Boolean ...
• 3,158
1 vote
234 views

### C++ Unsign 128 Bit Intrinsic Number

Per feed back for this question, I have written an unsigned 128 bit integer for Windows. The class first determines if it is in a 64 bit environment. It only creates the class if it is in a Windows ...
• 369
1k views

### Arcsine function for a real-time control program

I have been developing control software for a three-phase induction motor. The main task of this C++ code is to control the torque of the motor. In one part of the algorithm (The control algorithm is ...
• 355
1 vote
582 views

### Removing Elements from an Array Based on a Second Array

I've written a function that takes two arrays of integers as input and removes all the elements in the first array that are also present in the second array. I would like to share my code with you and ...
• 523
1 vote
52 views

### Optimizing the Dig Pow function

I have written a Python function to solve the Dig Pow problem, where the goal is to find a number k such that the sum of each digit of n raised to a specific and ...
• 523
1 vote
88 views

### Efficient N-Dimensional AABB Subdivision Algorithm

This is supposed to subdivide a n-dimensional aabb (axis aligned bounding box) into 2ⁿ equal pieces as if sliced by n planes that are perpendicular to only one axis and parallel to the rest of the ...
81 views

### Readable Backprogragation calculations in Numpy Neural Network

As an exercise we should write a small Neural Network with the following structure: There should be additionally a bias for each layer and sigmoid should be used as the activation function. The ...
• 51
57 views

...
533 views

### Fast approximate sin/cos function in Rust

Over the past month or so, I’ve been trying to create an extremely fast, platform agnostic, auto-vectorizing sin/cos function for fun. I initially started with sleef-rs’s fast sin function, and ...
159 views

### Using Ada's access type and generics to solve an ODE

This post is linked to Ada: Convert float to decimal I have produced Ada codes which uses the Euler algorithm Euler method to solve an ordinary differential equation. The codes given below are working ...
174 views

### Graph function in console

I created a program for drawing graphs of functions and want to hear ideas on "how to improve this program", because I'm only starting to write programs in Python. Would be very good to hear ...
• 81
145 views

### Ackermann-Péter function call count using Writer monad

I'm quite new to Monads and I tried add function call counting to the Ackermann function code. The goal was simplicity, not performance. I want to have code review on the ...
1k views

### Compute the sum of even numbers between two values

Recently I was watching two YouTube videos criticizing a function which sums the even elements in an inclusive range, the original function looks like this: ...
• 145
1 vote
65 views

### Fixing math library functions in Black-Scholes options pricing model

I've amended a code for the Black-Scholes formula for European pricing options found here at the bottom of the page and fixed the math functions accordingly. Unlike the code on the website, mine has ...
• 113
284 views

### Finite difference estimation of partial derivatives for arbitrary grids in python

I am currently working on testing some codes on python to solve differential equations by finite differences, but some problems and equations i am dealing with are: Too big to keep manually writing ...
• 123
41 views

### Python Module for representation, calculus and rich comparisons between temperature scale instances

ToTemp is a temperature conversion package with Celsius, Delisle, Fahrenheit, Kelvin, Rankine, Réaumur, Newton and Rømer scales. With a documentation and already in PyPI. The source code for the main ...
• 141
207 views

### Find factor pairs of an integer in Rust

I'm trying to efficiently generate all pairs of factors of a number n. For example, when n=27, the factor pairs are (1, 27), (3, 9), (9, 3), (27, 1) The order in which the pairs are found is not ...
• 93
89 views

### Speed up a JavaScript function for inverting matrices using Gauss elimination

I wrote this function and I'm interested if it can be sped up by improving the code. The function accepts either column major 1D array or 2D row major array. Maybe there are some obvious JS tricks ...
4k views

### Dividing two numbers then handle the divide by zero exception with try/catch

I am new to coding, I hope you can help me to improve my code :) First of all: The code works correctly. ...
• 53
2k views

### Euler's brick generator in C++

I stumbled upon this unsolved problem of math named Euler's brick. I wrote a program in C++ to generate solutions for Euler's brick problem. It searches from ...
336 views

### Generic Integer Square Root

I have implemented an integer square root function that is branch-free and runs in constant time, using the first variant found in this answer as a base. All possible values for the types ...
• 1,940
83 views

### Return a random integer with a probability progression

A function random_int_with_probability that returns a random number within a range, where the chance to get a bigger value decreases linearly towards the maxima. In ...
• 1,568