Skip to content

Getting Started

Ryan Beckett edited this page Jan 6, 2021 · 5 revisions

Installation

Just add the project to your visual studio solution. A nuget package is available here.

Library Overview

To import the library, add the following lines to your source 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 the library knows how to manipulate. As a simple example, consider the following code that computes a new integer from two integer inputs x and y:

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

Zen overloads common C# operators such as &,|,^,<=, <, >, >=, +, -, *, true, false to work over Zen values and supports implicit conversions between C# values and Zen values. To use Zen, we must next create a ZenFunction to wrap the MultiplyAndAdd function:

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

Now we can leverage Zen to find function inputs that lead to some outcome. For example, we can find an (x, y) input pair such that x is less than zero and the output of the function is 11:

var input = function.Find((x, y, result) => And(x <= 0, result == 11)); 
// input.Value = (-1883171776, 1354548043)
Clone this wiki locally