Questions tagged [programming]

For mathematical questions related to programming, and questions where a computer-aided solution is strongly suggested. A strong connection with a mathematical topic is needed to make programming questions on-topic. This should not be the only tag. Consider also using the tags (algorithms), (numerical-methods), or (linear-programming).

673 questions
36
votes
3 answers

Under the Curry-Howard correspondence or loosely "proofs-as-programs", do we also have "programs-as-proofs" and what would some arb. program prove?

Curry-Howard Correspondence Now, pick any 5-30 line algorithm in some programming language of choice. What is the program proving? Or, do we not also have "programs-as-proofs"? Take the GCD algorithm written in pseudo-code: function gcd(a, b) …
30
votes
6 answers

Is (a/b)/c equal to a/(b*c) for integer division?

Let $\div$ denote a binary operator that returns the integer quotient of two integers, i.e. (assuming that both integers are positive) $a \div b = \left\lfloor \frac ab \right\rfloor$. This corresponds to the integer division operator in many…
19
votes
1 answer

How to compute the sine of huge numbers

For several days, I've been wondering how it would be possible to compute the sine of huge numbers like 100000! (radians). I obviously don't use double but cpp_rational from the boost multiprecision library. But I can't simply do 100000! mod 2pi and…
Oliver Borchert
  • 299
  • 2
  • 7
16
votes
7 answers

Is there any way to find the number of real roots of a polynomial computationally?

I'm creating a program to find the real roots of any given polynomial. It takes a user given polynomial as input and tries to find its roots. As an aid, mainly to check if I've missed any after the process, I'd like to know how many roots the…
12
votes
1 answer

What's special about the number $1.000000015047466$E+$30$?

I'm a programmer by trade by I've run into a weirdly special number and need some help deciphering its significance. I was writing some machine learning code that compiles into GPU kernel code and the compiler output the number 1.000000015047466E+30…
Shrey Gupta
  • 223
  • 1
  • 6
9
votes
11 answers

Can exact square roots not be found?

I'm brushing up on some higher level maths for a programming project. I was going along and then I realized that I have absolutely no idea how square roots can be computed. I mean sure, I've memorized a lot of perfect squares. But I wouldn't be able…
7
votes
2 answers

Number of $n \to p \bmod n$ before getting to 0

There isn't much background context, but is there any estimations on how many iterations of $n \to p\% n$ are needed before $n$ becomes 0? Percentage sign is modulo. ($p$ is fixed, prime in my context but not sure if it matters). For example, when…
Gareth Ma
  • 1,833
  • 5
  • 13
7
votes
4 answers

When the product of a multi-digit integer and its mirror is a palindrome, can the original number have digits greater than $2$?

I am reposting a question I posted on r/mathematics. It was suggested I ask it here. My son was jotting down some multiplications for school and asked me if there were many numbers that, when multiplied by their mirror image, resulted in a…
7
votes
2 answers

Sum of the first $n$ palindromes

We put together a problem to be solved programmatically, and we know at lower numbers there is a solution to this problem. How would we go about proving whether the below problem has an answer, as our standard computational approaches do not yield a…
6
votes
0 answers

How to draw a planar-embedded graph in a visually pleasing way

I have a graph with two types of vertices: "boundary" vertices have degree 1, and "interior" vertices have degree 4. I've computed a planar embedding of the graph, i.e. around each vertex, I have the list of outgoing edges in (say) clockwise order,…
6
votes
2 answers

Doubling Point Formula of Elliptic Curve is Not Working

Let $E$ be an elliptic curve and a point $P = (x, y) \in E,$ from the duplication formula, the x-coordinate of $2P$ is - $$x_{(2P)}=(x^4-b_4*x^2-2*b_6*x-b_8)/(4*x^3+b_2*x^2+2*b_4*x+b_6)$$ The formula is given on page $54$ in book The Arithmetic…
6
votes
1 answer

Random point in a triangle

This subject has already been covered here, and my question is slightly different. Preliminary warning: i'm quite a noob (and probably will continue to be unless i go back to school), but i do love some maths, the one i can't do with programming.…
6
votes
1 answer

Matt Parker mistake in cannonball stacking video

I could need someone to do a check on this problem, since it has been published in Matt Parkers book "things to make and do in the fourth dimension" and has now been featured in a numberphile video In Matt Parker's most recent video on numberphile…
Gravrok
  • 69
  • 3
6
votes
2 answers

Random tree generation probability problem

Given a tree-structure with a root node, the node can either get zero, one or two children, all with the same probability of 1/3. The children also has the same probability of getting zero, one or two children, which is 1/3. Recursively the…
5
votes
1 answer

If a type is an object and a function is a morphism. How to interpret a value in programming?

I've been reading Bartoz's "Category Theory for Programmers", and one question came to mind. In programming, types are objects and functions are morphisms. A functor is then a way to construct types from other types (e.g. $F(Int) = String$) together…
Davi Barreira
  • 2,872
  • 1
  • 9
  • 28
1
2 3
44 45