3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 13:28:47 +00:00

overloading support for C# expressions

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2016-04-23 22:03:27 -07:00
parent 662e43d264
commit 643a87cb5b
2 changed files with 60 additions and 163 deletions

View file

@ -41,231 +41,130 @@ namespace Microsoft.Z3
#region Operators #region Operators
private static ArithExpr MkNum(ArithExpr e, int i) private static ArithExpr MkNum(ArithExpr e, int i) => (ArithExpr)e.Context.MkNumeral(i, e.Context.MkIntSort());
{
return (ArithExpr)e.Context.MkNumeral(i, e.Context.MkIntSort());
}
private static ArithExpr MkNum(ArithExpr e, double d) private static ArithExpr MkNum(ArithExpr e, double d) => (ArithExpr)e.Context.MkNumeral(d.ToString(), e.Context.MkRealSort());
{
return (ArithExpr)e.Context.MkNumeral(d.ToString(), e.Context.MkRealSort());
}
/// <summary> Operator overloading for arithmetical divsion operator (over reals) </summary> /// <summary> Operator overloading for arithmetical divsion operator (over reals) </summary>
public static ArithExpr operator /(ArithExpr a, ArithExpr b) public static ArithExpr operator /(ArithExpr a, ArithExpr b) => a.Context.MkDiv(a, b);
{
return a.Context.MkDiv(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(ArithExpr a, ArithExpr b) public static ArithExpr operator /(ArithExpr a, int b) => a / MkNum(a, b);
{
return a.Context.MkSub(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(ArithExpr a, int b) public static ArithExpr operator /(ArithExpr a, double b) => a / MkNum(a, b);
{
return a.Context.MkSub(a, MkNum(a, b));
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(ArithExpr a, double b) public static ArithExpr operator /(int a, ArithExpr b) => MkNum(b, a) / b;
{
return a.Context.MkSub(a, MkNum(a, b));
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(int a, ArithExpr b) public static ArithExpr operator /(double a, ArithExpr b) => MkNum(b, a) / b;
{
return b.Context.MkSub(MkNum(b, a), b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(double a, ArithExpr b) public static ArithExpr operator -(ArithExpr a, ArithExpr b) => a.Context.MkSub(a, b);
{
return b.Context.MkSub(MkNum(b, a), b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(ArithExpr a, ArithExpr b) public static ArithExpr operator -(ArithExpr a, int b) => a - MkNum(a, b);
{
return a.Context.MkAdd(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(ArithExpr a, int b) public static ArithExpr operator -(ArithExpr a, double b) => a - MkNum(a, b);
{
return a.Context.MkAdd(a, MkNum(a, b));
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(ArithExpr a, double b) public static ArithExpr operator -(int a, ArithExpr b) => MkNum(b, a) - b;
{
return a.Context.MkAdd(a, MkNum(a, b));
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(int a, ArithExpr b) public static ArithExpr operator -(double a, ArithExpr b) => MkNum(b, a) - b;
{
return b.Context.MkAdd(MkNum(b, a), b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(double a, ArithExpr b) public static ArithExpr operator +(ArithExpr a, ArithExpr b) => a.Context.MkAdd(a, b);
{
return b.Context.MkAdd(MkNum(b, a), b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(ArithExpr a, ArithExpr b) public static ArithExpr operator +(ArithExpr a, int b) => a + MkNum(a, b);
{
return a.Context.MkMul(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(ArithExpr a, int b) public static ArithExpr operator +(ArithExpr a, double b) => a + MkNum(a, b);
{
return a.Context.MkMul(a, MkNum(a, b)); /// <summary> Operator overloading for arithmetical operator </summary>
} public static ArithExpr operator +(int a, ArithExpr b) => MkNum(b, a) + b;
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(ArithExpr a, double b) public static ArithExpr operator +(double a, ArithExpr b) => MkNum(b, a) + b;
{
return a.Context.MkMul(a, MkNum(a, b));
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(int a, ArithExpr b) public static ArithExpr operator *(ArithExpr a, ArithExpr b) => a.Context.MkMul(a, b);
{
return b.Context.MkMul(MkNum(b, a), b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(double a, ArithExpr b) public static ArithExpr operator *(ArithExpr a, int b) => a * MkNum(a, b);
{
return b.Context.MkMul(MkNum(b, a), b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(ArithExpr a, ArithExpr b) public static ArithExpr operator *(ArithExpr a, double b) => a * MkNum(a, b);
{
return a.Context.MkLe(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(ArithExpr a, int b) public static ArithExpr operator *(int a, ArithExpr b) => MkNum(b, a) * b;
{
return a <= MkNum(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(ArithExpr a, double b) public static ArithExpr operator *(double a, ArithExpr b) => MkNum(b, a) * b;
{
return a <= MkNum(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(int a, ArithExpr b) public static BoolExpr operator <=(ArithExpr a, ArithExpr b) => a.Context.MkLe(a, b);
{
return MkNum(b, a) <= b;
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(double a, ArithExpr b) public static BoolExpr operator <=(ArithExpr a, int b) => a <= MkNum(a, b);
{
return MkNum(b, a) <= b;
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(ArithExpr a, ArithExpr b) public static BoolExpr operator <=(ArithExpr a, double b) => a <= MkNum(a, b);
{
return a.Context.MkLt(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(ArithExpr a, int b) public static BoolExpr operator <=(int a, ArithExpr b) => MkNum(b, a) <= b;
{
return a < MkNum(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(ArithExpr a, double b) public static BoolExpr operator <=(double a, ArithExpr b) => MkNum(b, a) <= b;
{
return a < MkNum(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(int a, ArithExpr b) public static BoolExpr operator <(ArithExpr a, ArithExpr b) => a.Context.MkLt(a, b);
{
return MkNum(b, a) < b;
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(double a, ArithExpr b) public static BoolExpr operator <(ArithExpr a, int b) => a < MkNum(a, b);
{
return MkNum(b, a) < b;
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(ArithExpr a, ArithExpr b) public static BoolExpr operator <(ArithExpr a, double b) => a < MkNum(a, b);
{
return a.Context.MkGe(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(ArithExpr a, int b) public static BoolExpr operator <(int a, ArithExpr b) => MkNum(b, a) < b;
{
return a >= MkNum(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(ArithExpr a, double b) public static BoolExpr operator <(double a, ArithExpr b) => MkNum(b, a) < b;
{
return a >= MkNum(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(int a, ArithExpr b) public static BoolExpr operator >(ArithExpr a, ArithExpr b) => a.Context.MkGt(a, b);
{
return MkNum(b, a) >= b;
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(double a, ArithExpr b) public static BoolExpr operator >(ArithExpr a, int b) => a > MkNum(a, b);
{
return MkNum(b, a) >= b;
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(ArithExpr a, ArithExpr b) public static BoolExpr operator >(ArithExpr a, double b) => a > MkNum(a, b);
{
return a.Context.MkGt(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(ArithExpr a, int b) public static BoolExpr operator >(int a, ArithExpr b) => MkNum(b, a) > b;
{
return a > MkNum(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(ArithExpr a, double b) public static BoolExpr operator >(double a, ArithExpr b) => MkNum(b, a) > b;
{
return a > MkNum(a, b);
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(int a, ArithExpr b) public static BoolExpr operator >=(ArithExpr a, ArithExpr b) => a.Context.MkGe(a, b);
{
return MkNum(b, a) > b;
}
/// <summary> Operator overloading for arithmetical operator </summary> /// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(double a, ArithExpr b) public static BoolExpr operator >=(ArithExpr a, int b) => a >= MkNum(a, b);
{
return MkNum(b, a) > b; /// <summary> Operator overloading for arithmetical operator </summary>
} public static BoolExpr operator >=(ArithExpr a, double b) => a >= MkNum(a, b);
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(int a, ArithExpr b) => MkNum(b, a) >= b;
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(double a, ArithExpr b) => MkNum(b, a) >= b;
#endregion #endregion
} }
} }

View file

@ -36,21 +36,19 @@ namespace Microsoft.Z3
#endregion #endregion
#region Operators #region Operators
/// <summary> /// <summary> Disjunction of Boolean expressions </summary>
/// Disjunction of Boolean expressions public static BoolExpr operator|(BoolExpr a, BoolExpr b) => a.Context.MkOr(a, b);
/// </summary>
public static BoolExpr operator|(BoolExpr a, BoolExpr b)
{
return a.Context.MkOr(a, b);
}
/// <summary> /// <summary>
/// Conjunction of Boolean expressions /// Conjunction of Boolean expressions
/// </summary> /// </summary>
public static BoolExpr operator &(BoolExpr a, BoolExpr b) public static BoolExpr operator &(BoolExpr a, BoolExpr b) => a.Context.MkAnd(a, b);
{
return a.Context.MkAnd(a, b); /// <summary> Xor of Boolean expressions </summary>
} public static BoolExpr operator ^(BoolExpr a, BoolExpr b) => a.Context.MkXor(a, b);
/// <summary> Negation </summary>
public static BoolExpr operator !(BoolExpr a) => a.Context.MkNot(a);
#endregion #endregion
} }