public List <Step> Solve(string raw, Expression e) { sequence = Utils.Sequences.ParseSequence(raw); Expression seconddifference = Utils.Sequences.GetDifference(Utils.Sequences.GetDifference(sequence)).Last(); List <List <Expression> > branches = new List <List <Expression> >(); branches.Add(sequence); branches.Add(Utils.Sequences.GetDifference(sequence)); branches.Add(Utils.Sequences.GetDifference(Utils.Sequences.GetDifference(sequence))); StepData.BranchData bd = new StepData.BranchData(branches); steps.Add(new Step(seconddifference, "get the second difference (" + Infix.Print(seconddifference) + ")", new StepData.BranchData(branches))); t_n = t_n * t_n; steps.Add(new Step(t_n, "must be n^2 in quadratic sequence", t_n)); t_n = t_n * ((seconddifference / 2)); steps.Add(new Step(t_n, "Half the second difference and multiply n^2 with it", t_n)); // Console.WriteLine(Infix.Print(FindOffset(1))); t_n += FindOffset(1); steps.Add(new Step(FindOffset(1), "work out the offset with our current expression and the given sequence", FindOffset(1))); steps.Add(new Step(t_n, "add the offset to our expression", t_n)); int na = 1; StringBuilder sb = new StringBuilder(); while (na != 10) { sb.Append(Infix.Print(Utils.Sequences.GetValueInSequence(t_n, t_n, na)) + ", "); na++; } steps.Add(new Step(null, "Double check: " + sb.ToString())); steps.Add(new Step(t_n, "final answer", t_n)); return(steps); }
public List <Step> Solve(string raw, Expression exp) { try { // Expression e = new Expression(); // e += exp; sequence = MATH2.Utils.Sequences.ParseSequence(raw); // steps.Add(new Step(null, raw + " - start off with the sequence",new StepData.LaTeXData(raw),StepData.DataType.LaTeX)); // Console.WriteLine("First difference:"); Expression firstdif = S.GetDifference(sequence)[S.GetDifference(sequence).Count - 1]; List <List <Expression> > branches = new List <List <Expression> >(); branches.Add(sequence); branches.Add(S.GetDifference(sequence)); // (80*x)-((19*x*y)-((-80+(81*x*y)))+((1/2)*(n*n)))*(13*y*y)+(4*x) steps.Add(new Step(firstdif, "find the first difference", new StepData.BranchData(branches))); //Console.WriteLine(Infix.Print(firstdif)); t_n = t_n * firstdif; steps.Add(new Step(t_n, "n must be multiple of first difference", t_n)); //substitute(thing,thingwith,raw); // Console.WriteLine("Equation so far: " + Infix.Print(t_n)); // Console.WriteLine("offset: " + Infix.Print(FindOffset())); steps.Add(new Step(FindOffset(), "subtract and calculate offset", FindOffset())); t_n = t_n + FindOffset(); steps.Add(new Step(t_n, "add that offset to the t_n expression", t_n)); //steps.Add(new Step(t_n, "boom, we now have a full expression for n in a linear sequence")); // Console.WriteLine("Answer: " + Infix.Print(t_n)); // Console.Write("Sequence as calculated: "); int na = 1; StringBuilder sb = new StringBuilder(); while (na != 10) { sb.Append(Infix.Print(S.GetValueInSequence(t_n, t_n, na)) + ", "); na++; } steps.Add(new Step(null, "Double check: " + sb.ToString())); steps.Add(new Step(t_n, "")); // Console.Write(Environment.NewLine); // Console.ReadKey(); // Console.WriteLine("Steps"); //foreach (var item in steps) { // Console.WriteLine(item); } return(steps); } catch (Exception e) { Console.WriteLine("BANANA Error " + e.Message + ":"); Console.WriteLine(e); Console.WriteLine(e.InnerException); return(null); } }
public string String(object o) { if (o as Expression == null) { return(o.ToString()); } else { return(Infix.Print(o as Expression)); } }
private void PaintBranch(List <Expression> branch, Point point, int spreadx, PaintEventArgs e) { List <Point> topstemp = new List <Point>(); List <Point> bottomstemp = new List <Point>(); foreach (var item in branch) { e.Graphics.DrawString(Infix.Print(item), Font, new SolidBrush(this.ForeColor), point); topstemp.Add(new Point(point.X, point.Y - (charspace + Font.Height / 3))); // Console.Write(new Point(point.X, point.Y + charspace)); bottomstemp.Add(new Point(point.X, point.Y + (charspace + Font.Height / 3))); //Console.WriteLine(); //Console.Write(new Point(point.X, point.Y - charspace)); point.X += spreadx; } tops.Add(topstemp); bottoms.Add(bottomstemp); }
/// <summary> /// </summary> /// <param name="x">Delta</param> /// <param name="y">Base 0</param> /// <param name="start">The start of x</param> /// <returns></returns> public Expression Solve(int x, int start) { Console.WriteLine(); var value = 0.P(); var str = "SUM "; for (var i = 0; i <= Rows; i++) { var part = Part(i, x, start); str += Infix.Print(part) + " "; value += part; } str += "= " + Infix.Print(value); str.Print(); value.Print(); return(value); }
public static void Print(this Expression obj) { Infix.Print(obj).Print(); }
/// <summary> /// Returns this expression in infix notation. /// </summary> /// <returns></returns> public string AsInfix() { return(Infix.Print(infix)); }