예제 #1
0
        private static object InferIntercept(this LineSymbol inputLineSymbol, string label)
        {
            var line = inputLineSymbol.Shape as Line;

            Debug.Assert(line != null);
            if (line.Intercept != null)
            {
                var goal = new EqGoal(new Var(label), line.Intercept);
                goal.Traces.AddRange(inputLineSymbol.Traces);
                TraceInstructionalDesign.FromLineToIntercept(inputLineSymbol, goal);
                return(goal);
            }

            if (inputLineSymbol.CachedSymbols.Count != 0)
            {
                var goalList = new List <object>();
                foreach (var lss in inputLineSymbol.CachedSymbols)
                {
                    var cachedLss = lss as LineSymbol;
                    Debug.Assert(cachedLss != null);
                    var cachedLs = cachedLss.Shape as Line;
                    Debug.Assert(cachedLs != null);
                    var goal = new EqGoal(new Var(label), cachedLs.Intercept);
                    goal.Traces.AddRange(cachedLss.Traces);
                    TraceInstructionalDesign.FromLineToIntercept(cachedLss, goal);
                    goalList.Add(goal);
                }
                return(goalList);
            }

            return(null);
        }
예제 #2
0
        public void TestLine_Unify_Reify_SequenceUncertainty_0()
        {
            var graph  = new RelationGraph();
            var a      = new Var('a');
            var eqGoal = new EqGoal(a, 1); // a=1

            graph.AddNode(eqGoal);

            var line = new Line(1, a, 1.0);
            var ls   = new LineSymbol(line);

            graph.AddNode(ls);

            List <ShapeSymbol> lines = graph.RetrieveShapeSymbols(ShapeType.Line);

            Assert.True(lines.Count == 1);
            var currLine = lines[0] as LineSymbol;

            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 1);
            var cachedLineSymbol = currLine.CachedSymbols.ToList()[0] as LineSymbol;

            Assert.NotNull(cachedLineSymbol);
            var cachedLine = cachedLineSymbol.Shape as Line;

            Assert.NotNull(cachedLine);
            Assert.True(cachedLine.A.Equals(1.0));
            Assert.True(cachedLine.B.Equals(1.0));
            Assert.True(cachedLine.C.Equals(1.0));
        }
예제 #3
0
        /*
         * given m=2, k=3, y=3x+2
         */
        public static void FromSlopeInterceptToLineSlopeIntercept(EqGoal slopeGoal, EqGoal interceptGoal, LineSymbol ls)
        {
            //1. Substitute slope and intercept properties into the line slope-intercept form y=mx+b.
            ////////////////////////////////////////////////////////


            var ts0 = new TraceStep(null, slopeGoal, GeometryScaffold.KC_LineSlopeForm, PlottingRule.PlottingStrategy, PlottingRule.Plot(slopeGoal));
            var ts1 = new TraceStep(null, interceptGoal, GeometryScaffold.KC_LineInterceptForm, PlottingRule.PlottingStrategy, PlottingRule.Plot(interceptGoal));

            ls._innerLoop.Add(ts0);

            var abstractLs  = new Line(ls.Shape.Label, slopeGoal.Lhs, interceptGoal.Lhs);
            var abstractLss = new LineSymbol(abstractLs);
            var internalLs  = new Line(ls.Shape.Label, ls.SymSlope, interceptGoal.Lhs);
            var internalLss = new LineSymbol(internalLs);

            var traceStep1 = new TraceStep(abstractLss, internalLss, SubstitutionRule.SubstituteKC(), SubstitutionRule.SubstitutionStrategy, SubstitutionRule.ApplySubstitute(abstractLss, slopeGoal));

            ls._innerLoop.Add(traceStep1);

            ls._innerLoop.Add(ts1);

            /*
             *          var rule = "Substitute given property to line slope-intercept form.";
             *          var appliedRule1 = string.Format("Substitute slope={0} into y=mx+b", ls.SymSlope);
             *          var appliedRule2= string.Format("Substitute intercept={0} into y=mx+b", ls.SymIntercept);*/
            var traceStep2 = new TraceStep(internalLss, ls, SubstitutionRule.SubstituteKC(), SubstitutionRule.SubstitutionStrategy, SubstitutionRule.ApplySubstitute(internalLss, interceptGoal));

            ls._innerLoop.Add(traceStep2);

            string strategy = "Substitute slope and intercept properties into the line slope-intercept form y = mx + b.";

            ls.GenerateATrace(strategy);
        }
예제 #4
0
        public void TestScenario3_CSP_2()
        {
            /*
             * Input sequence:
             * 1. 2x + y + 1 = 0
             * 2: m = ?
             */
            var graph      = new RelationGraph();
            var line       = new Line(2, 1, 1);
            var lineSymbol = new LineSymbol(line);

            Assert.True(line.InputType == LineType.GeneralForm);
            graph.AddNode(lineSymbol);
            var variable = new Var('m');
            var query    = new Query(variable);
            var qn       = graph.AddNode(query) as QueryNode;

            Assert.True(qn != null);
            Assert.True(qn.InternalNodes.Count == 1);
            var goalNode = qn.InternalNodes[0] as GoalNode;

            Assert.NotNull(goalNode);
            var eqGoal = goalNode.Goal as EqGoal;

            Assert.NotNull(eqGoal);
            Assert.True(eqGoal.Rhs.Equals(-2));
            Assert.True(eqGoal.Lhs.Equals(variable));
            //Output Usage
            Assert.True(query.CachedEntities.Count == 1);
            var cachedGoal = query.CachedEntities.ToList()[0] as EqGoal;

            Assert.NotNull(cachedGoal);
            Assert.True(cachedGoal.Rhs.Equals(-2));
        }
예제 #5
0
        public void TestLine_Unify_Reify_0()
        {
            var graph = new RelationGraph();
            var a = new Var("a");
		    var line = new Line(a, 1, 1.0);
		    var ls = new LineSymbol(line);
		    graph.AddNode(ls);

            List<ShapeSymbol> lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            var lineSymbol = lines[0] as LineSymbol;
            Assert.NotNull(lineSymbol);
            Assert.True(lineSymbol.CachedSymbols.Count == 0);

            var eqGoal = new EqGoal(a, 1); // a=1
            graph.AddNode(eqGoal);

            lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            var currLine = lines[0] as LineSymbol;
            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 1);
            var cachedLineSymbol = currLine.CachedSymbols.ToList()[0] as LineSymbol;
            Assert.NotNull(cachedLineSymbol);
            var cachedLine = cachedLineSymbol.Shape as Line;
            Assert.NotNull(cachedLine);
            Assert.True(cachedLine.A.Equals(1.0));
            Assert.True(cachedLine.B.Equals(1.0));
            Assert.True(cachedLine.C.Equals(1.0));

            graph.DeleteNode(eqGoal);
            lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            currLine = lines[0] as LineSymbol;
            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 0);
            Assert.True(currLine.CachedGoals.Count == 0);

		    var eqGoal2 = new EqGoal(a, 3);
            graph.AddNode(eqGoal2);

            lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            currLine = lines[0] as LineSymbol;
            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 1);
		    Assert.True(currLine.CachedGoals.Count == 1);

            graph.DeleteNode(eqGoal2);

            lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            currLine = lines[0] as LineSymbol;
            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 0);
            Assert.True(currLine.CachedGoals.Count == 0);

          
        }
예제 #6
0
        public void TestLine_Unify_Reify_1()
        {
            var graph = new RelationGraph();

            var a     = new Var('a');
            var point = new Point(2, a);
            var ps    = new PointSymbol(point);

            graph.AddNode(ps);
            var line = new Line(1, a, 1.0);
            var ls   = new LineSymbol(line);

            graph.AddNode(ls);

            List <ShapeSymbol> points = graph.RetrieveShapeSymbols(ShapeType.Point);

            Assert.True(points.Count == 1);
            var pt = points[0] as PointSymbol;

            Assert.NotNull(pt);
            Assert.True(pt.CachedSymbols.Count == 0);

            var eqGoal = new EqGoal(a, 1); // a=1

            graph.AddNode(eqGoal);
            points = graph.RetrieveShapeSymbols(ShapeType.Point);
            Assert.True(points.Count == 1);
            pt = points[0] as PointSymbol;
            Assert.NotNull(pt);
            Assert.True(pt.CachedSymbols.Count == 1);
            var cachedPs = pt.CachedSymbols.ToList()[0] as PointSymbol;

            Assert.NotNull(cachedPs);
            var cachedPt = cachedPs.Shape as Point;

            Assert.NotNull(cachedPt);
            Assert.True(cachedPt.XCoordinate.Equals(2.0));
            Assert.True(cachedPt.YCoordinate.Equals(1.0));

            var lines = graph.RetrieveShapeSymbols(ShapeType.Line);

            Assert.True(lines.Count == 1);
            var currLine = lines[0] as LineSymbol;

            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 1);
            var cachedLineSymbol = currLine.CachedSymbols.ToList()[0] as LineSymbol;

            Assert.NotNull(cachedLineSymbol);
            var cachedLine = cachedLineSymbol.Shape as Line;

            Assert.NotNull(cachedLine);
            Assert.True(cachedLine.A.Equals(1.0));
            Assert.True(cachedLine.B.Equals(1.0));
            Assert.True(cachedLine.C.Equals(1.0));
        }
        public void Test_Relation_Point_Line_2()
        {
            var  pt     = new Point(0, -3);
            var  ps     = new PointSymbol(pt);
            var  line   = new Line(null, 4, 1, 4);
            var  ls     = new LineSymbol(line);
            bool result = ls.UnifyShape(ps);

            Assert.False(result);
        }
