STb <FuncDecl, Expr, Sort> GenerateEncoder() { var ctx = _automataCtx.Z3; Expr inputVar = _automataCtx.MkVar(0, ctx.MkBitVecSort(8)); Expr registerVar = _automataCtx.MkVar(1, _automataCtx.MkTupleSort()); Sort outputSort = ctx.BoolSort; var stb = new STb <FuncDecl, Expr, Sort>(_automataCtx, DeclarationType.Name, inputVar.Sort, outputSort, registerVar.Sort, _automataCtx.MkTuple(), 0); var leafPatterns = new Dictionary <byte, bool[]>(); FindLeafPatterns(leafPatterns, _tree, new Stack <bool>()); var patterns = new bool[256][]; foreach (var entry in leafPatterns) { patterns[entry.Key] = entry.Value; } Debug.Assert(patterns.Select((x, i) => patterns.Select((y, j) => i == j || x.Length != y.Length || x.Zip(y, (a, b) => Tuple.Create(a, b)).Any(z => z.Item1 != z.Item2)).All(z => z)).All(z => z)); Debug.Assert(patterns.All(x => x != null), "Internal Huffman tree is missing leaves"); stb.AssignRule(0, GetBinarySearchRule(ctx, (BitVecExpr)inputVar, registerVar, patterns, 0, patterns.Length)); stb.AssignFinalRule(0, new BaseRule <Expr>(Sequence <Expr> .Empty, registerVar, 0)); stb = stb.Compose(GenerateToBytes()); stb = stb.ExploreBools(); if (ShowGraphStages.Count > 0) { stb.ToST().ShowGraph(); } return(stb); }