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 325 10/23/2023
3.1.5 175 8/30/2023
3.1.4 188 8/28/2023
3.1.3 242 7/14/2023
3.1.2 337 2/28/2023
3.1.1 523 9/22/2022
3.1.0 416 9/8/2022
3.0.0 389 8/25/2022
2.3.0 437 8/12/2022
2.2.9 379 8/12/2022
2.2.8 427 8/11/2022
2.2.7 422 8/8/2022
2.2.6 384 8/4/2022
2.2.5 427 7/27/2022
2.2.4 472 5/31/2022
2.2.3 415 5/20/2022
2.2.2 495 4/14/2022
2.2.1 446 4/8/2022
2.2.0 439 4/7/2022
2.1.9 450 3/24/2022
2.1.8 433 3/10/2022
2.1.7 438 3/5/2022
2.1.6 430 3/3/2022
2.1.5 426 3/2/2022
2.1.4 440 2/23/2022
2.1.3 421 2/18/2022
2.1.2 428 2/14/2022
2.1.1 419 2/14/2022
2.1.0 437 2/11/2022
2.0.0 432 2/9/2022
1.3.2 458 1/30/2022
1.3.1 312 1/5/2022
1.3.0 367 11/9/2021
1.2.9 366 10/28/2021
1.2.8 379 10/19/2021
1.2.7 317 10/18/2021
1.2.6 477 10/17/2021
1.2.5 332 10/16/2021
1.2.4 338 10/15/2021
1.2.3 354 10/11/2021
1.2.2 361 10/8/2021
1.2.1 323 10/6/2021
1.2.0 309 10/5/2021
1.1.9 353 8/31/2021
1.1.8 334 7/21/2021
1.1.7 345 7/15/2021
1.1.6 366 6/3/2021
1.1.5 608 1/5/2021
1.1.4 479 12/16/2020
1.1.3 401 10/13/2020
1.1.2 428 10/7/2020
1.1.1 484 10/2/2020
1.1.0 428 9/29/2020
1.0.9 424 9/25/2020
1.0.8 454 9/23/2020
1.0.7 505 9/17/2020
1.0.6 519 9/17/2020
1.0.5 881 7/15/2020
1.0.4 538 6/14/2020
1.0.3 556 6/6/2020
1.0.2 463 5/6/2020
1.0.1 471 5/6/2020
1.0.0 493 5/6/2020