예제 #8
0
        public void TestScenario_05_WorkedExample_1()
        {
            var graph = new RelationGraph();
            //general line form input
            var gLine      = new Line(4, 1, 4);
            var lineSymbol = new LineSymbol(gLine);

            Assert.True(gLine.InputType == LineType.GeneralForm);
            graph.AddNode(lineSymbol);
        }
예제 #9
0
        public static void FromPointPointToLine(PointSymbol ps1, PointSymbol ps2, LineSymbol ls)
        {
            var m    = new Var("m");
            var k    = new Var("k");
            var x    = new Var("x");
            var y    = new Var("y");
            var term = new Term(Expression.Multiply, new List <object>()
            {
                m, x
            });
            var term1 = new Term(Expression.Add, new List <object>()
            {
                term, k
            });
            var eqPattern = new Equation(y, term1);

            var term2 = new Term(Expression.Multiply, new List <object>()
            {
                m, ps1.SymXCoordinate
            });
            var term22 = new Term(Expression.Add, new List <object>()
            {
                term2, k
            });
            var eqPattern1 = new Equation(ps1.SymYCoordinate, term22);

            var term3 = new Term(Expression.Multiply, new List <object>()
            {
                m, ps2.SymXCoordinate
            });
            var term33 = new Term(Expression.Add, new List <object>()
            {
                term3, k
            });
            var eqPattern2 = new Equation(ps2.SymYCoordinate, term33);

            string strategy = "Generate a line by substituting two given points into the line slope-intercept form y=mx+k.";

            var ts0 = new TraceStep(eqPattern, eqPattern1, SubstitutionRule.SubstituteKC(), SubstitutionRule.SubstitutionStrategy,
                                    SubstitutionRule.ApplySubstitute(eqPattern, ps1));
            var ts1 = new TraceStep(eqPattern, eqPattern2, SubstitutionRule.SubstituteKC(), SubstitutionRule.SubstitutionStrategy,
                                    SubstitutionRule.ApplySubstitute(eqPattern, ps2));

            string kc = GeometryScaffold.KC_LineSlopeForm;

            var ts2 = new TraceStep(null, ls, kc, "calculate m and k through the above two linear equations.",
                                    "calculate m and k through linear equation and retrieve y=mx+k line form.");

            ls._innerLoop.Add(ts0);
            ls._innerLoop.Add(ts1);
            ls._innerLoop.Add(ts2);

            ls.GenerateATrace(strategy);
        }
예제 #10
0
        //forward solving
        private static EqGoal InferSlope(this LineSymbol inputLineSymbol, string label)
        {
            var line = inputLineSymbol.Shape as Line;

            Debug.Assert(line != null);
            var goal = new EqGoal(new Var(label), line.Slope);

            goal.Traces.AddRange(inputLineSymbol.Traces);
            TraceInstructionalDesign.FromLineToSlope(inputLineSymbol, goal);
            return(goal);
        }
예제 #11
0
        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="inputLineSymbol"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        private static LineSymbol InferGeneralForm(this LineSymbol inputLineSymbol, string label)
        {
            var line = inputLineSymbol.Shape as Line;

            Debug.Assert(line != null);
            var ls = new LineSymbol(line);

            ls.OutputType = LineType.GeneralForm;
            ls.Traces.AddRange(inputLineSymbol.Traces);
            TraceInstructionalDesign.FromOneFormToAnother(inputLineSymbol, ls);
            return(ls);
        }
예제 #12
0
        public void Test_Line_1()
        {
            var line = new Line(3.0, 1.0, 1.0);

            line.Label = "A";
            var    lineSymbol = new LineSymbol(line);
            string str        = lineSymbol.ToString();

            Assert.True(str.Equals("A(3x+y+1=0)"));

            Expr expr = lineSymbol.ToExpr();
        }
예제 #13
0
        /// <summary>
        /// ax+by+c=0 =========> y = -(a/b)x-(c/b)
        /// </summary>
        /// <param name="inputLineSymbol"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        private static LineSymbol InferSlopeInterceptForm(this LineSymbol inputLineSymbol)
        {
            //TODO
            var line = inputLineSymbol.Shape as Line;

            Debug.Assert(line != null);
            var ls = new LineSymbol(line);

            ls.OutputType = LineType.SlopeIntercept;
            ls.Traces.AddRange(inputLineSymbol.Traces);
            TraceInstructionalDesign.FromOneFormToAnother(inputLineSymbol, ls);
            return(ls);
        }
예제 #14
0
        public void test_symbolic_label()
        {
            //ax+2y-1=0
            var    variable   = new Var('a');
            var    line       = new Line(variable, 2, -1);
            var    lineSymbol = new LineSymbol(line);
            string str        = lineSymbol.ToString();

            Assert.True(str.Equals("ax+2y-1=0"));

            line.Label = "M";
            Assert.True(lineSymbol.ToString().Equals("M(ax+2y-1=0)"));
        }
예제 #15
0
        public void Test_SlopeIntercept_2()
        {
            //general form -> slope intercept form
            var    a    = new Var('a');
            double b    = 2.0d;
            double c    = 3.0d;
            var    line = new Line(a, b, c);

            Assert.False(line.Concrete);
            Assert.True(line.InputType == LineType.GeneralForm);

            var ls = new LineSymbol(line);

            Assert.True(ls.ToString().Equals("ax+2y+3=0"));
            ls.OutputType = LineType.SlopeIntercept;
            Assert.True(ls.ToString().Equals("y=(-a)/2x-1.5"));
        }
예제 #16
0
        public void Test_SlopeIntercept_1()
        {
            //general form -> slope intercept form
            double a    = 1.0d;
            double b    = 2.0d;
            double c    = 3.0d;
            var    line = new Line(a, b, c);

            Assert.True(line.Concrete);
            Assert.True(line.InputType == LineType.GeneralForm);

            var ls = new LineSymbol(line);

            Assert.True(ls.ToString().Equals("x+2y+3=0"));
            ls.OutputType = LineType.SlopeIntercept;
            Assert.True(ls.ToString().Equals("y=-0.5x-1.5"));
        }
예제 #17
0
        public void test_symbolic_1()
        {
            //x+2y+3=0
            var    line       = new Line(1, 2, 3);
            var    lineSymbol = new LineSymbol(line);
            string str        = lineSymbol.ToString();

            Assert.True(str.Equals("x+2y+3=0"));

            //-x+2y+3=0
            line       = new Line(-1, 2, 3);
            lineSymbol = new LineSymbol(line);
            str        = lineSymbol.ToString();
            Assert.True(str.Equals("-x+2y+3=0"));

            //x+y+1=0
            line       = new Line(1, 1, 1);
            lineSymbol = new LineSymbol(line);
            str        = lineSymbol.ToString();
            Assert.True(str.Equals("x+y+1=0"));

            //x-y+1=0
            line       = new Line(1, -1, 1);
            lineSymbol = new LineSymbol(line);
            str        = lineSymbol.ToString();
            Assert.True(str.Equals("x-y+1=0"));

            //x-3y-2=0
            line       = new Line(1, -3, -2);
            lineSymbol = new LineSymbol(line);
            str        = lineSymbol.ToString();
            Assert.True(str.Equals("x-3y-2=0"));

            //x=0
            line       = new Line(1, 0, 0);
            lineSymbol = new LineSymbol(line);
            str        = lineSymbol.ToString();
            Assert.True(str.Equals("x=0"));

            //y=0
            line       = new Line(0, 1, 0);
            lineSymbol = new LineSymbol(line);
            str        = lineSymbol.ToString();
            Assert.True(str.Equals("y=0"));
        }
예제 #18
0
        public static void FromOneFormToAnother(LineSymbol source, LineSymbol target)
        {
            if (source.OutputType.Equals(LineType.SlopeIntercept))
            {
                if (target.OutputType.Equals(LineType.GeneralForm))
                {
                    FromLineSlopeIntercetpToLineGeneralForm(target);
                }
            }

            if (source.OutputType.Equals(LineType.GeneralForm))
            {
                if (target.OutputType.Equals(LineType.SlopeIntercept))
                {
                    FromLineGeneralFormToSlopeIntercept(target);
                }
            }
        }
예제 #19
0
        public static void FromOneFormToAnother(LineSymbol source, LineSymbol target)
        {
            if (source.OutputType.Equals(LineType.SlopeIntercept))
            {
                if (target.OutputType.Equals(LineType.GeneralForm))
                {
                    FromLineSlopeIntercetpToLineGeneralForm(target);
                }
            }

            if (source.OutputType.Equals(LineType.GeneralForm))
            {
                if (target.OutputType.Equals(LineType.SlopeIntercept))
                {
                    FromLineGeneralFormToSlopeIntercept(target);
                }
            }
        }
예제 #20
0
        public static void FromLineSlopeIntercetpToLineGeneralForm(LineSymbol ls)
        {
            var line = ls.Shape as Line;

            Debug.Assert(line != null);
            Debug.Assert(ls.OutputType == LineType.GeneralForm);

            string step1metaRule    = "Given the line slope-intercept from y=mx+b, move y term to the right side of equation.";
            string step1AppliedRule = String.Format("Move y to the right side of equation");

            string kc = GeometryScaffold.KC_LinePatternsTransform;

            var    ts       = new TraceStep(ls.SlopeInterceptForm, ls.GeneralForm, kc, step1metaRule, step1AppliedRule);
            string strategy = strategy_si_general;

            ls._innerLoop.Add(ts);
            ls.GenerateATrace(strategy);
        }
