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

Conversion to SR adds unnecessary coefficient "1*" and creates an expression without variables #34695

Open
maxale opened this issue Oct 26, 2022 · 5 comments

Comments

@maxale
Copy link
Contributor

maxale commented Oct 26, 2022

The following code

R1.<x> = QQ[]
R2.<y,z> = QQ[]
R3.<t> = QQ[[]]
R4.<u,v> = QQ[[]]
V = [x,y,z,t,u,v]
print([SR(q) for q in V])
print([SR(q).variables() for q in V])

prints

x y z 1*t u v
[(x,), (y,), (z,), (t,), (), ()]

That is, conversion SR(t) produces 1*t rather than just t, while conversions SR(u) and SR(v) produce expressions with no variables.

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/34695

@maxale maxale added this to the sage-9.8 milestone Oct 26, 2022
@maxale maxale changed the title Conversion to SR sometimes add unnecessary coefficient "1*" Conversion to SR sometimes adds unnecessary coefficient "1*" Oct 26, 2022
@maxale

This comment has been minimized.

@maxale

This comment has been minimized.

@maxale maxale changed the title Conversion to SR sometimes adds unnecessary coefficient "1*" Conversion to SR adds unnecessary coefficient "1*" and creates an expression without variables Oct 26, 2022
@nbruin
Copy link
Contributor

nbruin commented Oct 27, 2022

comment:4

I don't think these are bugs; maybe possibilities for enhancements. You can look at the types:

sage: type(SR(x))
<class 'sage.symbolic.expression.Expression'>
sage: type(SR(t))
<class 'sage.symbolic.expression.SymbolicSeries'>
sage: type(SR(u))
<class 'sage.symbolic.expression.Expression'>
sage: SR(u).pyobject() == u
True

As you can see, univariate series are converted to a different type, which apparently explicitly prints the coefficient, even if it's 1.

From the last line you can see that the multivariate series got wrapped as basically a "constant" in the symbolic ring. This indicates that no more advanced mechanism for converting to SR has been implemented.

For either case, u.polynomial() and t.polynomial() give you a polynomial object that can be converted to SR.

@maxale
Copy link
Contributor Author

maxale commented Oct 27, 2022

comment:5

At very least I'd expect that under conversion of an algebraic object (polynomial or series) into SR its variables are converted into variables of the resulting symbolic expression. This is not case for multivariate series conversion as the resulting symbolic expression has no variables.

I understand that there are workarounds such as intermediate conversion to a polynomial, but I'd really appreciate if this bug is fixed so no workaround would be needed.

@nbruin
Copy link
Contributor

nbruin commented Oct 28, 2022

comment:6

Replying to Max Alekseyev:

At very least I'd expect that under conversion of an algebraic object (polynomial or series) into SR its variables are converted into variables of the resulting symbolic expression. This is not case for multivariate series conversion as the resulting symbolic expression has no variables.

I haven't checked, but there may not be an appropriate multivariate series object in SR to map to. You could just truncate and map that, as "polynomial" does, but that's far from a perfect conversion either. It's definitely worth opening a ticket for implementing a more meaningful conversion there, since mapping them to symbolic atoms is almost surely useless, but I expect that ticket won't be trivial to resolve. Someone would have to study what a reasonable target construction in SR would be.

You could repurpose this ticket for that purpose and perhaps split out improving printing of SymbolicSeries to a separate ticket

@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants