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
Including overloading of basic algebra #48
Comments
I was originally trying to keep this as a backend package, closely mirroring WSTP/MathLink itself, and build another package as the frontend, but never got around to that. This would also result in eager evaluation, which would give different semantics from the underlying Wolfram language. |
I see. I'm not an expert of the inner workings of mathematica, but I guess the , the For new users of the package however, having the most basic operations +, -, *, / overloaded would still be quite useful and pedagogic. |
After playing around with your package now for a while i have collected quite a bunch of auxiliary functions that make sense to me. The files contain overloading of functions +,-,*,/,^ as well as a switch Further is there a function `W2Mstr that can translate the ML representation to a string that can be pasted directly into the mathematica editor (quite useful) Further there is workaround that allows put to handle Int128 by performing a prime factorization (since it's currently not suported). The functions also comes with some basic tests (see attachments in zip file). I'd love to make this parts of the package, so if there is anything i can do to help please let me know. |
to be honest, my time is limited so that I really only have time to do bug fixes. Your best option might be to just create a new package (which is fairly simple in Julia), and add this as a dependency. |
Unless of course someone wants to take over maintenance. |
I think you are correct that my wished would better fit a new package. Let me therefore present MathLinkExtras, where this is all implemented. Hopefully it can make it al the way to be a full fledged julia package. |
Thanks: I'm sure there are others that would find that useful!
It should be possible to handle this by passing it as a string, as we do for Lines 87 to 92 in ab8ed47
I'd be happy to add that, if you want to open a PR? |
Hi, if it's that easy to mend that would be great. I'd love to open a PR for it but I can't seem to install the package from the repository source. julia> using MathLink |
Yeah, you have to |
Ah, silly me. Now it works :) |
Hi. Is there a particular reason why the library has chosen not to overload the basic arithmetic operator such as +,-,*,/?
Currently need to add some biolerpate code at the top to e able to things like
x=W"x"
y=W"y"
z=x+y
w=x-y
import Base.+
import Base.*
import Base.-
import Base./
+(a::MathLink.WSymbol,b::MathLink.WSymbol)=weval(W"Plus"(a,b))
+(a::MathLink.WExpr,b::MathLink.WSymbol)=weval(W"Plus"(a,b))
+(a::MathLink.WExpr,b::MathLink.WExpr)=weval(W"Plus"(a,b))
-(a::MathLink.WSymbol)=weval(W"Minus"(a))
-(a::MathLink.WExpr)=weval(W"Minus"(a))
-(a::MathLink.WSymbol,b::MathLink.WSymbol)=weval(W"Plus"(a,W"Minus"(b)))
-(a::MathLink.WExpr,b::MathLink.WSymbol)=weval(W"Plus"(a,W"Minus"(b)))
-(a::MathLink.WExpr,b::MathLink.WExpr)=weval(W"Plus"(a,W"Minus"(b)))
*(a::MathLink.WExpr,b::MathLink.WExpr)=weval(W"Times"(a,b))
*(a::MathLink.WSymbol,b::MathLink.WExpr)=weval(W"Times"(a,b))
*(a::MathLink.WExpr,b::MathLink.WSymbol)=weval(W"Times"(a,b))
*(a::MathLink.WSymbol,b::MathLink.WSymbol)=weval(W"Times"(a,b))
/(a::MathLink.WSymbol,b::MathLink.WSymbol)=weval(W"Times"(a, W"Power"(b, -1)))
/(a::MathLink.WExpr,b::Number)=weval(W"Times"(a, W"Power"(b, -1)))
The text was updated successfully, but these errors were encountered: