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?)

Filter by
Sorted by
Tagged with
0 votes
0 answers
50 views

A Java program interfacing with Gnuplot for generating triangle wave plots

Intro I have this repository. Given this command ...
coderodde's user avatar
  • 27k
1 vote
1 answer
78 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 ...
coderodde's user avatar
  • 27k
8 votes
4 answers
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 ...
iogamesplayer's user avatar
2 votes
2 answers
119 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: ...
coderodde's user avatar
  • 27k
2 votes
1 answer
43 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 ...
Toby Speight's user avatar
  • 70.8k
3 votes
1 answer
306 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 ...
Ξένη Γήινος's user avatar
5 votes
2 answers
141 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) = \...
Aleksey's user avatar
  • 153
1 vote
0 answers
108 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 ...
Kittoes0124's user avatar
  • 1,940
-2 votes
1 answer
86 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 ...
driver's user avatar
  • 212
2 votes
1 answer
101 views

generate prime factors via wheel factorization

I want to factor random values of n that range from uint.MinValue to uint.MaxValue as ...
Kittoes0124's user avatar
  • 1,940
4 votes
2 answers
166 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 ...
Kittoes0124's user avatar
  • 1,940
8 votes
3 answers
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 ...
mehdi mirzaie's user avatar
5 votes
1 answer
272 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 ...
uhoh's user avatar
  • 451
3 votes
1 answer
126 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 (...
MomentumEigenstate's user avatar
2 votes
0 answers
57 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 ...
Ξένη Γήινος's user avatar
1 vote
2 answers
106 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 ...
StormCrow's user avatar
  • 369
14 votes
2 answers
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 ...
Steve's user avatar
  • 355
1 vote
2 answers
163 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 ...
TAHER El Mehdi's user avatar
0 votes
1 answer
43 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 ...
TAHER El Mehdi's user avatar
1 vote
2 answers
78 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 ...
Jaysmito Mukherjee's user avatar
1 vote
1 answer
58 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 ...
Leon0402's user avatar
5 votes
0 answers
51 views

Exploring how densities can be approximated by histograms in R

...
user21582991's user avatar
3 votes
1 answer
270 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 ...
burgerdude's user avatar
2 votes
1 answer
140 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 ...
Adaenthusiast's user avatar
-1 votes
1 answer
87 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 ...
Максим's user avatar
5 votes
1 answer
133 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 ...
Arpad Horvath's user avatar
3 votes
3 answers
782 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: ...
Asleepace's user avatar
  • 133
1 vote
1 answer
44 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 ...
Jessie's user avatar
  • 113
2 votes
1 answer
191 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 ...
Klaus3's user avatar
  • 123
2 votes
1 answer
38 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 ...
eddyxide's user avatar
  • 141
3 votes
1 answer
127 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 ...
Bram's user avatar
  • 93
3 votes
0 answers
50 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 ...
user9163823's user avatar
5 votes
4 answers
3k 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. ...
jasmine's user avatar
  • 53
0 votes
0 answers
63 views

Bruteforce proof of an arithmetic expansion scheme expression in array lists (Java)

Given a list of, say, integers, one way to implement such a list is to rely on an array under the hood. When we are adding elements to the array list, we might need to make the internal array larger. ...
coderodde's user avatar
  • 27k
9 votes
3 answers
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 ...
RandomCoder59's user avatar
3 votes
1 answer
237 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 ...
Kittoes0124's user avatar
  • 1,940
0 votes
0 answers
67 views

Traversing a 2D array with a tree

In order to help me solve the December Jane Street puzzle "Die Agony" I wrote a quick and dirty script to manually brute-force through the thing and do the calculations for me. I then tried ...
Cirrocumulus's user avatar
0 votes
0 answers
30 views

Component-wise double precision multiplication in Go

I'm working on porting the bullet3 physics engine to Go to learn more about physics simulations. I'm working through some of the convex hull computing code, and I've reached a component-wise, double ...
Sienna's user avatar
  • 453
2 votes
2 answers
80 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 ...
Edenia's user avatar
  • 1,548
3 votes
1 answer
84 views

Finding Highly Composite Numbers in Swift

This code finds highly composite numbers (numbers with more factors than any smaller number) in Swift. I'm not too familiar with Swift, I did this in python but it was too slow so I decided to try it....
Octobass's user avatar
5 votes
2 answers
639 views

Recursively calculating powers by squaring

Consider the following function that implements optimised O(log n) exponentiation by squaring: ...
saxbophone's user avatar
0 votes
1 answer
113 views

Newton-raphson to find the square root of an arbitrarily sized number with arbitrary precision

I read here that "Furthermore, for a zero of multiplicity 1, the convergence is at least quadratic (see rate of convergence) in a neighbourhood of the zero, which intuitively means that the ...
avighnac's user avatar
  • 309
3 votes
1 answer
132 views

Willans' formula in Rust

I implemented Willans' formula to calculate the nth prime number in Rust: ...
Richard Neumann's user avatar
0 votes
0 answers
61 views

Euler's totient function in Rust, with a performance difference between generic and classic functions

I recently started to program in Rust, having like 2 good years of experience in C++, I thought it would be possible to directly switch to Rust without following a lot of tutorials, especially knowing ...
Teyzer18's user avatar
  • 101
3 votes
0 answers
41 views

Plot of massless particles on the unstable null circular geodesic

My friend and I were trying to reproduce Figure 4(left), page 7, from the paper "Probing phase structure of black holes with Lyapunov exponents", Guo 2022. We succeeded in reproducing the ...
codebpr's user avatar
  • 131
6 votes
4 answers
2k views

Find all ways to express each of a list of even numbers as the sum of 2 positive, even numbers

This code was a challenge from a friend. Essentially she wanted a way to "Divide an even number into 2 even numbers." So I made this quick and dirty Python program to find the solutions up ...
Omar Morales Rivera's user avatar
2 votes
2 answers
871 views

Solving the TDoA multilateration problem in 3-dimensions

Background. I've written an algorithm to solve the Time Difference of Arrival (TDoA) multilateration problem in 3-dimensions. That is, given the known coordinates of ...
10GeV's user avatar
  • 285
1 vote
2 answers
380 views

Calculates the multiplicative persistence of a given number // Returns the smallest number with a given level of MP (Numberphile Challenge)

I was watching this Numberphile video: https://youtu.be/Wim9WJeDTHQ on multiplicative persistence (multiplying digits of a number over and over until one digit remains). I decided to take up the ...
el.brollo.loco's user avatar
3 votes
1 answer
319 views

Find perfect squares within a given range

I managed to make this work without breaking the program if you enter some weird numbers in the range. The thing is I know this could have been done simpler and smarter. I can't really see how right ...
el.brollo.loco's user avatar
3 votes
1 answer
173 views

Applying a cost function to a string based on a pattern string

I have a cost function Cost_Func(pt,STRING) that calculates value in a specific way based on the given pattern string pt and ...
Michael's user avatar
  • 133

1
2 3 4 5
13