Sylvester.Arithmetic
0.2.8.1
dotnet add package Sylvester.Arithmetic --version 0.2.8.1
NuGet\Install-Package Sylvester.Arithmetic -Version 0.2.8.1
<PackageReference Include="Sylvester.Arithmetic" Version="0.2.8.1" />
paket add Sylvester.Arithmetic --version 0.2.8.1
#r "nuget: Sylvester.Arithmetic, 0.2.8.1"
// Install Sylvester.Arithmetic as a Cake Addin
#addin nuget:?package=Sylvester.Arithmetic&version=0.2.8.1
// Install Sylvester.Arithmetic as a Cake Tool
#tool nuget:?package=Sylvester.Arithmetic&version=0.2.8.1
Sylvester.Arithmetic
This library implements lightweight dependently typed natural number arithmetic and constraints which enable arithmetic operations like bounds checking to be performed at compile-time by the F# type checker as long as the values for the operations are known at compile-time.
open Sylvester.Arithmetic
///Create typed representations of some natural numbers
let a,b,c = new nat<400>(), new nat<231111>(), new nat<6577700>()
a + b + c
nat<6809211>
These values have types derived from Sylvester.Arithmetic.N10. The type of a
is N10<0,0,0,0,0,0,0,4,0,0> and the type of c
is N10<0,0,0,6,5,7,7,7,0,0>.
c.GetType()
Sylvester.Arithmetic.N10+N10`10[Sylvester.Arithmetic.Base10+0,Sylvester.Arithmetic.Base10+0,Sylvester.Arithmetic.Base10+0,Sylvester.Arithmetic.Base10+6,Sylvester.Arithmetic.Base10+5,Sylvester.Arithmetic.Base10+7,Sylvester.Arithmetic.Base10+7,Sylvester.Arithmetic.Base10+7,Sylvester.Arithmetic.Base10+0,Sylvester.Arithmetic.Base10+0]
The types of the results of arithmetic operations depend on the values of the operands.
let d = (a + b + c) * four
d
nat<27236844>
d.GetType()
Sylvester.Arithmetic.N10+N10`10[Sylvester.Arithmetic.Base10+0,Sylvester.Arithmetic.Base10+0,Sylvester.Arithmetic.Base10+2,Sylvester.Arithmetic.Base10+7,Sylvester.Arithmetic.Base10+2,Sylvester.Arithmetic.Base10+3,Sylvester.Arithmetic.Base10+6,Sylvester.Arithmetic.Base10+8,Sylvester.Arithmetic.Base10+4,Sylvester.Arithmetic.Base10+4]
This enables type-level constraints to be written which run at compile-time
check(d +< ten) /// Type error
Type mismatch. Expecting a
'Constraint<Success>'
but given a
'Constraint<Failure>'
The type 'Success' does not match the type 'Failure'
a - (two * a) /// A negative number results in a type representing an underflow at compile-time
N10Underflow
let myop a b c d =
check(a +> b)
check (b +== zero)
check (c +== (a + one))
a + b + c + d
myop four five four ten ///Type error. Program will not compile
Type mismatch. Expecting a
'Constraint<Success>'
but given a
'Constraint<Failure>'
The type 'Success' does not match the type 'Failure'
Type mismatch. Expecting a
'Constraint<Success>'
but given a
'Constraint<Failure>'
The type 'Success' does not match the type 'Failure'
let myop a b c d =
check(a +> b)
check (b +== zero)
check (c +== (a + one))
a + b + c + d
myop seven zero eight ten ///Program compiles once the parameters to myop satisfy the arithmetic constraints
nat<25>
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
- FSharp.Core (>= 4.3.4)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Sylvester.Arithmetic:
Package | Downloads |
---|---|
Sylvester.tf
High-level functional and verifiable TensorFlow 2.0 API. |
|
Sylvester.Collections
Sylvester number-parameterized collection types. These collection types can perform static verification of lengths and indices as long as some information about these values is available at compile time. |
|
Sylvester.Tensors
Linear algebra types with type-level numeric dimensions |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.2.8.1 | 326 | 5/11/2021 |
0.2.8 | 229 | 5/11/2021 |
0.2.7 | 295 | 3/8/2021 |
0.2.6.1 | 311 | 3/7/2021 |
0.2.6 | 305 | 3/7/2021 |
0.2.5.1 | 397 | 2/6/2020 |
0.2.5 | 403 | 2/6/2020 |
0.2.4 | 1,232 | 1/16/2020 |
0.2.3 | 370 | 1/16/2020 |
0.2.2.1 | 1,452 | 1/3/2020 |
0.2.2 | 384 | 1/3/2020 |
0.2.1 | 478 | 12/30/2019 |
0.2.0 | 386 | 12/30/2019 |
0.1.7 | 430 | 6/23/2019 |
0.1.6 | 506 | 6/22/2019 |
0.1.5.1 | 625 | 6/21/2019 |
0.1.3 | 435 | 6/12/2019 |
0.1.2.2 | 444 | 6/10/2019 |
0.1.2.1 | 456 | 6/10/2019 |
Move types and functions to module instead of namespace and remove unneeded code. Add max and min functions.