racket / math

Other
34 stars 28 forks source link

factorize should be more limited #32

Open sorawee opened 4 years ago

sorawee commented 4 years ago

It would be ideal if factorize is injective. It is not right now due to how (factorize 0) = (factorize 1) = '(). Changing the type of the domain to Positive-Integer is one possibility to accomplish this.

sorawee commented 4 years ago

Also, regardless of this, the type of the co-domain could be strengthen to (Listof (List Positive-Integer Positive-Integer)).

soegaard commented 2 years ago

Wait. Isn't (factorize 0) = '() simply an mistake?

The empty product is 1, so an empty list of factors represents 1.

pavpanchekha commented 2 years ago

I agree, (factorize 0) should raise an error or return ((0 1)) or something else but definitely not return '(). The easiest fix is definitely to change the domain to Positive-Integer.