Microsoft.Z3.Model.FuncInterp C# (CSharp) Méthode

FuncInterp() public méthode

Retrieves the interpretation (the assignment) of a non-constant f in the model.
public FuncInterp ( FuncDecl f ) : FuncInterp
f FuncDecl A function declaration of non-zero arity
Résultat FuncInterp
        public FuncInterp FuncInterp(FuncDecl f)
        {
            Contract.Requires(f != null);

            Context.CheckContextMatch(f);

            Z3_sort_kind sk = (Z3_sort_kind)Native.Z3_get_sort_kind(Context.nCtx, Native.Z3_get_range(Context.nCtx, f.NativeObject));

            if (f.Arity == 0)
            {
                IntPtr n = Native.Z3_model_get_const_interp(Context.nCtx, NativeObject, f.NativeObject);

                if (sk == Z3_sort_kind.Z3_ARRAY_SORT)
                {
                    if (n == IntPtr.Zero)
                        return null;
                    else
                    {
                        if (Native.Z3_is_as_array(Context.nCtx, n) == 0)
                            throw new Z3Exception("Argument was not an array constant");
                        IntPtr fd = Native.Z3_get_as_array_func_decl(Context.nCtx, n);
                        return FuncInterp(new FuncDecl(Context, fd));
                    }
                }
                else
                {
                    throw new Z3Exception("Constant functions do not have a function interpretation; use ConstInterp");
                }
            }
            else
            {
                IntPtr n = Native.Z3_model_get_func_interp(Context.nCtx, NativeObject, f.NativeObject);
                if (n == IntPtr.Zero)
                    return null;
                else
                    return new FuncInterp(Context, n);
            }
        }

Usage Example

    /**
       \brief Custom model pretty printer.
    */
    void display_model(System.IO.TextWriter w, Model model)
    {
        w.WriteLine("Custom model display:");
        FuncDecl[] consts = model.ConstDecls;
        for (int i = 0; i < consts.Length; i++)
        {
            w.WriteLine("{0} |-> {1}", consts[i], model.Evaluate(consts[i].Apply()));
        }
        w.WriteLine("num consts: {0}", consts.Length);
        FuncDecl[] funcs = model.FuncDecls;
        foreach (FuncDecl f in funcs)
        {
            FuncInterp g = model.FuncInterp(f);

            w.WriteLine("function {0}:", f);
            for (int j = 0; j < g.Entries.Length; ++j)
            {
                for (int k = 0; k < g.Entries[j].Args.Length; ++k)
                {
                    w.Write("  {0} ", g.Entries[j].Args[k]);
                }
                w.WriteLine(" |-> {0}", g.Entries[j].Value);
            }
            w.WriteLine("  else |-> {0}", g.Else);
        }
    }