Example #1
0
        /// <summary>
        /// Coerces an integer into a natural.
        /// </summary>
        public Z3Expr MkNegCoercion(Z3IntExpr i)
        {
            var zero = Context.MkInt(0);
            var one  = Context.MkInt(1);
            var two  = Context.MkInt(2);

            var oddCase = BoxingFun.Apply(i.Add(Context, one).Div(Context, two));

            var coercion = i.IsEven(Context).Ite(
                Context,
                BoxingFun.Apply(i.Neg(Context).Div(Context, two)),
                oddCase);

            return(coercion);
        }
Example #2
0
        /// <summary>
        /// Coerces an integer into a pos integer.
        /// </summary>
        public Z3Expr MkPosCoercion(Z3IntExpr i)
        {
            var zero = Context.MkInt(0);
            var one  = Context.MkInt(1);
            var two  = Context.MkInt(2);

            var oddCase = BoxingFun.Apply(one.Sub(Context, i).Div(Context, two));

            var coercion = i.IsEven(Context).Ite(
                Context,
                BoxingFun.Apply(i.Div(Context, two)),
                oddCase);

            coercion = i.Eq(Context, one).Ite(
                Context,
                BoxingFun.Apply(zero),
                coercion);
            return(coercion);
        }
Example #3
0
        /// <summary>
        /// Coerces an integer into a natural.
        /// </summary>
        public Z3Expr MkNatCoercion(Z3IntExpr i)
        {
            var zero = Context.MkInt(0);
            var one  = Context.MkInt(1);
            var two  = Context.MkInt(2);

            var evenCase = BoxingFun.Apply(i.Neg(Context).Div(Context, two));

            var coercion = i.IsEven(Context).Not(Context).Ite(
                Context,
                BoxingFun.Apply(i.Add(Context, one).Div(Context, two)),
                evenCase);

            coercion = i.Eq(Context, zero).Ite(
                Context,
                BoxingFun.Apply(zero),
                coercion);
            return(coercion);
        }