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

Support VT("name") where VT::Type{<:Variable} #137

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

timholy
Copy link
Contributor

@timholy timholy commented Jul 12, 2023

Rather than creating a variable with Variable(name, V, M),
sometimes it's easier to create one with Variable{V,M}(name).
This allows one to create a new variable from an old one with
typeof(oldvar)(newname).

Rather than creating a variable with `Variable{name, V, M)`,
sometimes it's easier to create one with `Variable{V,M}(name)`.
This allows one to create a new variable from an old one with
`typeof(oldvar)(newname)`.
Copy link
Member

@blegat blegat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, that's a convenient syntax.
I usually use the following: https://juliaalgebra.github.io/MultivariatePolynomials.jl/dev/types/#MultivariatePolynomials.similar_variable
when I want my code to work with TypedPolynomials as well for which this won't work but code only meant for DynamicPolynoials, I can see this being useful

@blegat blegat merged commit 6795fc4 into JuliaAlgebra:master Jul 12, 2023
4 checks passed
@timholy
Copy link
Contributor Author

timholy commented Jul 12, 2023

I just discovered similar_variable!

Since this is the first thing I thought of, perhaps for generic programming it could be added to TypedPolynomials too? In essence, have that constructor call similar_variable.

@timholy timholy deleted the teh/varcreate branch July 12, 2023 15:32
@blegat
Copy link
Member

blegat commented Jul 12, 2023

For TypedPolynomials, the type depends on the name so it would be weird to have Variable{:x}(Val{:y}) return Variable{:y}:

julia> typeof(x)
Variable{:x}

julia> typeof(similar_variable(x, Val{:y}))
Variable{:y}

@timholy
Copy link
Contributor Author

timholy commented Jul 12, 2023

Yeah, that would definitely be bad. I hadn't played enough with TypedPolynomials to realize what that would look like.

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

Successfully merging this pull request may close these issues.

2 participants