I've been working a little on porting https://github.com/tbuktu/bigint to scala and using value classes and universal traits to implement BigInt. So far my implementation seems to have a linear speed improvement over scala.math.BigInt on repeated addition. I was curious, if I get this code into good shape would it be able to be added to the standard library?
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I'll contact Tim Buktus and see if he'd be willing to work with us on the licence.
I'll contact Tim Buktus and see if he'd be willing to work with us on the licence.
I would prefer it if we could get at least Erik and someone from the Scala team on board first and figure out the content, the wordening, the reasoning and the value proposition of the mail together.
--
If it's going to be a non-negligible amount of work, I'd also want to make sure we're starting in the right place.
It's not clear to me that BigInteger even has the right model; it would be a shame to pour lots of effort into something that is going to end up being e.g. 2x slower than it needs to be due to details in how data is laid out etc.
Agreed. Getting permission here is really just about being able to use
their code as a reference without worrying about possible copyright
issues.
Hi Rex,If it's going to be a non-negligible amount of work, I'd also want to make sure we're starting in the right place.
having evaluated a lot options, I think Tim Buktu's and Alan Eliasen's is the right starting point. The code is extremely fast, has undergone an immense amount of testing and is currently intended to be integrated into OpenJDK.
It's not clear to me that BigInteger even has the right model; it would be a shame to pour lots of effort into something that is going to end up being e.g. 2x slower than it needs to be due to details in how data is laid out etc.
Pretty much the only thing I'm interested in (and which has the chance to be relicensed) are the algorithms.
I have already looked into how the representation can be optimized and apart from leaving out deprecated, superfluous fields, the decision between a BigEndian and a LitteEndian representation of the magnitude and whether to represent the sign as a field or put it in the array in front of the magnitude are the only important decisions to make.
There is no questions that it will be faster than scala's BigInt. It even beats the shit out of the current Java one. We just need to benchmark it to make sure that no regression is introduced.
If it's going into OpenJDK anyway, why do we need to do anything but wait?
Also, maybe the benchmarks are screwy, but it's not hard at all to beat BigInteger at small sizes also.
Well, the algorithms aren't novel; they're the result of numerical computing research and are used in a variety of places (e.g. GMP). It's nice to have a reference implementation for the more complicated algorithms.
Er, really? You don't think that creating log(n) extra temporary copies in recursive routines might be not the fastest/most memory-efficient way to do things (for example)? Or not re-using existing data which will fit because your code is all in the immutable path? And the 32 bit vs. 64 bit word size is likely to be important also--is it really true that going to a 64 bit word is not dramatically better on a 64 bit machine? (And can we do both without extraordinary extra effort?)
It's very important to get the algorithms right first, especially when you have n^2 vs. n^1.58 vs. n^1.4 vs. n log n log log n with multiplication, for instance. But the overall design of the library strikes me as wrong: you want to have a private mutable phase where you can reuse space for calculations. I suppose one could move everything into MutableBigInteger, but then you have double object creations on everything which is a drag for not-so-big BigIntegers.
Anyway, I am far from convinced that the current framework is the right one. It looks to me like it follows BigInteger's general design principles, which I think were right for ease-of-correctness but wrong for speed, and if you're going to spend a lot of effort on speed it makes sense to spend a bit more effort obtaining correctness in a slightly-less-easy-but-more-performant framework while protecting the library user from having to worry about it at all.
Anything else?
Thanks and bye,
Simon
Yes, we'd definitely welcome a faster Bigint type in Spire. For thone that don't know, amongst other things, Spire provides several new number types for Scala, including complex and rational numbers, floating point filters, a work with anything type, a number type for exact geometric computation, etc.
I'd like to see this sort of code incubated and matured in an independent open-source library before being included in the standard library (if at all.) Spire might provide a good home for this.
I'm happy about every contribution here, because I really suck at some of these tasks. :-)
Thanks and bye,
Simon
One thing that's going to be weird though is the continued existence
of scala.math.BigDecimal and scala.math.BigInt (not to mention the
rest of the scala.math package). What are the long-term plans for
these classes? Are there any?
On Sun, May 5, 2013 at 12:50 PM, Erik Osheim <er...@plastic-idolatry.com> wrote:One thing that's going to be weird though is the continued existence
of scala.math.BigDecimal and scala.math.BigInt (not to mention the
rest of the scala.math package). What are the long-term plans for
these classes? Are there any?To the extent that I have any say, I would desperately like to get them out of the core library.
I think we should aim at shipping an interface and let people compete to be the implementation. We will never be able to properly manage the super-fiddly, detail-oriented, easy to mis-design areas like math classes.
There clearly are people who can and would do it better, and it's highly unfortunate that it's so hard to get to a place where they can do that.
To the extent that I have any say, I would desperately like to get them out of the core library. I think we should aim at shipping an interface and let people compete to be the implementation. We will never be able to properly manage the super-fiddly, detail-oriented, easy to mis-design areas like math classes. There clearly are people who can and would do it better, and it's highly unfortunate that it's so hard to get to a place where they can do that.
My observations in this arena strongly suggest this is not how it happens. "Math" may have one right answer, but code never does.