Skip to content

Conversation

@devmotion
Copy link
Contributor

NaNMath 1.0.2 introduced a method ambiguity error.

@devmotion
Copy link
Contributor Author

Hmm seems not sufficient...

src/methods.jl Outdated
@number_methods(BasicSymbolic{<:LiteralReal}, term(f, a), term(f, a, b), onlybasics)

# Fix method ambiguity issue in NaNMath >= 1.0.2
NaNMath.pow(x::BasicSymbolic{<:Number}, y::Integer) = x^y
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
NaNMath.pow(x::BasicSymbolic{<:Number}, y::Integer) = x^y
NaNMath.pow(x::BasicSymbolic{<:Number}, y::Integer) = maketerm(typeof(x), NaNMath.pow, [x, y], metadata(x))

Copy link
Contributor Author

@devmotion devmotion Jan 10, 2025

Choose a reason for hiding this comment

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

We want to avoid NaNMath in that case in NaNMath < 1.0.2 and on NaNMath >= 1.0.2 an Integer as second argument falls back to ^ anyway. So I think using ^ is the better and safer approach, regardless of the NaNMath version.

Copy link
Member

Choose a reason for hiding this comment

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

Then can we add this to @number_methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did but I guess incorrectly. The original error is gone but it seems it causes https://github.com/JuliaSymbolics/SymbolicUtils.jl/actions/runs/12708708876/job/35426212172?pr=690#step:6:885.

@AayushSabharwal
Copy link
Member

In fact, this should instead be a change to @number_methods which adds a NaNMath.pow(::T, ::Integer)

@AayushSabharwal
Copy link
Member

Actually, never mind 😅 Symbolics is the only one with the ambiguity, right? Because Num <: Number. Adding a method here doesn't help. We instead need NaNMath.pow(x::Num, y::Integer) = wrap(NaNMath.pow(unwrap(x), y)) in Symbolics

@AayushSabharwal
Copy link
Member

@AayushSabharwal
Copy link
Member

I think a couple of the tests need to be updated

@ChrisRackauckas ChrisRackauckas merged commit bf23a1d into JuliaSymbolics:master Jan 13, 2025
6 of 10 checks passed
@devmotion devmotion deleted the patch-1 branch January 13, 2025 08:58
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.

3 participants