-
Notifications
You must be signed in to change notification settings - Fork 15
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
Base.zero
, Base.one
, Base.inv
missing
#168
Comments
MWE, continuing from the code above: x = @sym x
inv(im*x)
# outut
ERROR: MethodError: no method matching inv(::Mxpr{:Times})
Closest candidates are:
inv(::Complex{Float64}) at complex.jl:431
inv(::BigFloat) at mpfr.jl:471
inv(::Integer) at int.jl:56 |
It is also at least not sufficient to change my original attempt to Base.one(::Symbol) = @symExpr 1
Base.zero(::Symbol) = @symExpr 0
Base.inv(s::Symbol) = @symExpr 1 / s |
Thanks very much for the report. There are a few issues.
But this is "type piracy" because this defines You can define a method for
The definition for A well-thought-out plan for methods like This
could be made to work, but again only using type piracy. Some people think this should never be allowed and they have very good arguments. Supporting opt-in type piracy is also dangerous in general. If many people come to rely on piracy in one package and then Julia core devs decide later they want to use the methods for something else, it will start a contest. |
Thank you very much for the quick and detailed response. The following seems to go a long way: using Symata
import Base
symatamath()
Base.one(::Mxpr) = @symExpr 1
Base.zero(::Mxpr) = @symExpr 0
Base.inv(m::Mxpr) = mxpr(:Power, m, -1)
Base.sqrt(m::Mxpr) = mxpr(:Power, m, 1//2)
Base.complex(x::Mxpr, y::Mxpr) = x + im*y Perhaps it should be incorporated into Symata.jl? On the other hand, it's not quite production-ready yet because this requires replacing |
I'm trying to use Symata symbols in Julia code which relies on methods such as
Base.zero
,Base.one
, andBase.inv
. These are not implemented for the symbols one gets from the julia code@sym x
.I have tried to implement them as follows, but that does not seem to be correct (or at least not complete) since it leads to
MethodError: no method matching zero(::Symata.Mxpr{:Times})
which presumably means this code will have to handle objects of typeSymata.Mxpr
as well:What would a proper implementation look like and can one be added to this great package?
The text was updated successfully, but these errors were encountered: