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

584 questions
Filter by
Sorted by
Tagged with
43 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 ...
147 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 ...
68 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. ...
48 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$$...
1 vote
16 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 ...
1 vote
112 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 ...
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 ...
1 vote
48 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 ...
1 vote
48 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 ...
879 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: ...
858 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 ...
1 vote
54 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 ...
190 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: ...
61 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 ...
59 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'...
78 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 ...
72 views

### Find the mean magnitude of values inside unit circle

I'm fairly new to Python and am exploring how to fix functions and make code 'more effective and readable'. As a first step, I would want to try to make shorter snippets of code here - for example by ...
71 views

### Cholesky decomposition

This code is Cholesky decomposition in numerical linear algebra. ...
42 views

### Intersection of 2D vector equation straight lines

I know the vectors that describe two lines, $$\mathbf{a} + \lambda\mathbf{d}$$ and $$\mathbf{b} + \mu\mathbf{d'}$$ I've written a JavaScript function to get the coordinates of the point of ...
123 views

69 views

### Transform inertia tensor

I am trying to translate book: Game Physics Engine Development by Ian Millington to DirectXMath and faced with the code wich transform inertia tensor. Is it right to convert code from book like that: ...
260 views

### Mean difference calculator for any int combination

What it does Calculates the mean difference for a list of any combination of ints (I think). What I want to know The only other way I can think of doing this is using recursion. I’d like to know if ...
561 views

### Python code to find greatest common divisor of multiple numbers

Hmm, I know this has been implemented countless times, and Python 3.9.5 math standard library has a built-in gcd() method that ...
4k views

### A math engine with support for complex numbers, calculus, and fractions

I've been creating a math engine in C++. I have decided now is a good time to ask for feedback from the community. Right now the main "good" things it has is complex numbers, calculus and a ...
75 views

### Formula filler and calculator

So I made this script for my calculator, so that I can just write whatever formula I want and the calculator would just ask for the missing pieces to do the calculations. I made it so that it would be ...
47 views

### Runge Kutta 2 Python ODE fluid flow

I am trying to solve a set of differential equations in x,y,z, I have made simple kutta 2 code in python before but not with 3 variables. I am not sure if what i have done is an acceptable way to ...
131 views

### Implementation of the square root for real time application

For the real time control software I need square root calculation. I have heard that the sqrt function from the standard library isn't good choice due to the unpredictable number of iterations used ...
522 views

### C++ class to create and evaluate Chebyshev approximations of arbitrary functions

I recently needed to create a function to approximate a complex trigonometric function on an embedded system without a floating point unit and without a fast trigonometric library. So I pulled out my ...