예제 #21
0
        public void test_symbolic_1()
        {
            //x+2y+3=0
            var line = new Line(1, 2, 3);
            var lineSymbol = new LineSymbol(line);
            string str = lineSymbol.ToString();
            Assert.True(str.Equals("x+2y+3=0"));

            //-x+2y+3=0
            line = new Line(-1, 2, 3);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("-x+2y+3=0"));

            //x+y+1=0
            line = new Line(1, 1, 1);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("x+y+1=0"));

            //x-y+1=0
            line = new Line(1, -1, 1);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("x-y+1=0"));

            //x-3y-2=0
            line = new Line(1, -3, -2);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("x-3y-2=0"));

            //x=0
            line = new Line(1, 0, 0);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("x=0"));

            //y=0
            line = new Line(0, 1, 0);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("y=0"));
        }
예제 #22
0
        public void test_unreify_1()
        {
            var variable  = new Var('a');
            var variable2 = new Var('b');
            var variable3 = new Var('c');
            var line      = new Line(variable, variable2, variable3);
            var ls        = new LineSymbol(line);
            //a = 2
            var goal = new EqGoal(variable, 2.0);

            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 1);
            Assert.True(ls.CachedGoals.Count == 1);

            ls.UnReify(goal);
            Assert.True(ls.CachedSymbols.Count == 0);
            Assert.True(ls.CachedGoals.Count == 0);
        }
예제 #23
0
        public void test_reify_1()
        {
            /*
             * //ax+by+c=0
             *  b = 1
             *  a = 2
             */
            var variable  = new Var('a');
            var variable2 = new Var('b');
            var variable3 = new Var('c');
            var line      = new Line(variable, variable2, variable3);
            var ls        = new LineSymbol(line);

            //a = 2
            var goal = new EqGoal(variable, 2.0);

            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 1);
            Assert.True(ls.CachedGoals.Count == 1);

            //b = 1
            goal = new EqGoal(variable2, 1);
            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 1);
            Assert.True(ls.CachedGoals.Count == 2);

            //c = -3.2
            goal = new EqGoal(variable3, -3.2);
            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 1);
            Assert.True(ls.CachedGoals.Count == 3);

            //c = 4
            goal = new EqGoal(variable3, 4);
            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 2);
            Assert.True(ls.CachedGoals.Count == 4);
        }
예제 #24
0
        /// <summary>
        /// Trace from Line General Form to Slope-Intercept Form
        /// ax+by+c=0 => y=mx+b
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static void FromLineGeneralFormToSlopeIntercept(LineSymbol ls)
        {
            string strategy = "Given a general form line ax+by+c=0, the slope-intercept form of it is y = -(a/b)x-c/b.";

            var line = ls.Shape as Line;
            Debug.Assert(line != null);

            var newLS = new LineSymbol(line);
            newLS.OutputType = LineType.SlopeIntercept;

            var x = new Var("x");
            var y = new Var("y");
            var xTerm = new Term(Expression.Multiply, new List<object>() { line.A, x });
            var yTerm = new Term(Expression.Multiply, new List<object>() { line.B, y });
            var oldEqLeft = new Term(Expression.Add, new List<object>() { xTerm, yTerm, line.C });
            var oldEq = new Equation(oldEqLeft, 0);

            var invertXTerm = new Term(Expression.Multiply, new List<object>() { -1, xTerm });
            var intertZ = new Term(Expression.Multiply, new List<object>() { -1, line.C });

            var internalRight = new Term(Expression.Add, new List<object>() { invertXTerm, intertZ });
            var internalEq = new Equation(yTerm, internalRight);

            var finalXTerm = new Term(Expression.Multiply, new List<object>() { line.Slope, x });
            var finalRight = new Term(Expression.Add, new List<object>() { finalXTerm, line.Intercept });
            var lastEq = new Equation(yTerm, finalRight);

            string step1metaRule = "Given the line general form ax+by+c=0, move x term and Constant term to the right side of equation.";
            string step1AppliedRule = String.Format("Move {0}x and {1} to right side of equation.", ls.SymA, ls.SymC);

            string kc = EquationsRule.RuleConcept(EquationsRule.EquationRuleType.Transitive);
            var ts0 = new TraceStep(null, internalEq, kc, step1metaRule, step1AppliedRule);
            ls._innerLoop.Add(ts0);

            string appliedRule = string.Format("divide coefficient b in both side of equation.");

            kc = EquationsRule.RuleConcept(EquationsRule.EquationRuleType.Inverse);

            var ts1 = new TraceStep(null, lastEq, kc, AlgebraRule.AlgebraicStrategy, appliedRule);
            ls._innerLoop.Add(ts1);
            ls.GenerateATrace(strategy);
        }
예제 #25
0
        //forward solving
        public static void FromLineToSlope(LineSymbol ls, EqGoal goal)
        {
            //one strategy, one step.
            var line = ls.Shape as Line;

            Debug.Assert(line != null);
            var    lst              = new List <TraceStep>();
            string step1metaRule    = "Given the line slope intercept form y=mx+b, the slope is m.";
            string step1AppliedRule = String.Format("Given line slope-intercept form {0}, the slope is {1}.", ls.ToString(), ls.SymSlope);

            string kc = GeometryScaffold.KC_LineSlopeForm;

            var ts = new TraceStep(ls, goal, kc, step1metaRule, step1AppliedRule);

            lst.Add(ts);
            var strategy = strategy_si_slope;
            var tuple    = new Tuple <object, object>(strategy, lst);

            goal.Traces.Add(tuple);
        }
예제 #26
0
        /// <summary>
        /// construct a line through a point and a goal,
        /// e.g A(1,2) ^ S = 2=> Conjunctive Norm Form
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="goal"></param>
        /// <returns></returns>
        public static LineSymbol Unify(PointSymbol pt, EqGoal goal)
        {
            var variable1 = goal.Lhs as Var;

            Debug.Assert(variable1 != null);

            if (LineAcronym.EqualSlopeLabels(variable1.ToString()))
            {
                double dValue;
                bool   result = LogicSharp.IsDouble(goal.Rhs, out dValue);
                if (result)
                {
                    if (!pt.Shape.Concrete)
                    {
                        return(null);
                    }
                    var line = LineGenerationRule.GenerateLine((Point)pt.Shape, dValue, null);
                    if (pt.Traces.Count != 0)
                    {
                        line.Traces.AddRange(pt.Traces);
                    }
                    if (goal.Traces.Count != 0)
                    {
                        line.Traces.AddRange(goal.Traces);
                    }

                    TraceInstructionalDesign.FromPointSlopeToLine(pt, goal, line);

                    line.OutputType = LineType.SlopeIntercept;
                    return(line);
                }
                else
                {
                    var line = new Line(null); //ghost line
                    var ls   = new LineSymbol(line);
                    ls.OutputType = LineType.SlopeIntercept;
                    return(ls);
                }
            }
            return(null);
        }
예제 #27
0
        public void test_symbolic_2()
        {
            //ax+2y-1=0
            var    variable   = new Var('a');
            var    line       = new Line(variable, 2, -1);
            var    lineSymbol = new LineSymbol(line);
            string str        = lineSymbol.ToString();

            Assert.True(str.Equals("ax+2y-1=0"));

            //x+by+c=0
            var variable2 = new Var('b');
            var variable3 = new Var('c');

            line       = new Line(1, variable2, variable3);
            lineSymbol = new LineSymbol(line);
            str        = lineSymbol.ToString();
            Assert.True(str.Equals("x+by+c=0"));

            //ax=0
            line       = new Line(variable, 0, 0);
            lineSymbol = new LineSymbol(line);
            str        = lineSymbol.ToString();
            Assert.True(str.Equals("ax=0"));

            //by+3=0
            line       = new Line(0, variable2, 3);
            lineSymbol = new LineSymbol(line);
            str        = lineSymbol.ToString();
            Assert.True(str.Equals("by+3=0"));

            //x-by+1=0 => not allowed -> Exception

            /*   var term = new Term(Expression.Multiply,
             *     new Tuple<object, object>(-1, variable2));
             * line = new Line(1, term, 3);
             * lineSymbol = new LineSymbol(line);
             * str = lineSymbol.ToString();
             * Assert.True(str.Equals("x+(-1*b)y+3=0"));*/
        }
예제 #28
0
 /// <summary>
 /// TODO
 /// </summary>
 /// <param name="inputLineSymbol"></param>
 /// <param name="label"></param>
 /// <returns></returns>
 private static LineSymbol InferGeneralForm(this LineSymbol inputLineSymbol, string label)
 {
     var line = inputLineSymbol.Shape as Line;
     Debug.Assert(line != null);
     var ls = new LineSymbol(line);
     ls.OutputType = LineType.GeneralForm;
     ls.Traces.AddRange(inputLineSymbol.Traces);
     TraceInstructionalDesign.FromOneFormToAnother(inputLineSymbol, ls);
     return ls;
 }
예제 #29
0
 public void Test_Relation_Point_Line_2()
 {
     var pt = new Point(0, -3);
     var ps = new PointSymbol(pt);
     var line = new Line(null, 4, 1, 4);
     var ls = new LineSymbol(line);
     bool result = ls.UnifyShape(ps);
     Assert.False(result);
 }
예제 #30
0
        public void test_unreify_1()
        {
            var variable = new Var('a');
            var variable2 = new Var('b');
            var variable3 = new Var('c');
            var line = new Line(variable, variable2, variable3);
            var ls = new LineSymbol(line);
            //a = 2
            var goal = new EqGoal(variable, 2.0);
            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 1);
            Assert.True(ls.CachedGoals.Count == 1);

            ls.UnReify(goal);
            Assert.True(ls.CachedSymbols.Count == 0);
            Assert.True(ls.CachedGoals.Count == 0);
        }
예제 #31
0
        public void Test_SlopeIntercept_1()
        {
            //general form -> slope intercept form
            double a = 1.0d;
            double b = 2.0d;
            double c = 3.0d;
            var line = new Line(a, b, c);

            Assert.True(line.Concrete);
            Assert.True(line.InputType == LineType.GeneralForm);

            var ls = new LineSymbol(line);
            Assert.True(ls.ToString().Equals("x+2y+3=0"));
            ls.OutputType = LineType.SlopeIntercept;
            Assert.True(ls.ToString().Equals("y=-0.5x-1.5"));
        }
예제 #32
0
 public static Expr ToExpr(this LineSymbol ls)
 {
     return(Text.Convert(ls.ToString()));
 }
        private static bool Reify(this LineSymbol line, PointSymbol pt1, PointSymbol pt2)
        {
            //if (!line.RelationStatus) return false;
            line.CachedSymbols.Clear(); //re-compute purpose

            var shape1Lst = new List <PointSymbol>();
            var shape2Lst = new List <PointSymbol>();

            #region Caching Point 1
            if (pt1.Shape.Concrete)
            {
                shape1Lst.Add(pt1);
            }
            else
            {
                foreach (var shapeSymbol in pt1.CachedSymbols.ToList())
                {
                    var ptTemp = shapeSymbol as PointSymbol;
                    Debug.Assert(ptTemp != null);
                    if (ptTemp.Shape.Concrete)
                    {
                        shape1Lst.Add(ptTemp);
                    }
                }
            }
            #endregion

            #region Caching Point 2
            if (pt2.Shape.Concrete)
            {
                shape2Lst.Add(pt2);
            }
            else
            {
                foreach (var shapeSymbol in pt2.CachedSymbols.ToList())
                {
                    var ptTemp = shapeSymbol as PointSymbol;
                    Debug.Assert(ptTemp != null);
                    if (ptTemp.Shape.Concrete)
                    {
                        shape2Lst.Add(ptTemp);
                    }
                }
            }
            #endregion

            #region Generate caching line

            if (shape1Lst.Count == 0 || shape2Lst.Count == 0)
            {
                return(false);
            }
            foreach (var gPt1 in shape1Lst)
            {
                foreach (var gPt2 in shape2Lst)
                {
                    Debug.Assert(gPt1 != null);
                    Debug.Assert(gPt2 != null);
                    var gPoint1 = gPt1.Shape as Point;
                    var gPoint2 = gPt2.Shape as Point;
                    Debug.Assert(gPoint1 != null);
                    Debug.Assert(gPoint2 != null);
                    Debug.Assert(gPoint1.Concrete);
                    Debug.Assert(gPoint2.Concrete);
                    var lineTemp = LineGenerationRule.GenerateLine(gPoint1, gPoint2);
                    if (lineTemp != null)
                    {
                        line.CachedSymbols.Add(lineTemp);
                    }
                }
            }
            #endregion

            return(true);
        }
예제 #34
0
        public void CacheC(object obj, EqGoal goal)
        {
            CachedGoals.Add(new KeyValuePair<object, EqGoal>(LineAcronym.C, goal));

            if (CachedSymbols.Count == 0)
            {
                var line = Shape as Line;
                Debug.Assert(line != null);

                #region generate new object

                var gLine = new Line(line.Label, line.A, line.B, obj);
                var gLineSymbol = new LineSymbol(gLine);
                gLineSymbol.CachedGoals.Add(new KeyValuePair<object, EqGoal>(LineAcronym.C, goal));
                CachedSymbols.Add(gLineSymbol);

                //Transform goal trace
                for (int i = goal.Traces.Count - 1; i >= 0; i--)
                {
                    gLine.Traces.Insert(0, goal.Traces[i]);
                }

                //Substitution trace
                string rule = SubstitutionRule.ApplySubstitute();
                string appliedRule = SubstitutionRule.ApplySubstitute(this, goal);
                string kc = SubstitutionRule.SubstituteKC();

                var ts = new TraceStep(this, gLineSymbol, kc, rule, appliedRule);
                gLine._innerLoop.Add(ts);
                gLine.GenerateATrace(SubstitutionRule.SubstitutionStrategy);
                //gLine.Traces.Insert(0, ts);
                #endregion
            }
            else
            {
                #region Iterate existing point object

                foreach (ShapeSymbol ss in CachedSymbols.ToList())
                {
                    var line = ss.Shape as Line;
                    if (line != null)
                    {
                        var cResult = LogicSharp.Reify(line.C, goal.ToDict());
                        if (!line.C.Equals(cResult))
                        {
                            var gline = new Line(line.Label, line.A, line.B, line.C);
                            var gLineSymbol = new LineSymbol(gline);
                            //substitute
                            line.C = cResult;
                            ss.CachedGoals.Add(new KeyValuePair<object, EqGoal>(LineAcronym.C, goal));

                            //transform goal trace
                            for (int i = goal.Traces.Count - 1; i >= 0; i--)
                            {
                                line.Traces.Insert(0, goal.Traces[i]);
                            }

                            string rule = SubstitutionRule.ApplySubstitute();
                            string appliedRule = SubstitutionRule.ApplySubstitute(gLineSymbol, goal);
                            string kc = SubstitutionRule.SubstituteKC();

                            var ts = new TraceStep(gLineSymbol, ss, kc, rule, appliedRule);
                            //line.Traces.Insert(0, ts);
                            line._innerLoop.Add(ts);
                            line.GenerateATrace(SubstitutionRule.SubstitutionStrategy);
                        }
                        else
                        {
                            //generate
                            var gLine = new Line(line.Label, line.A, line.B, obj);
                            var gLineSymbol = new LineSymbol(gLine);
                            gLineSymbol.CachedGoals.Add(new KeyValuePair<object, EqGoal>(LineAcronym.C, goal));
                            foreach (KeyValuePair<object, EqGoal> pair in ss.CachedGoals)
                            {
                                if (pair.Key.Equals(LineAcronym.A))
                                {
                                    gLineSymbol.CachedGoals.Add(new KeyValuePair<object, EqGoal>(LineAcronym.A, pair.Value));
                                }
                                else if (pair.Key.Equals(LineAcronym.B))
                                {
                                    gLineSymbol.CachedGoals.Add(new KeyValuePair<object, EqGoal>(LineAcronym.B, pair.Value));
                                }
                            }
                            CachedSymbols.Add(gLineSymbol);

                            //substitute
                            //Add traces from line to gLine
                            for (int i = line.Traces.Count - 1; i >= 0; i--)
                            {
                                gLine.Traces.Insert(0, line.Traces[i]);
                            }
                            //transform goal trace
                            for (int i = goal.Traces.Count - 1; i >= 0; i--)
                            {
                                gLine.Traces.Insert(0, goal.Traces[i]);
                            }
                            string rule = SubstitutionRule.ApplySubstitute();
                            string appliedRule = SubstitutionRule.ApplySubstitute(gLineSymbol, goal);
                            string kc = SubstitutionRule.SubstituteKC();

                            var ts = new TraceStep(ss, gLineSymbol, kc, rule, appliedRule);
                            gLine._innerLoop.Add(ts);
                            gLine.GenerateATrace(SubstitutionRule.SubstitutionStrategy);
                            //gLine.Traces.Insert(0, ts);
                        }
                    }
                }
                #endregion
            }
        }
예제 #35
0
 //backward solving
 private static object InferSlope(this LineSymbol inputLineSymbol, double value)
 {
     return(TraceInstructionalDesign.FromLineToSlope(inputLineSymbol, value));
 }
예제 #36
0
        /// <summary>
        /// construct a line through a point and a goal,
        /// e.g A(1,2) ^ S = 2=> Conjunctive Norm Form
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="goal"></param>
        /// <returns></returns>
        public static LineSymbol Unify(PointSymbol pt, EqGoal goal)
        {
            var variable1 = goal.Lhs as Var;
            Debug.Assert(variable1 != null);

            if(LineAcronym.EqualSlopeLabels(variable1.ToString()))
            {
                double dValue;
                bool result = LogicSharp.IsDouble(goal.Rhs, out dValue);
                if (result)
                {
                    if (!pt.Shape.Concrete) return null;
                    var line = LineGenerationRule.GenerateLine((Point)pt.Shape, dValue, null);
                    if (pt.Traces.Count != 0)
                    {
                        line.Traces.AddRange(pt.Traces);
                    }
                    if (goal.Traces.Count != 0)
                    {
                        line.Traces.AddRange(goal.Traces);
                    }

                    TraceInstructionalDesign.FromPointSlopeToLine(pt, goal, line);

                    line.OutputType = LineType.SlopeIntercept;
                    return line;
                }
                else
                {
                    var line = new Line(null); //ghost line
                    var ls = new LineSymbol(line);
                    ls.OutputType = LineType.SlopeIntercept;
                    return ls;
                }
            }
            return null;
        }
예제 #37
0
        public void Test_SlopeIntercept_2()
        {
            //general form -> slope intercept form
            var a = new Var('a');
            double b = 2.0d;
            double c = 3.0d;
            var line = new Line(a, b, c);
            Assert.False(line.Concrete);
            Assert.True(line.InputType == LineType.GeneralForm);

            var ls = new LineSymbol(line);
            Assert.True(ls.ToString().Equals("ax+2y+3=0"));
            ls.OutputType = LineType.SlopeIntercept;
            Assert.True(ls.ToString().Equals("y=(-a)/2x-1.5"));
        }
예제 #38
0
        /// <summary>
        /// construct a line through two goals
        /// e.g  m=2, k=3 => conjunctive norm form
        /// </summary>
        /// <param name="goal1"></param>
        /// <param name="goal2"></param>
        /// <returns></returns>
        public static LineSymbol Unify(EqGoal goal1, EqGoal goal2)
        {
            var variable1 = goal1.Lhs as Var;
            var variable2 = goal2.Lhs as Var;
            Debug.Assert(variable1 != null);
            Debug.Assert(variable2 != null);

            var dict = new Dictionary<string, object>();

            string slopeKey = "slope";
            string interceptKey = "intercept";
            if (LineAcronym.EqualSlopeLabels(variable1.ToString()))
            //if (variable1.ToString().Equals(LineAcronym.Slope1))
            {
                dict.Add(slopeKey, goal1.Rhs);
            }
            if (LineAcronym.EqualInterceptLabels(variable1.ToString()))
            //if (variable1.ToString().Equals(LineAcronym.Intercept1))
            {
                dict.Add(interceptKey, goal1.Rhs);
            }
            if (LineAcronym.EqualSlopeLabels(variable2.ToString()))
            //if (variable2.ToString().Equals(LineAcronym.Slope1))
            {
                if (dict.ContainsKey(slopeKey)) return null;
                dict.Add(slopeKey, goal2.Rhs);
            }
            if(LineAcronym.EqualInterceptLabels(variable2.ToString()))
            //if (variable2.ToString().Equals(LineAcronym.Intercept1))
            {
                if (dict.ContainsKey(interceptKey)) return null;
                dict.Add(interceptKey, goal2.Rhs);
            }

            if (dict.Count == 2 &&
                dict[slopeKey] != null &&
                dict[interceptKey] != null)
            {
                if (LogicSharp.IsNumeric(dict[slopeKey]) &&
                    LogicSharp.IsNumeric(dict[interceptKey]))
                {
                    double dSlope, dIntercept;
                    LogicSharp.IsDouble(dict[slopeKey], out dSlope);
                    LogicSharp.IsDouble(dict[interceptKey], out dIntercept);
                    var line = LineGenerationRule.GenerateLine(dSlope, dIntercept);
                    var ls = new LineSymbol(line) { OutputType = LineType.SlopeIntercept };
                    
                    TraceInstructionalDesign.FromSlopeInterceptToLineSlopeIntercept(goal1, goal2, ls);
                    return ls;
                }
                else
                {
                    //lazy evaluation    
                    //Constraint solving on Graph
                    var line = new Line(null); //ghost line
                    var ls = new LineSymbol(line);
                    ls.OutputType = LineType.SlopeIntercept;
                    return ls;
                }
            }
            return null;
        }
예제 #39
0
        public static void LineSlopeIntercepToGraph(LineSymbol ls)
        {
            string strategy = strategy_graphing;

            //Plotting shapes
            //1. plotting Y-Intercept
            //2. plotting X-Intercept
            //3. plotting the line

            //////////////////////////////////////////////////////////////
            // Step 1:
            var pt = new Point(0, ls.SymIntercept);
            var ptSym = new PointSymbol(pt);

            var ts0 = new TraceStep(null, ptSym, null, PlottingRule.PlottingStrategy, PlottingRule.Plot(ptSym));
            ls._innerLoop.Add(ts0);
            //////////////////////////////////////////////////////////////
            // Step 2:

            var line = ls.Shape as Line;
            Debug.Assert(line != null);

            Equation eq;
            if (line.B == null)
            {
                
            }
            else
            {
                var x = new Var("x");
                //step 2.1
                var term = new Term(Expression.Multiply, new List<object>() { line.Slope, x });
                var term1 = new Term(Expression.Add, new List<object>() { term, line.Intercept });
                eq = new Equation(term1, 0);
                object obj;
                EqGoal gGoal = null;
                bool result = eq.IsEqGoal(out obj);
                if (result)
                {
                    gGoal = obj as EqGoal;
                }
                if (gGoal != null)
                {
                    double dX;
                    LogicSharp.IsDouble(gGoal.Rhs, out dX);
                    var pt1 = new Point(dX, 0);
                    var ptSym1 = new PointSymbol(pt1);
                    var ts1 = new TraceStep(null, ptSym1, null, PlottingRule.PlottingStrategy, PlottingRule.Plot(ptSym1));
                    ls._innerLoop.Add(ts1);
                }
            }

            /////////////////////////////////////////////////////////////////

            const string step1MetaRule = "Given the line slope-intercept form y=mx+b, plot the line by passing points (0,b) and (-b/m,0).";
            string step1AppliedRule = String.Format("Plotting the line passing through (0,{0}) and ({1},0) ", ls.SymIntercept, ls.SymC);
            //var ts = new TraceStep(null, ls.SlopeInterceptForm, step1MetaRule, step1AppliedRule);


            string kc = GeometryScaffold.KC_LineGraphing;

            var ts = new TraceStep(null, ls, kc, step1MetaRule, step1AppliedRule);
            ls._innerLoop.Add(ts);

            //////////////////////////////////////////////////////////////////

            ls.GenerateATrace(strategy);
        }
예제 #40
0
        /// <summary>
        /// construct a line through two points
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="pt2"></param>
        /// <returns></returns>
        public static object Unify(PointSymbol pt1, PointSymbol pt2, EqGoal goal = null)
        {
            //point identify check
            if (pt1.Equals(pt2)) return null;

            //Line build process
            if (pt1.Shape.Concrete && pt2.Shape.Concrete)
            {
                var point1 = pt1.Shape as Point;
                var point2 = pt2.Shape as Point;
               
                Debug.Assert(point1 != null);
                Debug.Assert(point2 != null);

                var winPt1 = new System.Windows.Point((double) point1.XCoordinate, (double) point1.YCoordinate);
                var winPt2 = new System.Windows.Point((double) point2.XCoordinate, (double) point2.YCoordinate);

                var lineSymbol = LineGenerationRule.GenerateLine(point1, point2);

                if (lineSymbol == null) return null;

                var line = lineSymbol.Shape as Line;
                Debug.Assert(line != null);

                line.Rel1 = winPt1;
                line.Rel2 = winPt2;

                TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, lineSymbol);
                return lineSymbol;
            }
            else
            {
                //lazy evaluation    
                //Constraint solving on Graph
                var line = new Line(null); //ghost line
                line.Rel1 = pt1.Shape;
                line.Rel2 = pt2.Shape;
                var ls =  new LineSymbol(line);

                #region Reification Purpose

                if (pt1.Shape.Concrete && !pt2.Shape.Concrete)
                {
                    var point1 = pt1.Shape as Point;
                    if (pt2.CachedSymbols.Count != 0)
                    {
                        foreach (ShapeSymbol ss in pt2.CachedSymbols)
                        {
                            var ps = ss as PointSymbol;
                            Debug.Assert(ps != null);
                            Debug.Assert(ps.Shape.Concrete);
                            var cachePoint = ps.Shape as Point;
                            Debug.Assert(cachePoint != null);
                            var gline = LineGenerationRule.GenerateLine(point1, cachePoint);
                            gline.Traces.AddRange(ps.Traces);
                            TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline);
                            ls.CachedSymbols.Add(gline);
                        }
                    }
                }

                if (!pt1.Shape.Concrete && pt2.Shape.Concrete)
                {
                    var point2 = pt2.Shape as Point;
                    if (pt1.CachedSymbols.Count != 0)
                    {
                        foreach (ShapeSymbol ss in pt1.CachedSymbols)
                        {
                            var ps = ss as PointSymbol;
                            Debug.Assert(ps != null);
                            Debug.Assert(ps.Shape.Concrete);
                            var cachePoint = ps.Shape as Point;
                            Debug.Assert(cachePoint != null);
                            var gline = LineGenerationRule.GenerateLine(cachePoint, point2);
                            gline.Traces.AddRange(ps.Traces);
                            TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline);
                            ls.CachedSymbols.Add(gline);
                        }
                    }
                }

                if (!pt1.Shape.Concrete && !pt2.Shape.Concrete)
                {
                    foreach (ShapeSymbol ss1 in pt1.CachedSymbols)
                    {
                        foreach (ShapeSymbol ss2 in pt2.CachedSymbols)
                        {
                            var ps1 = ss1 as PointSymbol;
                            Debug.Assert(ps1 != null);
                            Debug.Assert(ps1.Shape.Concrete);
                            var cachePoint1 = ps1.Shape as Point;
                            Debug.Assert(cachePoint1 != null);
                            var ps2 = ss2 as PointSymbol;
                            Debug.Assert(ps2 != null);
                            Debug.Assert(ps2.Shape.Concrete);
                            var cachePoint2 = ps2.Shape as Point;
                            Debug.Assert(cachePoint2 != null);
                            var gline = LineGenerationRule.GenerateLine(cachePoint1, cachePoint2);
                            gline.Traces.AddRange(ps1.Traces);
                            gline.Traces.AddRange(ps2.Traces);
                            TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline);
                            ls.CachedSymbols.Add(gline);
                        }
                    }
                }

                #endregion

                if (goal != null)
                {
                    return ls.Unify(goal);
                }

                return ls;
            }
        }
