-
Notifications
You must be signed in to change notification settings - Fork 0
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
Using parametric types for Symbolic? #1
Comments
Furthermore, multiple dispatch should try to do compile-time optimizations whenever the method can be unambiguously determined by type-inference. |
Another thought, 32 bit architectures work on 4 byte chunks, 64 bit archs on 8 byte chunks. That is, if |
👍 for trying parametric types. There will be no performance loss usually, I guess. And there can be some performance gain when the dispatch can be done statically. Such technique will make Julia dispatching system shine once again. (I always wonder why it is not used in the Expr type in the first place.) |
There is another project about symbolic math in Julia: That looks more like a clone of Wolfram Mathematica. In SJulia there is a base object called
In SJulia it becomes The thing I don't like of Mathematica is its lack of support for mixed commutative-noncommutative elements in a multiplication, SJulia has the same problem. |
This approach is what I originally was using, but switched due to performance issues. Multiple dispatch is great for composability, and can result in fast code when the concrete type of the object is known at compile time. The reason such an approach is slower is because of the need to store arbitrary expressions in the
Yeah, I responded to that thread on julia-users a while ago. I don't care for his approach of storing everything in
I didn't intend for this to be the CAS for Julia. Maybe later, but I really like the way CSymPy is going, and think in the long run that's the best bet. |
I really wish julia had a |
Oh, I see. Anyways, I think that's a Julia limitation, because if you define a type such as
all of its subtypes (e.g. |
Yes, but because they are different types, then any methods being called on them may be different from element to element, and so the dispatch must happen at runtime, rather than compile time. |
Closing in favor of #2 . |
I think that is a Julia issue, even if they are different types, the memory access is the same. Julia's compiler fails to recognize that. CSymPy uses subtypes without losing performance. Maybe C++ compilers are currently better than Julia's? |
It has nothing to do with the memory access. Fundamentally
because it has no knowledge of which Certainly the compiler for a new language like Julia isn't as good as those of C++, but there is a fundamental difference between parametric types in Julia and subclasses in C++. For more info: http://julia.readthedocs.org/en/latest/manual/types/#man-parametric-types |
I'm sorry, I meant field access. I have no computer access right now. The parametric types in my example are still slower when accessing a field. Field access in that mixed array may be made static, if Julia's compiler had the proper optimization, because all those different types have the same memory space. C++ introduces similar issues due to class inheritance, CSymPy uses class inheritance, Add and Mul are different types, but there is no such performance loss. I conclude that C++ compiler has better optimizations than Julia's. I believe that once such problems are addressed in Julia, the approach of this issue will work well. Concerning the switch, do you mean a binary tree or hash table lookup at assembly code instead of a nested list of ifs, or airthmetic operations to determine the jump size? I believe that a well optimized compiler should treat nested ifs and a switch statement the same way. |
Either or. There was some talk in a thread I read a while back that LLVM can perform this optimization, but looking at |
Hi, I have noticed that you define the type of
Symbolic
by anInt8
parameter (notUInt8
?).What about a parametric type instead? That is, something like
Symbolic{:Add}(args...)
.This way you can use multiple dispatch easily on the node types. Mathematica uses "Plus", "Times", "Power" in its M-expressions, and it doesn't seem to be a noticeable performance loss over an
Int8
.The text was updated successfully, but these errors were encountered: