Closed stewienj closed 5 years ago
Unfortunately I wrote this code before I read you recent replies. The new project targets .NET 4.7.2, you'll need to change this to a version supported by VS2015.
Generic number types, how very interesting. This is a limitation of the language that I have ran up against many times. Because you cant declare static members in interfaces, there is no good clean way to approach making a generic type that supports arithmetic operations.
I see you use Linq.Expressions to build an appropriate type converter. I didn't realize Expression.Convert did so much for you in terms of selecting the right convert method. Interesting!
Actually, it is a bit of a coincidence that you happened to show me just such an implementation; I actually just implemented generic arithmetic types successfully for the first time a few days ago (I have attempted to do this before, but unsuccessfully). I have a symbolic polynomial arithmetic library, and I wanted to be able to swap out the coefficient's BigInteger type that it performs arithmetic on for a BigComplex type, and BigRational, and finally, I have done just that! Obviously my implementation is a bit more involved, as it must support a few more operations. Feel free to check out my implementation, Id be interested if you have any suggestions on how to improve it or if you see anything that needs more clarity: https://github.com/AdamWhiteHat/Polynomial/tree/GenericArithmeticTypes
I haven't had the chance to explore what you've done with your polynomial arithmetic library, so I can't give any informed feedback. I've got multiple projects on the go right now so I'm working days, nights, and weekends. Regarding writing classes that can take generic numeric types, I'm looking forward to trying out the Shapes/Type Classes C# implementation which hasn't been released yet https://github.com/dotnet/csharplang/issues/164
So I explored/played around with your MullersReucrrenceExample, read the related scipython link from the other pull request and checked out some of Jean-Michel Muller's publications, in particular some slideshows from a presentation about how to implement arithmetic in floating point numbers without loss of precision. All interesting stuff, and indeed arithmetic using BitRational does not suffer from divergence like floating point types do.
In regards to this pull request, I just don't think the MullersReucrrenceExample project fits within the scope / aim of this project, which is to be a BigRational library, and I feel including this project would be confusing and/or distracting for others who might seek to clone down the BigRational library and wrap their mind around it. Further, I feel this concept is already sufficiently and appropriately addressed/demonstrated in the project's unit test TestMullersRecurrenceConvergesOnFive that you contributed in one of the earlier pull requests..
So, I will be rejecting this pull request, but thank you for all your other contributions, and interest in my project.
This compares float, double, decimal and BigRational using Muller's Recurrence which I've used before in a test. The code uses some interesting constructs to allow the number type to be used as a generic. Potentially the code could be modified to generate Markdown code that could be added to the readme to show the functionality of BigRational. Note this depends on my previous pull request that adds the conversion from BigRational to a decimal type.