예제 #41
0
        public void TestLine_Unify_Reify_1()
        {
            var graph = new RelationGraph();

            var a = new Var('a');
            var point = new Point(2, a);
            var ps = new PointSymbol(point);
            graph.AddNode(ps);
            var line = new Line(1, a, 1.0);
            var ls = new LineSymbol(line);
            graph.AddNode(ls);

            List<ShapeSymbol> points = graph.RetrieveShapeSymbols(ShapeType.Point);
            Assert.True(points.Count == 1);
            var pt = points[0] as PointSymbol;
            Assert.NotNull(pt);
            Assert.True(pt.CachedSymbols.Count == 0);

            var eqGoal = new EqGoal(a, 1); // a=1
            graph.AddNode(eqGoal);
            points = graph.RetrieveShapeSymbols(ShapeType.Point);
            Assert.True(points.Count == 1);
            pt = points[0] as PointSymbol;
            Assert.NotNull(pt);
            Assert.True(pt.CachedSymbols.Count == 1);
            var cachedPs = pt.CachedSymbols.ToList()[0] as PointSymbol;
            Assert.NotNull(cachedPs);
            var cachedPt = cachedPs.Shape as Point;
            Assert.NotNull(cachedPt);
            Assert.True(cachedPt.XCoordinate.Equals(2.0));
            Assert.True(cachedPt.YCoordinate.Equals(1.0));

            var lines = graph.RetrieveShapeSymbols(ShapeType.Line);
            Assert.True(lines.Count == 1);
            var currLine = lines[0] as LineSymbol;
            Assert.NotNull(currLine);
            Assert.True(currLine.CachedSymbols.Count == 1);
            var cachedLineSymbol = currLine.CachedSymbols.ToList()[0] as LineSymbol;
            Assert.NotNull(cachedLineSymbol);
            var cachedLine = cachedLineSymbol.Shape as Line;
            Assert.NotNull(cachedLine);
            Assert.True(cachedLine.A.Equals(1.0));
            Assert.True(cachedLine.B.Equals(1.0));
            Assert.True(cachedLine.C.Equals(1.0));
        }
예제 #42
0
        public void Test_Line_1()
        {
            var line = new Line(3.0, 1.0, 1.0);
            line.Label = "A";
            var lineSymbol = new LineSymbol(line);
            string str = lineSymbol.ToString();

            Assert.True(str.Equals("A(3x+y+1=0)"));

            Expr expr = lineSymbol.ToExpr();
        }
예제 #43
0
파일: PEG.cs 프로젝트: buptkang/MathCog
        public static bool IsLineRel(this starPadSDK.MathExpr.Expr expr, out LineSymbol ls)
        {
            ls = null;
            var compExpr = expr as CompositeExpr;
            if (compExpr == null) return false;

            if (compExpr.Head.Equals(WellKnownSym.times) &&
                compExpr.Args.Count() == 2)
            {
                var underExpr = compExpr.Args[1] as CompositeExpr;
                if (underExpr == null) return false;
                if (underExpr.Head.Equals(WellKnownSym.divide)
                    && underExpr.Args.Count() == 1)
                {
                    var expr1 = underExpr.Args[0] as CompositeExpr;
                    if (expr1 == null) return false;

                    if (expr1.Head.Equals(WellKnownSym.times) &&
                        expr1.Args.Count() == 2)
                    {
                        object obj1, obj2;
                        var result1 = expr1.Args[0].IsLabel(out obj1);
                        var result2 = expr1.Args[1].IsLabel(out obj2);

                        if (result1 && result2)
                        {
                            var str1 = obj1 as string;
                            var str2 = obj2 as string;
                            Debug.Assert(str1 != null);
                            Debug.Assert(str2 != null);
                            var label = str1 + str2;
                            var line = new Line(label);
                            ls = new LineSymbol(line);
                            return true;
                        }
                        return false;
                    }
                    else
                    {
                        return false;
                    }
                }
                return false;
            }
            return false;
        }
예제 #44
0
        public static void FromPointPointToLine(PointSymbol ps1, PointSymbol ps2, LineSymbol ls)
        {
            var m = new Var("m");
            var k = new Var("k");
            var x = new Var("x");
            var y = new Var("y");
            var term = new Term(Expression.Multiply, new List<object>() { m, x });
            var term1 = new Term(Expression.Add, new List<object>() { term, k });
            var eqPattern = new Equation(y, term1);

            var term2 = new Term(Expression.Multiply, new List<object>() {m, ps1.SymXCoordinate});
            var term22 = new Term(Expression.Add, new List<object>() {term2, k});
            var eqPattern1 = new Equation(ps1.SymYCoordinate, term22);

            var term3 = new Term(Expression.Multiply, new List<object>() {m, ps2.SymXCoordinate});
            var term33 = new Term(Expression.Add, new List<object>() { term3, k });
            var eqPattern2 = new Equation(ps2.SymYCoordinate, term33);

            string strategy = "Generate a line by substituting two given points into the line slope-intercept form y=mx+k.";

            var ts0 = new TraceStep(eqPattern, eqPattern1, SubstitutionRule.SubstituteKC(),SubstitutionRule.SubstitutionStrategy,
                SubstitutionRule.ApplySubstitute(eqPattern, ps1));
            var ts1 = new TraceStep(eqPattern, eqPattern2, SubstitutionRule.SubstituteKC(),SubstitutionRule.SubstitutionStrategy,
                SubstitutionRule.ApplySubstitute(eqPattern, ps2));

            string kc = GeometryScaffold.KC_LineSlopeForm;

            var ts2 = new TraceStep(null, ls, kc, "calculate m and k through the above two linear equations.",
                "calculate m and k through linear equation and retrieve y=mx+k line form.");

            ls._innerLoop.Add(ts0);
            ls._innerLoop.Add(ts1);
            ls._innerLoop.Add(ts2);

            ls.GenerateATrace(strategy);
        }
예제 #45
0
        public void test_symbolic_label()
        {
            //ax+2y-1=0
            var variable = new Var('a');
            var line = new Line(variable, 2, -1);
            var lineSymbol = new LineSymbol(line);
            string str = lineSymbol.ToString();
            Assert.True(str.Equals("ax+2y-1=0"));

            line.Label = "M";
            Assert.True(lineSymbol.ToString().Equals("M(ax+2y-1=0)"));
        }
예제 #46
0
 public void TestScenario_05_WorkedExample_1()
 {
     var graph = new RelationGraph();
     //general line form input
     var gLine = new Line(4, 1, 4);
     var lineSymbol = new LineSymbol(gLine);
     Assert.True(gLine.InputType == LineType.GeneralForm);
     graph.AddNode(lineSymbol);
 }
예제 #47
0
        public static void FromPointSlopeToLine(PointSymbol ps, EqGoal goal, LineSymbol ls)
        {
            string strategy = "Substitute point and slope property into line form.";

            // 1. Substitute slope property into the line slope-intercept form.
            // 2. Calculate the line intercept by substituting the point into line pattern.
            
            //////////////////////////////////////////////////////////////////////

            string strategy1 = "Substitute slope property into the line slope-intercept form.";

            var m = new Var("m");
            var k = new Var("k");
            var x = new Var("x");
            var y = new Var("y");
            var term = new Term(Expression.Multiply, new List<object>() {m, x});
            var term1 = new Term(Expression.Add, new List<object>() {term, k});
            var eqPattern = new Equation(y, term1);

            var term2 = new Term(Expression.Multiply, new List<object>() {goal.Rhs,x});
            var term3 = new Term(Expression.Add, new List<object>() {term2, k});
            var eqInternal1 = new Equation(y, term3);

            var appliedRule1 = SubstitutionRule.ApplySubstitute(eqPattern, goal);

            var ts0 = new TraceStep(eqPattern, eqInternal1, SubstitutionRule.SubstituteKC(), strategy1, appliedRule1);
            ls._innerLoop.Add(ts0);

            //////////////////////////////////////////////////////////////////////

            var point = ps.Shape as Point;
            Debug.Assert(point != null);

            string strategy2 = "Calculate the line intercept by substituting the point into line pattern.";

            var term4 = new Term(Expression.Multiply, new List<object>() { goal.Rhs, point.XCoordinate});
            var term5 = new Term(Expression.Add, new List<object>() {term4, k});
            var eqinternal2 = new Equation(point.YCoordinate, term5);

            object obj;
            bool result = eqinternal2.IsEqGoal(out obj);
            var eqGoal = obj as EqGoal;
            Debug.Assert(eqGoal != null);

            var gTuple = eqGoal.Traces[0];
            var gLst = gTuple.Item2 as List<TraceStep>;
            Debug.Assert(gLst != null);
            ls._innerLoop.AddRange(gLst);

            var appliedRule2 = SubstitutionRule.ApplySubstitute(eqInternal1, ps);

            var ts = new TraceStep(eqInternal1, ls, SubstitutionRule.SubstituteKC(), strategy2, appliedRule2);
            ls._innerLoop.Add(ts);
            ls.GenerateATrace(strategy);
        }
예제 #48
0
        //forward solving
        public static void FromLineToIntercept(LineSymbol ls, EqGoal goal)
        {
            var line = ls.Shape as Line;
            Debug.Assert(line != null);
            var lst = new List<TraceStep>();
            string step1metaRule = "Given the line slope intercept form y=mx+K, the y-intercept is K.";
            string step1AppliedRule = String.Format("Given line slope-intercept form {0}, the slope is {1}.", ls.ToString(), ls.SymIntercept);

            string kc = GeometryScaffold.KC_LineInterceptForm;



            var ts = new TraceStep(ls, goal, kc, step1metaRule, step1AppliedRule);




            lst.Add(ts);
            var strategy = strategy_si_intercept;
            var tuple = new Tuple<object, object>(strategy, lst);
            goal.Traces.Add(tuple);
        }
