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 535 10/23/2023
3.1.5 213 8/30/2023
3.1.4 221 8/28/2023
3.1.3 285 7/14/2023
3.1.2 371 2/28/2023
3.1.1 571 9/22/2022
3.1.0 452 9/8/2022
3.0.0 420 8/25/2022
2.3.0 479 8/12/2022
2.2.9 415 8/12/2022
2.2.8 462 8/11/2022
2.2.7 454 8/8/2022
2.2.6 420 8/4/2022
2.2.5 473 7/27/2022
2.2.4 638 5/31/2022
2.2.3 442 5/20/2022
2.2.2 530 4/14/2022
2.2.1 479 4/8/2022
2.2.0 476 4/7/2022
2.1.9 474 3/24/2022
2.1.8 465 3/10/2022
2.1.7 473 3/5/2022
2.1.6 460 3/3/2022
2.1.5 466 3/2/2022
2.1.4 475 2/23/2022
2.1.3 454 2/18/2022
2.1.2 457 2/14/2022
2.1.1 448 2/14/2022
2.1.0 471 2/11/2022
2.0.0 465 2/9/2022
1.3.2 489 1/30/2022
1.3.1 343 1/5/2022
1.3.0 397 11/9/2021
1.2.9 393 10/28/2021
1.2.8 409 10/19/2021
1.2.7 352 10/18/2021
1.2.6 507 10/17/2021
1.2.5 365 10/16/2021
1.2.4 377 10/15/2021
1.2.3 380 10/11/2021
1.2.2 380 10/8/2021
1.2.1 337 10/6/2021
1.2.0 338 10/5/2021
1.1.9 386 8/31/2021
1.1.8 349 7/21/2021
1.1.7 380 7/15/2021
1.1.6 397 6/3/2021
1.1.5 649 1/5/2021
1.1.4 520 12/16/2020
1.1.3 437 10/13/2020
1.1.2 464 10/7/2020
1.1.1 511 10/2/2020
1.1.0 457 9/29/2020
1.0.9 461 9/25/2020
1.0.8 484 9/23/2020
1.0.7 538 9/17/2020
1.0.6 555 9/17/2020
1.0.5 915 7/15/2020
1.0.4 574 6/14/2020
1.0.3 589 6/6/2020
1.0.2 503 5/6/2020
1.0.1 490 5/6/2020
1.0.0 528 5/6/2020