Generic Algorithms in IronPython QuickStart Sample
Illustrates how to write algorithms that are generic over the numerical type of the arguments in IronPython.
This sample is also available in: C#, Visual Basic, F#.
Overview
This QuickStart sample demonstrates how to write numerical algorithms that can work with different numeric types using Numerics.NET’s generic arithmetic capabilities.
The sample implements a Newton-Raphson root-finding algorithm that can work with any numeric type that supports the required operations. It shows how to:
- Create a generic solver class that can work with different numeric types
- Use the Operations
class to perform arithmetic operations generically - Solve equations using different numeric types including:
- BigFloat for arbitrary-precision floating point
- BigRational for exact rational arithmetic
- Double for standard floating point
The sample includes concrete examples that:
- Compute π by finding the root of sin(x) using arbitrary precision arithmetic
- Calculate √2 using exact rational arithmetic
- Find the value of Lambert’s W function using double precision
It demonstrates how to write truly generic numerical code that can work with any numeric type while maintaining good performance and numerical stability. The sample also shows how to use Numerics.NET’s generic provider system and license verification.
The code
Coming soon...