예제 #49
0
        public static bool IsLineEquation(this Equation eq, out LineSymbol ls, bool allowEval = true)
        {
            Debug.Assert(eq != null);
            Debug.Assert(eq.Rhs != null);
            ls = null;

            Line line;
           /* bool matched = SatisfySpecialForm(eq, out line);
            if (matched)
            {
                ls = new LineSymbol(line);
                line.Label = eq.EqLabel;
                if (eq.Traces.Count == 1)
                {
                    var strategy = "Generate a line by manipulating algebraic equation.";
                    var newTrace = new Tuple<object, object>(strategy, eq.Traces[0].Item2);
                    ls.Traces.Add(newTrace);
                    //ls.ImportTrace(eq);
                }
                TraceInstructionalDesign.LineSlopeIntercepToGraph(ls);
                return true;
            }

            matched = SatisfyLineSlopeInterceptForm(eq, out line);
            if (matched)
            {
                ls = new LineSymbol(line);
                line.Label = eq.EqLabel;
                if (eq.Traces.Count == 1)
                {
                    var strategy = "Generate a line by manipulating algebraic equation.";
                    var newTrace = new Tuple<object, object>(strategy, eq.Traces[0].Item2);
                    ls.Traces.Add(newTrace);
                    //ls.ImportTrace(eq);
                }
                TraceInstructionalDesign.LineSlopeIntercepToGraph(ls);
                return true;
            }*/

/*            if (!allowEval)
            {
                matched = SatisfyLineGeneralForm(eq, out line);
                if (matched)
                {
                    ls = new LineSymbol(line);
                    line.Label = eq.EqLabel;
                    return true;
                }
                matched = SatisfyLineSlopeInterceptForm(eq, out line);
                if (matched)
                {
                    ls = new LineSymbol(line);
                    line.Label = eq.EqLabel;
                    return true;
                }
                return false;
            }*/

            object obj;
            bool? result = eq.Eval(out obj, true, true); // without transitive equational rule.
            if (result != null) return false;

            if (eq.CachedEntities.Count != 1) return false;

            var outputEq = eq.CachedEntities.ToList()[0] as Equation;
            if (outputEq == null) return false;

            bool matched = SatisfySpecialForm(outputEq, out line);
            if (matched)
            {
                ls = new LineSymbol(line);
                line.Label = eq.EqLabel;

                if (outputEq.Traces.Count == 1)
                {
                    var strategy = "Generate a line by manipulating algebraic equation.";
                    var newTrace = new Tuple<object, object>(strategy, outputEq.Traces[0].Item2);
                    ls.Traces.Add(newTrace);
                    //ls.ImportTrace(eq);
                }
                TraceInstructionalDesign.LineSlopeIntercepToGraph(ls);
                return true;
            }

            //Equation Semantic Unification
            //general     form of line equation ax+by+c=0
            //point-slope form of line equation y = mx + b

            matched = SatisfyLineGeneralForm(outputEq, out line);
            if (matched)
            {
                ls = new LineSymbol(line);
                line.Label = eq.EqLabel;
                if (outputEq.Traces.Count == 1)
                {
                    var strategy = "Generate a line by manipulating algebraic equation.";
                    var newTrace = new Tuple<object, object>(strategy, outputEq.Traces[0].Item2);
                    ls.Traces.Add(newTrace);
                    //ls.ImportTrace(eq);
                }

                //Instruction Design
                TraceInstructionalDesign.FromLineGeneralFormToSlopeIntercept(ls);
                TraceInstructionalDesign.LineSlopeIntercepToGraph(ls);
               
              /*  List<Tuple<object, object>> trace = eq.CloneTrace();               
                ls.Traces.AddRange(trace);
                List<Tuple<object, object>> lst = ls.Traces.Intersect(trace).ToList();
                if (lst.Count == 0) ls.Traces.AddRange(trace);*/
                return true;
            }


            matched = SatisfyLineSlopeInterceptForm(outputEq, out line);
            if (matched)
            {
                ls = new LineSymbol(line);
                line.Label = eq.EqLabel;
                if (outputEq.Traces.Count == 1)
                {
                    var strategy = "Generate a line by manipulating algebraic equation.";
                    var newTrace = new Tuple<object, object>(strategy, outputEq.Traces[0].Item2);
                    ls.Traces.Add(newTrace);
                    //ls.ImportTrace(eq);
                }
                TraceInstructionalDesign.LineSlopeIntercepToGraph(ls);

               /* List<Tuple<object,object>> trace = eq.CloneTrace();
                ls = new LineSymbol(line);
                line.Label = eq.EqLabel;
                ls.Traces.AddRange(trace);
                List<Tuple<object, object>> lst = ls.Traces.Intersect(trace).ToList();
                if (lst.Count == 0) ls.Traces.AddRange(trace);*/
                return true;
            }
            eq.ClearTrace();
            //eq.CachedEntities.Clear();

            return false;
        }
예제 #50
0
        public void test_reify_1()
        {
            /*
             * //ax+by+c=0
             *  b = 1
             *  a = 2
             */
            var variable = new Var('a');
            var variable2 = new Var('b');
            var variable3 = new Var('c');
            var line = new Line(variable, variable2, variable3);
            var ls = new LineSymbol(line);

            //a = 2
            var goal = new EqGoal(variable, 2.0);
            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 1);
            Assert.True(ls.CachedGoals.Count == 1);

            //b = 1
            goal = new EqGoal(variable2, 1);
            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 1);
            Assert.True(ls.CachedGoals.Count == 2);

            //c = -3.2
            goal = new EqGoal(variable3, -3.2);
            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 1);
            Assert.True(ls.CachedGoals.Count == 3);
            
            //c = 4
            goal = new EqGoal(variable3, 4);
            ls.Reify(goal);
            Assert.False(line.Concrete);
            Assert.True(ls.CachedSymbols.Count == 2);
            Assert.True(ls.CachedGoals.Count == 4);
        }
예제 #51
0
 public void TestScenario3_CSP_2()
 {
     /*
      * Input sequence:
      * 1. 2x + y + 1 = 0
      * 2: m = ?
      */
     var graph = new RelationGraph();
     var line = new Line(2, 1, 1);
     var lineSymbol = new LineSymbol(line);
     Assert.True(line.InputType == LineType.GeneralForm);
     graph.AddNode(lineSymbol);
     var variable = new Var('m');
     var query = new Query(variable);
     var qn = graph.AddNode(query) as QueryNode;
     Assert.True(qn != null);
     Assert.True(qn.InternalNodes.Count == 1);
     var goalNode = qn.InternalNodes[0] as GoalNode;
     Assert.NotNull(goalNode);
     var eqGoal = goalNode.Goal as EqGoal;
     Assert.NotNull(eqGoal);
     Assert.True(eqGoal.Rhs.Equals(-2));
     Assert.True(eqGoal.Lhs.Equals(variable));
     //Output Usage
     Assert.True(query.CachedEntities.Count == 1);
     var cachedGoal = query.CachedEntities.ToList()[0] as EqGoal;
     Assert.NotNull(cachedGoal);
     Assert.True(cachedGoal.Rhs.Equals(-2));
 }
예제 #52
0
 public static bool Unify(this LineSymbol shapeSymbol, object constraint, out object output)
 {
     output = shapeSymbol.Unify(constraint);
     return(output != null);
 }
예제 #53
0
        /*
         * given m=2, k=3, y=3x+2
         */
        public static void FromSlopeInterceptToLineSlopeIntercept(EqGoal slopeGoal, EqGoal interceptGoal, LineSymbol ls)
        {
            //1. Substitute slope and intercept properties into the line slope-intercept form y=mx+b.
            ////////////////////////////////////////////////////////


            var ts0 = new TraceStep(null, slopeGoal, GeometryScaffold.KC_LineSlopeForm, PlottingRule.PlottingStrategy, PlottingRule.Plot(slopeGoal));
            var ts1 = new TraceStep(null, interceptGoal, GeometryScaffold.KC_LineInterceptForm, PlottingRule.PlottingStrategy, PlottingRule.Plot(interceptGoal));
            ls._innerLoop.Add(ts0);

            var abstractLs = new Line(ls.Shape.Label, slopeGoal.Lhs, interceptGoal.Lhs);
            var abstractLss = new LineSymbol(abstractLs);
            var internalLs = new Line(ls.Shape.Label, ls.SymSlope, interceptGoal.Lhs);
            var internalLss = new LineSymbol(internalLs);

            var traceStep1 = new TraceStep(abstractLss, internalLss, SubstitutionRule.SubstituteKC(), SubstitutionRule.SubstitutionStrategy, SubstitutionRule.ApplySubstitute(abstractLss, slopeGoal));
            ls._innerLoop.Add(traceStep1);

            ls._innerLoop.Add(ts1);
            /*
                        var rule = "Substitute given property to line slope-intercept form.";
                        var appliedRule1 = string.Format("Substitute slope={0} into y=mx+b", ls.SymSlope);
                        var appliedRule2= string.Format("Substitute intercept={0} into y=mx+b", ls.SymIntercept);*/
            var traceStep2 = new TraceStep(internalLss, ls, SubstitutionRule.SubstituteKC(), SubstitutionRule.SubstitutionStrategy, SubstitutionRule.ApplySubstitute(internalLss, interceptGoal));
            ls._innerLoop.Add(traceStep2);

            string strategy = "Substitute slope and intercept properties into the line slope-intercept form y = mx + b.";
            ls.GenerateATrace(strategy);
        }
