ZenLib 1.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package ZenLib --version 1.0.7                
NuGet\Install-Package ZenLib -Version 1.0.7                
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="ZenLib" Version="1.0.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZenLib --version 1.0.7                
#r "nuget: ZenLib, 1.0.7"                
#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.
// Install ZenLib as a Cake Addin
#addin nuget:?package=ZenLib&version=1.0.7

// Install ZenLib as a Cake Tool
#tool nuget:?package=ZenLib&version=1.0.7                

Introduction

Zen is a research library that aims to simplify the process of building verification tools. Zen lets users write a single implementation of a function and then execute, compile, and verify that function.

Getting Started

To import the library, add the following line to your file:

using ZenLib;
using static ZenLib.Language;

The main abstraction Zen provides is through the type Zen<T> which represents a value of type T that can be either concrete or symbolic. As a simple example, consider the following code:

Zen<int> MultiplyAndAdd(Zen<int> x, Zen<int> y)
{
    return 3 * x + y;
}

This is a function that takes two Zen parameters (x and y) that represents an integer values and returns a new Zen value of type integer by multiplying x by 3 and adding y to the result. Zen overloads common C# operators such as &,|,^,<=, <, >, >=, +, -, *, true, false to work over Zen values and supports implicit conversions between literals and Zen values.

The next step is to create a ZenFunction:

var function = Function<int, int, int>(MultiplyAndAdd);

Given a ZenFunction we can leverage the library to perform multiple tasks. The first is to simply evaluate the function on a collection of inputs:

var output = function.Evaluate(3, 2); // output = 11

To perform verification, we can ask Zen to find us the inputs that leads to something being true:

var input = function.Find((x, y, result) => And(x >= 0, x <= 10, result == 11)); // input.Value = (0, 11)

The type of the result in this case will be Option<(int, int)>, which will have a pair of integer inputs that make the expression true if such a pair exists.

Finally, Zen can compile the function to generate IL at runtime that executes without a performance penalty.

function.Compile();
output = function.Evaluate(3, 2); // output = 11

Comparing the performance between the two:

var watch = System.Diagnostics.Stopwatch.StartNew();

for (int i = 0; i < 1000000; i++) function.Evaluate(3, 2);

Console.WriteLine($"interpreted function time: {watch.ElapsedMilliseconds}ms");
watch.Restart();

function.Compile();
Console.WriteLine($"compilation time: {watch.ElapsedMilliseconds}ms");
watch.Restart();

for (int i = 0; i < 1000000; i++) function.Evaluate(3, 2);

Console.WriteLine($"compiled function time: {watch.ElapsedMilliseconds}ms");
interpreted function time: 4601ms
compilation time: 4ms
compiled function time: 2ms

Supported Types

Zen currently supports the following primitive types: bool, byte, short, ushort, int, uint, long, ulong, string. It also supports values of type Tuple<T1, T2>, (T1, T2), Option<T>, IList<T> and IDictionary<T> so long as the inner types are also supported. Zen has some limited support for class and struct types; it will attempt to model all public fields and properties. The class/struct must also have a default constructor.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.6 525 10/23/2023
3.1.5 211 8/30/2023
3.1.4 219 8/28/2023
3.1.3 283 7/14/2023
3.1.2 367 2/28/2023
3.1.1 567 9/22/2022
3.1.0 450 9/8/2022
3.0.0 418 8/25/2022
2.3.0 477 8/12/2022
2.2.9 413 8/12/2022
2.2.8 460 8/11/2022
2.2.7 452 8/8/2022
2.2.6 418 8/4/2022
2.2.5 471 7/27/2022
2.2.4 634 5/31/2022
2.2.3 440 5/20/2022
2.2.2 528 4/14/2022
2.2.1 477 4/8/2022
2.2.0 474 4/7/2022
2.1.9 472 3/24/2022
2.1.8 463 3/10/2022
2.1.7 471 3/5/2022
2.1.6 458 3/3/2022
2.1.5 464 3/2/2022
2.1.4 473 2/23/2022
2.1.3 452 2/18/2022
2.1.2 455 2/14/2022
2.1.1 446 2/14/2022
2.1.0 469 2/11/2022
2.0.0 461 2/9/2022
1.3.2 487 1/30/2022
1.3.1 341 1/5/2022
1.3.0 395 11/9/2021
1.2.9 391 10/28/2021
1.2.8 407 10/19/2021
1.2.7 350 10/18/2021
1.2.6 505 10/17/2021
1.2.5 363 10/16/2021
1.2.4 375 10/15/2021
1.2.3 378 10/11/2021
1.2.2 378 10/8/2021
1.2.1 333 10/6/2021
1.2.0 336 10/5/2021
1.1.9 384 8/31/2021
1.1.8 347 7/21/2021
1.1.7 378 7/15/2021
1.1.6 395 6/3/2021
1.1.5 645 1/5/2021
1.1.4 517 12/16/2020
1.1.3 435 10/13/2020
1.1.2 462 10/7/2020
1.1.1 509 10/2/2020
1.1.0 455 9/29/2020
1.0.9 459 9/25/2020
1.0.8 482 9/23/2020
1.0.7 536 9/17/2020
1.0.6 553 9/17/2020
1.0.5 913 7/15/2020
1.0.4 572 6/14/2020
1.0.3 587 6/6/2020
1.0.2 501 5/6/2020
1.0.1 488 5/6/2020
1.0.0 526 5/6/2020