Ratiocinia.Models 0.1.3

dotnet add package Ratiocinia.Models --version 0.1.3
                    
NuGet\Install-Package Ratiocinia.Models -Version 0.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ratiocinia.Models" Version="0.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ratiocinia.Models" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="Ratiocinia.Models" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ratiocinia.Models --version 0.1.3
                    
#r "nuget: Ratiocinia.Models, 0.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ratiocinia.Models@0.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ratiocinia.Models&version=0.1.3
                    
Install as a Cake Addin
#tool nuget:?package=Ratiocinia.Models&version=0.1.3
                    
Install as a Cake Tool

Ratiocinia

A rational number arithmetic library for .NET using generic math. Core algorithms are adapted from Boost.Rational.

Features

  • Generic Math Support: Works with any IBinaryInteger<T> type via Rational<T>
  • Arbitrary Precision: BigIntegerRational for unlimited precision arithmetic
  • Policy-Based Design: Choose between checked and unchecked arithmetic at compile-time
  • Full INumberBase Implementation: Rationals integrate seamlessly with .NET generic math APIs
  • Automatic Normalization: All rationals are stored in canonical form (positive denominator, GCD of 1)

Installation

Install via NuGet:

# For Rational<T> and BigIntegerRational
dotnet add package Ratiocinia.Rational

Or via Package Manager Console:

Install-Package Ratiocinia.Rational

Quick Start

Using Rational<T>

using Ratiocinia;

// Create rational numbers (automatically normalized)
var half = Rational.Create(1, 2);
var third = Rational.Create(1, 3);

// Arithmetic operations
var sum = half + third;        // 5/6
var product = half * third;    // 1/6
var quotient = half / third;   // 3/2

// Checked arithmetic (throws on overflow)
var result = checked(half + third);

// Comparisons
bool isLess = half < third;    // false
bool isEqual = half == half;   // true

// INumberBase methods
bool isInteger = Rational<int>.IsInteger(half);     // false
bool isZero = Rational<int>.IsZero(half);           // false
bool isPositive = Rational<int>.IsPositive(half);   // true

Using BigIntegerRational

using Ratiocinia;
using System.Numerics;

// Create from BigInteger values
var large = BigIntegerRational.Create(
    BigInteger.Parse("123456789012345678901234567890", CultureInfo.InvariantCulture),
    BigInteger.Parse("987654321098765432109876543210", CultureInfo.InvariantCulture)
);

// Or from smaller integers
var simple = BigIntegerRational.Create(22, 7);

// Full arithmetic support
var sum = large + simple;
var product = large * simple;

Architecture

Ratiocinia uses a layered architecture with policy-based design. Project references between packages are:

graph BT
  Abstractions["Abstractions"]
  AlgorithmsGeneric["Algorithms.Generic"]
  Models["Models"]
  AlgorithmsSpecialized["Algorithms.Specialized"]
  Rational["Rational"]
  AlgorithmsGeneric --> Abstractions
  Models --> AlgorithmsGeneric
  Models --> Abstractions
  AlgorithmsSpecialized --> AlgorithmsGeneric
  AlgorithmsSpecialized --> Models
  Rational --> AlgorithmsSpecialized
  Rational --> Models

Projects

Project Description
Ratiocinia.Abstractions Pure interfaces for math operations
Ratiocinia.Algorithms.Generic Policy-based rational arithmetic algorithms
Ratiocinia.Models Checked/unchecked arithmetic policy implementations
Ratiocinia.Algorithms.Specialized Convenience wrappers using .NET generic math
Ratiocinia.Rational Rational<T> and BigIntegerRational structs

Design Principles

  • Policy-Based Algorithms: Core algorithms accept policy parameters implementing operation interfaces. This separates algorithms from checked/unchecked arithmetic behavior.

  • Normalization: Rationals are always stored in normalized form. Use Create() to auto-normalize or TryCreate() to validate pre-normalized values.

  • INumberBase Conformance: Both rational types fully implement INumberBase<T>, enabling use with generic numeric algorithms.

Building

Prerequisites

  • .NET 10.0 SDK or later (see global.json)

Commands

# Build entire solution
dotnet build Ratiocinia.sln

# Build in Release mode
dotnet build Ratiocinia.sln -c Release

# Run all tests
dotnet test Ratiocinia.sln

# Run specific test project
dotnet test tests/Tests.Algorithms/Tests.Algorithms.csproj

# Run specific test by name filter
dotnet test tests/Tests.Algorithms/Tests.Algorithms.csproj --filter "FullyQualifiedName~Add_reduces_result"

# Run benchmarks
dotnet run -c Release --project benchmarks/Benchmarks.Algorithms/Benchmarks.Algorithms.csproj

Requirements

  • .NET 7.0+ for Rational<T>, BigIntegerRational, and specialized algorithms
  • .NET Standard 2.0 compatible for abstractions and generic algorithms

License

This project is licensed under the MIT License.

Acknowledgments

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Ratiocinia.Models:

Package Downloads
Ratiocinia.Algorithms.Specialized

Convenience wrappers over the core rational algorithms using .NET generic math constraints.

Ratiocinia.Rational

Generic Rational<T> for any IBinaryInteger<T>, fully integrated with .NET generic math. Arbitrary-precision rational arithmetic via BigIntegerRational.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.3 126 1/16/2026
0.1.2 125 1/15/2026