예제 #54
0
        public static object Unify(this LineSymbol ls, object constraint)
        {
            var refObj = constraint as string;
            var eqGoal = constraint as EqGoal;

            if (refObj != null)
            {
                #region forward searching

                if (LineAcronym.EqualSlopeLabels(refObj))
                {
                    return(ls.InferSlope(refObj));
                }

                if (LineAcronym.EqualInterceptLabels(refObj))
                {
                    return(ls.InferIntercept(refObj));
                }

                if (LineAcronym.EqualGeneralFormLabels(refObj))
                {
                    return(ls.InferGeneralForm(refObj));
                }

                if (LineAcronym.EqualSlopeInterceptFormLabels(refObj))
                {
                    return(ls.InferSlopeInterceptForm());
                }

                if (LineAcronym.GraphLine.Equals(refObj))
                {
                    return(ls.InferGraph());
                }
                #endregion
            }

            if (eqGoal != null)
            {
                var    rhs = eqGoal.Rhs;
                double dNum;
                bool   isDouble = LogicSharp.IsDouble(rhs, out dNum);
                if (!isDouble)
                {
                    return(null);
                }

                var lhs = eqGoal.Lhs.ToString();

                if (LineAcronym.EqualSlopeLabels(lhs))
                {
                    var obj    = ls.InferSlope(dNum);
                    var lstObj = obj as List <object>;
                    Debug.Assert(lstObj != null);
                    var eqGoal1 = lstObj[0] as EqGoal;
                    if (eqGoal1 != null)
                    {
                        var newTraces = new List <Tuple <object, object> >();
                        newTraces.AddRange(eqGoal.Traces);
                        newTraces.AddRange(eqGoal1.Traces);
                        eqGoal1.Traces = newTraces;
                    }
                    return(obj);
                }
            }
            return(null);
        }
예제 #55
0
        //backward solving
        public static object FromLineToSlope(LineSymbol ls, double value)
        {
            var line = ls.Shape as Line;
            Debug.Assert(line != null);

            var pt1 = line.Rel1 as Point;
            var pt2 = line.Rel2 as Point;

            if (pt1 == null || pt2 == null) return null;

            //(pt2.Y-pt1.Y)/(pt2.X-pt1.X) = slope

            var yInverse = new Term(Expression.Multiply, new List<object>() { -1, pt1.YCoordinate });
            var term1 = new Term(Expression.Add, new List<object>() { pt2.YCoordinate, yInverse });
            var xInverse = new Term(Expression.Multiply, new List<object>() { -1, pt1.XCoordinate });
            var term2 = new Term(Expression.Add, new List<object>() { pt2.XCoordinate, xInverse });
            var term11 = new Term(Expression.Divide, new List<object>() { term1, term2 });
            var eq = new Equation(term11, value);

            object obj1;
            bool result = eq.IsEqGoal(out obj1);
            if (!result) return null;

            var eqGoal = obj1 as EqGoal;
            if (eqGoal == null) return null;

            var newTraces = new List<Tuple<object, object>>();
            newTraces.Add(SlopeSubstitution(pt1, pt2, value));
            Debug.Assert(eqGoal.Traces.Count == 1);
            var trace = eqGoal.Traces[0];
            var subStrategy = "Derive unknown variable by manipulating the current algebraic expression.";
            var newTrace = new Tuple<object, object>(subStrategy, trace.Item2);
            newTraces.Add(newTrace);
            //newTraces.AddRange(eqGoal.Traces);
            eqGoal.Traces = newTraces;
            return new List<object>() { eqGoal };
        }
예제 #56
0
        /// <summary>
        /// construct a line through two points
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="pt2"></param>
        /// <returns></returns>
        public static object Unify(PointSymbol pt1, PointSymbol pt2, EqGoal goal = null)
        {
            //point identify check
            if (pt1.Equals(pt2))
            {
                return(null);
            }

            //Line build process
            if (pt1.Shape.Concrete && pt2.Shape.Concrete)
            {
                var point1 = pt1.Shape as Point;
                var point2 = pt2.Shape as Point;

                Debug.Assert(point1 != null);
                Debug.Assert(point2 != null);

                var winPt1 = new System.Windows.Point((double)point1.XCoordinate, (double)point1.YCoordinate);
                var winPt2 = new System.Windows.Point((double)point2.XCoordinate, (double)point2.YCoordinate);

                var lineSymbol = LineGenerationRule.GenerateLine(point1, point2);

                if (lineSymbol == null)
                {
                    return(null);
                }

                var line = lineSymbol.Shape as Line;
                Debug.Assert(line != null);

                line.Rel1 = winPt1;
                line.Rel2 = winPt2;

                TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, lineSymbol);
                return(lineSymbol);
            }
            else
            {
                //lazy evaluation
                //Constraint solving on Graph
                var line = new Line(null); //ghost line
                line.Rel1 = pt1.Shape;
                line.Rel2 = pt2.Shape;
                var ls = new LineSymbol(line);

                #region Reification Purpose

                if (pt1.Shape.Concrete && !pt2.Shape.Concrete)
                {
                    var point1 = pt1.Shape as Point;
                    if (pt2.CachedSymbols.Count != 0)
                    {
                        foreach (ShapeSymbol ss in pt2.CachedSymbols)
                        {
                            var ps = ss as PointSymbol;
                            Debug.Assert(ps != null);
                            Debug.Assert(ps.Shape.Concrete);
                            var cachePoint = ps.Shape as Point;
                            Debug.Assert(cachePoint != null);
                            var gline = LineGenerationRule.GenerateLine(point1, cachePoint);
                            gline.Traces.AddRange(ps.Traces);
                            TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline);
                            ls.CachedSymbols.Add(gline);
                        }
                    }
                }

                if (!pt1.Shape.Concrete && pt2.Shape.Concrete)
                {
                    var point2 = pt2.Shape as Point;
                    if (pt1.CachedSymbols.Count != 0)
                    {
                        foreach (ShapeSymbol ss in pt1.CachedSymbols)
                        {
                            var ps = ss as PointSymbol;
                            Debug.Assert(ps != null);
                            Debug.Assert(ps.Shape.Concrete);
                            var cachePoint = ps.Shape as Point;
                            Debug.Assert(cachePoint != null);
                            var gline = LineGenerationRule.GenerateLine(cachePoint, point2);
                            gline.Traces.AddRange(ps.Traces);
                            TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline);
                            ls.CachedSymbols.Add(gline);
                        }
                    }
                }

                if (!pt1.Shape.Concrete && !pt2.Shape.Concrete)
                {
                    foreach (ShapeSymbol ss1 in pt1.CachedSymbols)
                    {
                        foreach (ShapeSymbol ss2 in pt2.CachedSymbols)
                        {
                            var ps1 = ss1 as PointSymbol;
                            Debug.Assert(ps1 != null);
                            Debug.Assert(ps1.Shape.Concrete);
                            var cachePoint1 = ps1.Shape as Point;
                            Debug.Assert(cachePoint1 != null);
                            var ps2 = ss2 as PointSymbol;
                            Debug.Assert(ps2 != null);
                            Debug.Assert(ps2.Shape.Concrete);
                            var cachePoint2 = ps2.Shape as Point;
                            Debug.Assert(cachePoint2 != null);
                            var gline = LineGenerationRule.GenerateLine(cachePoint1, cachePoint2);
                            gline.Traces.AddRange(ps1.Traces);
                            gline.Traces.AddRange(ps2.Traces);
                            TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline);
                            ls.CachedSymbols.Add(gline);
                        }
                    }
                }

                #endregion

                if (goal != null)
                {
                    return(ls.Unify(goal));
                }

                return(ls);
            }
        }
예제 #57
0
        private static LineSymbol InferGraph(this LineSymbol inputLineSymbol)
        {
/*            var ls = inputLineSymbol.InferSlopeInterceptForm();
 *          TraceInstructionalDesign.LineSlopeIntercepToGraph(ls);*/
            return(inputLineSymbol);
        }
예제 #58
0
 /// <summary>
 /// ax+by+c=0 =========> y = -(a/b)x-(c/b)
 /// </summary>
 /// <param name="inputLineSymbol"></param>
 /// <param name="label"></param>
 /// <returns></returns>
 private static LineSymbol InferSlopeInterceptForm(this LineSymbol inputLineSymbol)
 {
     //TODO
     var line = inputLineSymbol.Shape as Line;
     Debug.Assert(line != null);
     var ls = new LineSymbol(line);
     ls.OutputType = LineType.SlopeIntercept;
     ls.Traces.AddRange(inputLineSymbol.Traces);
     TraceInstructionalDesign.FromOneFormToAnother(inputLineSymbol, ls);
     return ls;
 }
예제 #59
0
        public void test_symbolic_2()
        {
            //ax+2y-1=0
            var variable = new Var('a');
            var line = new Line(variable, 2, -1);
            var lineSymbol = new LineSymbol(line);
            string str = lineSymbol.ToString();
            Assert.True(str.Equals("ax+2y-1=0"));

            //x+by+c=0
            var variable2 = new Var('b');
            var variable3 = new Var('c');
            line = new Line(1, variable2, variable3);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("x+by+c=0"));

            //ax=0
            line = new Line(variable, 0, 0);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("ax=0"));

            //by+3=0
            line = new Line(0, variable2, 3);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("by+3=0"));

            //x-by+1=0 => not allowed -> Exception
         /*   var term = new Term(Expression.Multiply,
                new Tuple<object, object>(-1, variable2));
            line = new Line(1, term, 3);
            lineSymbol = new LineSymbol(line);
            str = lineSymbol.ToString();
            Assert.True(str.Equals("x+(-1*b)y+3=0"));*/
        }
예제 #60
0
        public static void FromLineSlopeIntercetpToLineGeneralForm(LineSymbol ls)
        {
            var line = ls.Shape as Line;
            Debug.Assert(line != null);
            Debug.Assert(ls.OutputType == LineType.GeneralForm);

            string step1metaRule = "Given the line slope-intercept from y=mx+b, move y term to the right side of equation.";
            string step1AppliedRule = String.Format("Move y to the right side of equation");

            string kc = GeometryScaffold.KC_LinePatternsTransform;

            var ts = new TraceStep(ls.SlopeInterceptForm, ls.GeneralForm, kc, step1metaRule, step1AppliedRule);
            string strategy = strategy_si_general;
            ls._innerLoop.Add(ts);
            ls.GenerateATrace(strategy);
        }