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
Introduce factor_or_zero into global namespace #15364
Comments
comment:1
I guess your usage scenario is
Can't you do:
it's not that much longer (you can save some parentheses if you want) and that way sage doesn't have to choose an arbitrary sentinel value. Plus, the pattern can be used in other similar situations as well. At some point it's more beneficial to teach users how to use the building blocks available than to provide them with increasingly special-purpose bricks. |
comment:2
I think that is one of many scenarios. The purpose of Solution during Sage Days on Monday (which completely stopped everything for much longer than was necessary):
A more common scenario is
Or that a similar expression should come up as the coefficient of some element in an algebra and one should want to |
New commits:
|
Commit: |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:7
Please be aware that
0, of course, doesn't have that attribute:
|
comment:9
You are right. For consistency it should return a factorization object rather than an actual 0. New commits:
|
Changed branch from public/ticket/15364-factor_or_zero to public/ticket/15364/zabrocki/factor_or_zero |
comment:10
Replying to @zabrocki:
And now compare:
you should probably be consistent with that too. From the application you describe, I guess you're mostly interested in application to SR (the first case) in which case the most appropriate thing to do is probably to add a method |
comment:11
For Factorization objects: I think you really don't want those to get out into the wild when constructed with 0:
That's just wrong. I think that's even worse than getting an attribute error on |
comment:13
I (and my colleagues that are likely to use this code) will probably be working with algebras over polynomial rings/fraction fields or integer coefficients. SR is rather slow so I don't use it much. This is a convenience function. I can go through my list worksheets and could say that in about 1/3 of them I've had to work around factor throwing errors at me.
You are right. We might need to clean up the factorization code so that it handles the 0 object properly. |
comment:16
I noticed another problem with
This happens because If you trace it further, you see that
Now |
comment:19
I was the one pushing for a means of gussying up algebraic expressions through a |
The current top level factor command raises an error if factor is applied to 0. This is inconvenient for trying to factor polynomial expressions which reduce to 0 or lists of integers.
A function which does not force the user to handle 0 as a corner case is SUPER useful for users who just want to observe patterns in factorizations of lists or expressions that might reduce to 0. The error message of factor should indicate to the user to call
factor_or_zero
an error message such asArithmeticError: Prime factorization of 0 not defined. Use factor_or_zero to return 0 as the factorization of 0.
CC: @vbraun @tscrim @mguaypaq
Component: factorization
Author: Mike Zabrocki
Branch/Commit: public/ticket/15364/zabrocki/factor_or_zero @
1e0e3da
Issue created by migration from https://trac.sagemath.org/ticket/15364
The text was updated successfully, but these errors were encountered: