//public Z3Point3D GetApproximateNormalized() //{ // Z3Point3D result = this.GetManhattanNormalized(); // result.X = CalcApproximateCoordFromManhattanToEuclidianSystem(result.X, result.Y, result.Z); // result.Y = CalcApproximateCoordFromManhattanToEuclidianSystem(result.Y, result.X, result.Z); // result.Z = CalcApproximateCoordFromManhattanToEuclidianSystem(result.Z, result.Y, result.X); // return result; //} public ArithExpr Norm() { ArithExpr result = Z3Math.Max( Z3Math.Abs(CalcApproximateCoordFromManhattanToEuclidianSystem(this.X, this.Y, this.Z)), Z3Math.Abs(CalcApproximateCoordFromManhattanToEuclidianSystem(this.Y, this.X, this.Z)), Z3Math.Abs(CalcApproximateCoordFromManhattanToEuclidianSystem(this.Z, this.Y, this.X))); return(result); }
public static void Run() { Z3Point3D constPoint = Z3Point3D.MkZ3Const("const"); // ("const X", "const Y", "const Z") Z3Point3D normalized = new Z3Point3D(); ArithExpr higherCoord = Z3Math.Max( Z3Math.Max( Z3Math.Abs(constPoint.X), Z3Math.Abs(constPoint.Y)), Z3Math.Abs(constPoint.Z)); normalized.X = Z3.Context.MkDiv(constPoint.X, constPoint.Y); normalized.Y = Z3Math.One;//Z3.Context.MkDiv(constPoint.Y, higherCoord); normalized.Z = Z3.Context.MkDiv(constPoint.Z, constPoint.Y); normalized.X = CalcApproximateCoordFromManhattanToEuclidianSystem(normalized.X, normalized.Y, normalized.Z); normalized.Y = CalcApproximateCoordFromManhattanToEuclidianSystem(normalized.Y, normalized.X, normalized.Z); normalized.Z = CalcApproximateCoordFromManhattanToEuclidianSystem(normalized.Z, normalized.Y, normalized.X); Z3Point3D up = Z3Point3D.DirectionPoint(Direction.Up); // (0, 1, 0) Z3Point3D distVec = normalized - up; ArithExpr distance = Max( Abs(CalcApproximateCoordFromManhattanToEuclidianSystem(distVec.X, distVec.Y, distVec.Z)), Abs(CalcApproximateCoordFromManhattanToEuclidianSystem(distVec.Y, distVec.X, distVec.Z)), Abs(CalcApproximateCoordFromManhattanToEuclidianSystem(distVec.Z, distVec.Y, distVec.X))); BoolExpr expr = Z3.Context.MkLt(distance, Z3.Context.MkReal(1, 2)); Solver solver = Z3.Context.MkSolver(); solver.Assert(expr); Status status = solver.Check(); Statistics stats = solver.Statistics; switch (status) { case Status.UNKNOWN: Console.WriteLine("Solver check for witness returned Status.UNKNOWN because: " + solver.ReasonUnknown); throw new ArgumentException("Test Failed Expception"); case Status.UNSATISFIABLE: Console.WriteLine("There is no valid witness for " + expr); throw new ArgumentException("Test Failed Expception"); case Status.SATISFIABLE: Console.WriteLine("OK, model: " + solver.Model); break; } }
public Z3Point3D GetManhattanNormalized() { Z3Point3D result = new Z3Point3D(); ArithExpr higherCoord = Z3Math.Max( Z3Math.Max( Z3Math.Abs(this.X), Z3Math.Abs(this.Y)), Z3Math.Abs(this.Z)); result.X = Z3Math.Div(this.X, higherCoord); result.Y = Z3Math.Div(this.Y, higherCoord); result.Z = Z3Math.Div(this.Z, higherCoord); return(result); }
public ArithExpr CalcApproximateDistance(Z3Point3D that) { // Manhattan distance vector Z3Point3D distVec = this.GrabDistancePoint3D(that); //ArithExpr result = // Z3Math.Add( // Z3Math.Abs(CalcApproximateCoordFromManhattanToEuclidianSystem(distVec.X, distVec.Y, distVec.Z)), // Z3Math.Abs(CalcApproximateCoordFromManhattanToEuclidianSystem(distVec.Y, distVec.X, distVec.Z)), // Z3Math.Abs(CalcApproximateCoordFromManhattanToEuclidianSystem(distVec.Z, distVec.Y, distVec.X))); ArithExpr result = Z3Math.Max( Z3Math.Abs(distVec.X), Z3Math.Abs(distVec.Y), Z3Math.Abs(distVec.Z)); return(result); }
ArithExpr CalcApproximateCoordFromManhattanToEuclidianSystem( ArithExpr firstCoord, ArithExpr secondCoord, ArithExpr thirdCoord) { // Work only with values length // Values sign will be assigned again in the end ArithExpr firstCoordLength = Z3Math.Abs(firstCoord); ArithExpr secondCoordLength = Z3Math.Abs(secondCoord); ArithExpr thirdCoordLength = Z3Math.Abs(thirdCoord); // The all common length will be weighted by this // This way for example a (1, 1, 1) vector will become // A (0.57, 0.57, 0.57) with norm near to 1 //ArithExpr sqrt1div3 = Z3Math.Real(0.57735026918962576450914878050196); ArithExpr sqrt1div3 = Z3Math.Real(0.577); // The remaining common length will be weighted by this // This way for example a (1, 1, 0) vector will become // A (0.7, 0.7, 0.7) with norm near to 1 //ArithExpr sin45 = Z3Math.Real(0.70710678118654752440084436210485) ArithExpr sin45 = Z3Math.Real(0.707); // Calc common length between x, y, z ArithExpr allCommonLength = Z3Math.Min( firstCoordLength, secondCoordLength, thirdCoordLength); // Calc the common length between the target coord (firstCoord) // and the higher coord between the second and third coords ArithExpr lastTwoCommonLength = Z3Math.Max( Z3Math.Min(secondCoordLength, firstCoordLength), Z3Math.Min(thirdCoordLength, firstCoordLength)); // Calc exclusevely common length with the remaining coordinate ArithExpr lastTwoExclusiveCommonLength = Z3Math.Sub( lastTwoCommonLength, allCommonLength); // Calc remaining length ArithExpr especificLength = Z3Math.Sub(firstCoordLength, Z3Math.Add(lastTwoExclusiveCommonLength, allCommonLength)); // Calc weighted lengths ArithExpr weigthedLength1 = Z3Math.Mul(lastTwoExclusiveCommonLength, sin45); ArithExpr weigthedLength2 = Z3Math.Mul(allCommonLength, sqrt1div3); // Calc weighted result length ArithExpr resultLength = Z3Math.Add( especificLength, weigthedLength1, weigthedLength2); // The transform doesn't change the sign of the coordinate // Recover it from original data Expr result = Z3.Context.MkITE( Z3.Context.MkGe(firstCoord, Z3Math.Zero), resultLength, Z3Math.Neg(resultLength)); return(result as ArithExpr); }
public static ArithExpr Max(ArithExpr expr1, ArithExpr expr2, ArithExpr expr3) { return(Z3Math.Max(Z3Math.Max(expr1, expr2), expr3)); }