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
1 vote
2 answers
62 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
  • 367
13 votes
1 answer
926 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
  • 345
1 vote
2 answers
157 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
40 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
69 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
0 votes
1 answer
41 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
45 views

Exploring how densities can be approximated by histograms in R

...
user21582991's user avatar
3 votes
1 answer
166 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
133 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
62 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
117 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
710 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
34 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
118 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
34 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
105 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
36 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
2k 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
62 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
  • 26.6k
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
212 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,870
0 votes
0 answers
50 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
29 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 ...
SiennaD.'s user avatar
  • 453
2 votes
2 answers
78 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,538
3 votes
1 answer
76 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
626 views

Recursively calculating powers by squaring

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

Geometric Brownian Motion Monte Carlo simulation in Rust

I am going through code that I wrote a while ago in Rust that simulates Geometric Brownian Motion. Geometric Brownian Motion satisfies the stochastic differential equation: $$dS_t = \mu S_t dt + \...
FISR's user avatar
  • 11
0 votes
1 answer
94 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
113 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
49 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
40 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
601 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
232 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
280 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
167 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
0 votes
1 answer
100 views

Optimizing a program that checks through a very large set of permutations

I'm not sure if this is the correct place for an optimization question like this, but I'm not even sure where to start looking. So here it goes. There's this game I play that has very simple rules. ...
Olivier Poulin's user avatar
2 votes
0 answers
106 views

JavaScript functions to generate Pythagorean triples

I am sure you know what Pythagorean triples are, in the extremely unlikely case that you don't know: A Pythagorean triple consists of three positive integers a, b, and c, such that $$a^2 + b^2 = c^2$$...
Ξένη Γήινος's user avatar
1 vote
0 answers
35 views

Iterating over de Bruijn sequences in JavaScript

I have just put this code together, it's not quite the most elegant but it seems to get the job done. Does it seem alright? I could not find anywhere a "de Bruijn sequence algorithm", so I ...
Lance's user avatar
  • 351
1 vote
1 answer
186 views

Unit tests for a 2D Vector class

I'm writing a vector class for 2D geometry applications, and below is a rough draft for a unit test using Cpputest. I'm familiar with unit tests, but this is the first I've done for a purely ...
Mode77's user avatar
  • 619
6 votes
2 answers
1k views

Entropy of String in C

I have written a C program that calculates Shannon entropy for a C-String (const char *). It works well but in many ...
Darth-CodeX's user avatar
1 vote
1 answer
54 views

C code for discovering numbers with interesting/beautiful/symmetric properties

Below is a C code that generates 1000 random positive integers, for each number we check primality, palindromic property, and the square root of the sum of the digits. The purpose is to find/discover ...
Redsbefall's user avatar
  • 1,132
1 vote
0 answers
88 views

Integrate a normal map via a 2D gradient field

This code transforms a normal map into a 2D gradient field and then iteratively integrates it to a likely solution. I don't have a lot of experience with C++/CUDA yet and would appreciate some advice ...
Niklas Hauber's user avatar
4 votes
4 answers
1k views

Count numbers that are the sum of three perfect cubes

From numbers from 1 to 100, count the numbers where the following equation is satisfied with 1 <= a <= 100, 1 <= b <= 100, and 1 <= c <= 100: $$a³ + b³ + c³$$ I have this: ...
Alan Bagel's user avatar
6 votes
4 answers
1k views

Converting lengths and weights using functions in C++

Question is: Write a program that asks the user if he or she wants to convert lengths or weights. If the user chooses lengths, then the program asks the user if he or she wants to convert from feet ...
Strange Alchemist's user avatar
1 vote
0 answers
61 views

Haskell proof checker for FOL with equality

Is this a correct implementation in Haskell of a proof checker for first order logic with equality? I am most interested in if it is correct, and if the functions can be made clearer. I would like it ...
user695931's user avatar
3 votes
1 answer
398 views

(Google Foobar XOR Checksum Challenge) How do i optimize this function to run for much larger values?

I wrote a function that accepts 2 integers start and length as input and returns the bitwise XOR of certain numbers as described below: ...
Ibrahim-san's user avatar
0 votes
1 answer
68 views

Generating floats from integers

I wanted to make an algorithm that is a counter-example of Cantor's diagonalization argument. Given an integer, this Python code will produce a unique rational number. Fed the sequence of positive and ...
Brent's user avatar
  • 451
5 votes
1 answer
65 views

Exploring the space of 8 parameters of a physics problem to then be evaluated in ODE integrator as LSODA millions of times, efficently

there's a function in one of the scripts I've been working on that I really want to improve. Disclaimer: Being honest, I'm not really very good at programming but I've been learning day to day and it'...
nuwe's user avatar
  • 163
2 votes
0 answers
173 views

Maximizing Efficiency of Collatz Conjecture Program Python

My question is very simple. I wrote this program for pure entertainment. It takes a numerical input and finds the length of every Collatz Sequence up to and including that number. I want to make it ...
Ghull's user avatar
  • 41

1
2 3 4 5
13