Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature proposal: Factorization as an abstract integer? #97

Open
cmichelenstrofer opened this issue Aug 24, 2021 · 3 comments
Open

Feature proposal: Factorization as an abstract integer? #97

cmichelenstrofer opened this issue Aug 24, 2021 · 3 comments

Comments

@cmichelenstrofer
Copy link

It would be cool if Factorization could be a representation of an abstract integer so that one could do arithmetics with them, etc.

f1e2 = factor(100)
f1e4 = f100 * f100
@reinermartin
Copy link
Contributor

Just a small comment, I find the following convenient sometimes:

using Primes
import Primes.Factorization

*(p1::Factorization, p2::Factorization) = Factorization(merge(+, p1, p2))

@show factor(12) * factor(21)

@rfourquet
Copy link
Member

Yes I also had this idea once in a while. I find both behaviors (dict and integer) useful; we could probably allow multiplication of Factorization objects, even when they are not <: Integer. If we made them <: Integer, there would be some questions to sort out, like for +, do we implicitly factorize the sum, or return a non-factorized integer?

@cmichelenstrofer
Copy link
Author

I see your point. If it is <: Int inevitably some operations would simply require promoting to Int and some thought is needed as to which operations should be defined specifically to return Factorization. Obviously the most useful is multiplication (including division, exponentiation, etc). If this approach is chosen I would argue it would make sense to define the basic arithmetic operations (including + even if its use is not immediately obvious). Anything else could be promoted to an integer. Support for other operations or functions can be added later if they make sense.

If the <: Int approach is not taken, I like your idea of allowing multiplication of the Factorization objects.

I'm completely new to Julia (coming from Python) but would be willing to give either of these a shot as a first issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants