Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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
2
votes
1answer
55 views

Quadratic “Complete the Square” Solver in Python 3

I quickly wrote this program to transform quadratic expressions in general form into vertex form. \$ax^2 + bx + c \;=\; a(x-h)^2 + k,\quad\text{where}\quad h = -\frac{b}{2a} \quad\text{and}\quad k = ...
-2
votes
0answers
13 views

Jacobi and Gauss-Seidel Iterative Method for Solving Linear System [on hold]

I have been working on creating a program that solves linear systems of equations for the Jacobi and Gauss-Seidel iterative methods. (Link to the methods: https://www.cis.upenn.edu/~cis515/cis515-12-...
3
votes
0answers
67 views

Making a fast Mandelbrot Fractal viewer

I'm making a Mandelbrot set viewer in JavaFX. It takes a while, like maybe 5 seconds to finish. Here's my code: ...
7
votes
4answers
15k views

Algorithm to get an arbitrary perpendicular vector

Is there a more efficient/direct way to find an arbitrary perpendicular vector of another vector? ...
3
votes
2answers
85 views

Finding root of strictly monotonic function by bisection

I need to find a root of strictly monotonic function f (only raising or only lowering). There is only a one root of a function. If given range from a to ...
4
votes
1answer
334 views

Computational verification of Collatz conjecture using OpenCL

This code review request follows my previous request Computational verification of Collatz conjecture. Unlike the previous program (which was designed for the CPU), this code should run on modern GPUs....
-1
votes
2answers
68 views

Find minimum value of a quadratic function [closed]

This is program that computes the minimum of the function \$y=(ax+b)^2\$. The program will find the value of \$x\$ that gives the minimum \$y\$. It will start with an initial value \$x\$ that you ...
1
vote
2answers
102 views

Get the best rational approximations for any real number in builtin Python

Best rational approximations is a technical term and not subjective. The best rational approximations are the convergents of a value plus it's semi convergents that are closer to the original value ...
1
vote
0answers
46 views

Daubechies wavelet and scaling filters: Is there a better way?

I have computed the Daubechies wavelet and scaling filters in float, double, long double, ...
4
votes
1answer
76 views

Magic Square with Five Methods (Python)

Problem Write a program to return a boolean if an input grid is magic square. A magic square of order \$N\$ is an arrangement of \$N^2\$ distinct integers in a square such that the \$N\$ numbers in ...
5
votes
2answers
232 views

Magic Square (Python)

Problem Write a method to return a boolean if an input grid is magic square. A magic square is a \$NxN\$ square grid (where N is the number of cells on each side) filled with distinct positive ...
5
votes
3answers
367 views

identify groups of congruent points

I have two sets of points in lists list1 and list2 given below ...
3
votes
2answers
116 views

Project price of publicly traded contract

I have to project the price for a publicly traded contract when the price should be approximately matching the targeted profit or loss. I have written the following code, runs under 0.02ms.. could be ...
1
vote
0answers
65 views

Recursion to dynamic programming [closed]

I was trying to solve a problem on de-arrangements (Number of partial derangement such that exactly prime number discs are found away from their natural positions? (Any number of non-prime K disks ...
1
vote
0answers
55 views

Solidity: verifying primality certificates, bounty for large primes

This is my first smart contract, and it isn't finished yet, but the remaining bits are complicated enough that I'd like to make sure I'm on the right track first. My concerns are: At line 117, is the ...
4
votes
1answer
59 views

Meta-circular interpreter for lambda calculus in Python

For learning purpose, I've written a simple lambda calculus interpreter (plus 'Add'). I would like it to be the cleanest and most idiomatic possible. Can we make it as neat as the Haskell version? <...
2
votes
1answer
111 views

Meta-circular interpreter for lambda calculus in Haskell

For learning purpose, I've written a simple lambda calculus interpreter (plus 'Add'). I would like it to be the cleanest and most idiomatic possible. Bonus question: how would you use ...
2
votes
1answer
59 views

Arbitrary precision Euler-Mascheroni constant via a Brent-McMillan algorithm with no math module

Utilizing the below relation, I am able to compute the Euler constant to great precision on a single thread quickly and simply. My process is to compute the natural log via the AGM(utilizing Pi an ...
1
vote
1answer
41 views

Euler-Mascheroni Single Thread Speed Improvements

The below code was written to generate γ, for educational purposes. My general methodology is as follows: Compute Gamma via the accepted answer's algorithm here. In order to do this I need to ...
4
votes
1answer
77 views

Calculate the Euler-Mascheroni constant without the math module

The below code was written to generate γ, for educational purposes. Single threaded, no functional zeroes required, no binary splitting(which can all be used to compute competitively like y-cruncher, ...
32
votes
7answers
8k views

Checking if a number is divisible by 9

I tried to develop a new way to check if a number is divisible by 9. I have written my code and it is working fine. I'm not allowed to use *,...
3
votes
2answers
80 views

Computational verification of Collatz conjecture using gmplib

Prerequisites The unsigned long type has a size of 64 bits. The following macros are defined. ...
3
votes
1answer
286 views

Computational verification of Collatz conjecture

Prerequisites The typedef name uint128_t designates an unsigned integer type with width exactly 128 bits. The ...
11
votes
7answers
7k views

Check if a given number N is a power of k

I am trying to solve a problem to check whether a given number N is a power of k. Example: Input 9, 3 > True // 3**2 = 9 Input 10, 2 > False Input 4096, 16 > True // 16**3 = 4096 I want to know ...
4
votes
1answer
261 views

Compute the square root of a positive integer using binary search

The requirement is to find the square root of a positive integer using binary search and the math property that square root of a number n is between ...
0
votes
1answer
156 views

Find the product of digits at odd/even places

The 'score' of a race is given. We have to calculate the 'bonus points' to be given to the participant. The '...
11
votes
2answers
29k views

Calculating Exponential Moving Average in Python

I'm in the process of creating a forex trading algorithm and wanted to try my shot at calculating EMA (Exponential Moving Averages). My results appear to be correct (compared to the calculations I did ...
4
votes
1answer
101 views

Faster algorithm to tailor given mathematical expression

Is there a more optimized solution to solve the stated problem? Given an array 'arr' of 'N' elements and a number 'M', find the least index 'z' at which the equation gets satisfied. [ ] is ...
3
votes
1answer
33 views

GLSL Shader that displays a Rotating Rainbow Ring

I'm learning GLSL shaders on Book of Shaders and I decided to mess around with one of the examples. I wanted to see, whats a more efficient way to calculate to mask out the color? ...
8
votes
2answers
695 views

Balanced centrifuge configurations

Given an input N as the size of a centrifuge, I need to find out the number of balanced configurations. The full description is here. Centrifuge is a piece of ...
8
votes
2answers
459 views

Make Project Euler 27 solution idiomatic Ruby

I learned to program in Java and C# and in my free time I am using Ruby because it is fun. Unfortunately I have the feeling that I write Ruby code like I am making Java or C# code. I have learned to ...
2
votes
2answers
86 views

VBA root finder algorithm

I did two simple functions in VBA (see below). When a user calls TirNoPer360 in Excel he must select cashflows and dates (as range), then he will get a rate (...
7
votes
3answers
138 views

Check if an integer equals the sum of its digits to the fifth power

I can do this in one line in Python: sum([i for i in range(9,9999999) if i == sum([int(x)**5 for x in str(i)])]) Not very fast, but works nicely. I thought it ...
5
votes
1answer
100 views

Baby Step Giant Step Discrete Log Solver

I've made a concurrent implementation of the Big Step Giant Step discrete log solver in Go. I'm pretty new to this branch of math, but it seems slow. Any way to speed it up or is this the limit of ...
11
votes
2answers
3k views

Softmax function implementation

I'm implementing some mathematical functions right now for future use in more exciting things and wanted to know if I'm on the right track in my approach, as I don't have much C++ experience. Here I'...
11
votes
1answer
60 views

Visualization of the Pythagorean theorem

Background The Pythagorean theorem asserts that for a right triangle with hypotenuse \$c\$ and other sides \$a\$ and \$b\$, the area of the square placed upon \$c\$ is equal to the sum of the areas ...
3
votes
1answer
50 views

Stern's diatomic series fusc: replacing #define functions with two return values

I have a function to review which implements Stern's diatomic series fusc for a single word (ulong = unsigned long) in place, as ...
4
votes
2answers
4k views

4x4 matrix implementation in C++

I've been doing some 3D graphics in OpenGL lately and I needed a way to work with 4x4 matrices. My implementation supports the following operations: Matrix-matrix addition. Matrix-matrix subtraction. ...
137
votes
17answers
17k views

Disproving Euler proposition by brute force in C

I wrote a little bit of code to brute force disprove the Euler proposition that states: $$a^4 + b^4 + c^4 = d^4$$ has no solution when \$a\$, \$b\$, \$c\$, \$d\$ are positive integers. I'm no ...
3
votes
2answers
91 views

Gram-Schmidt process in Java for computing independent bases in linear spaces

Given a set of \$k\$ \$n\$-vectors \$\vec{x_1}, \dots, \vec{x_k}\$, Gram-Schmidt process computes a basis \$\vec{y_1}, \dots, \vec{y_m}\$ (\$m \leq k\$) the vectors of which span the same space as \$\...
5
votes
1answer
8k views

Better implementation of Gaussian Elimination

I made an algorithm in C# that solves any system of linear equations using the Gaussian elimination. There are 2 text boxes in the program for input and output. Input is in the format of the ...
0
votes
1answer
42 views

Modular multiplicative inverse in Ruby

I implemented an algorithm to find the modular multiplicative inverse of an integer. The code works, but it is too slow and I don't know why. I compared it with an algorithm I found in Rosetta Code, ...
4
votes
3answers
743 views

Find smallest number of squares that sum to a number

Leetcode problem 279 “Perfect Squares” is: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) I wrote the following solution: ...
1
vote
1answer
81 views

Sum of number's quotients when divided by exact powers of 2

Problem I have written code to solve this challenge: Given a formula: GCD(x,y) means the GCD (Greatest Common Divisor) of x and y. For example: if N=2, then: f(2) = 1/GCD(1,...
8
votes
1answer
279 views

Computing a Discrete Cosine Transform matrix

I'm learning Haskell and I needed to work with discrete cosine transform matrices, so I made a program that generates text (usable in WolframAlpha) containing the generated matrix. The elements of ...
2
votes
2answers
110 views

PHP find cheapest permutation

I have multiple products that all have sizes and I need to find the cheapest configuration that meets the minimum required size. For example, John needs a minimum of 10 litres of storage - it can be ...
3
votes
2answers
238 views

Reverse int within the 32-bit signed integer range: \$[−2^{31}, 2^{31} − 1]\$ Optimized

LeetCode Problem Reverse digits of a 32-bit signed integer. When the reversed integer overflows return 0. Feedback Optimized from beta code in the original question here. Based on this LeetCode ...
2
votes
0answers
92 views

Shutting down all lamps with minimum number of switch presses

I found an optimization problem written in Finnish but I will translate it into English. The following is an example case. I have \$n=120\$ lamps in a circle, and enumerated by \$L_1,…,L_{120}\$. ...
3
votes
0answers
62 views

Optimising multiplication of matrix rows with matrix slice/page

I've recently vectorized most of the code for an optimization problem but this one still eludes me. As the procedure and not the actual values are important here, I have replaced the original matrices ...
15
votes
3answers
18k views

RSA algorithm implementation in Python 3

First, a reminder of the RSA algorithm and what my program implements: Take two distinct, large primes p and q Ideally these ...