asc-community / AngouriMath

New open-source cross-platform symbolic algebra library for C# and F#. Can be used for both production and research purposes.
https://am.angouri.org
MIT License
782 stars 74 forks source link

Solve a pythagorian triple #475

Open Happypig375 opened 3 years ago

Happypig375 commented 3 years ago

The package I want to suggest the idea to: AngouriMath Solve a^2 + b^2 = c provided a in ZZ and b in ZZ and c in { 16, 25, 36, 49 } and 0 < a < c and 0 < b < c: a = 3, b = 4, c = 25

https://www.youtube.com/watch?v=jLSDWgIWXh8

upam00 commented 3 years ago

This problem of representing an integer as sum of two perfect square dates back to Diophantus of Alexandria. Later in 17t century Fermat noted it in his notebook but without a proof. A complete proof was first produced by Euler. Many more proofs followed after that.

From an algorithmic perspective we have many methods of doing it in exponential time when c is composite. In case c is prime there is a method by Stan Wagon to calculate it in polynomial time. (https://www.jstor.org/stable/2323912). We can combine this with an approach as shown here http://nonagon.org/ExLibris/fermat-sum-two-squares-calculator to build a desired solution.

I would love to contribute if you can give me some more detailed specification.

WhiteBlackGoose commented 3 years ago

@upam00 we currently do not support solving over multiple variables (we only have Solve over one variable), so I'm not sure yet how we're going to address alike issues.

On the other hand, it doesn't mean you can't contribute. You are very much welcome to add a algorithm of solving this problem outside of the Entity class, but as a separate function. Let me show where and how.

Here you can see a subclass which accumulates our number theory functions. This is the public API where you will add your function.

This folder is where you add a internal static class with your algorithm.

The class to work with is Entity.Number.Integer, but you can address it with Integer thanks to C# 10's global usings.

Feel free to ask more questions! You can also join our Discord chat and/or ask your questiosn after opening a draft PR.

Thanks.

upam00 commented 3 years ago

Thanks for the info. I guess we don't need an equation solver. Will built the solution using prime factorization. Which is available I guess. I am joining the discord server and discuss details there. Cheers.