public bool SetEquals(ExprCollection <T> other) { //new HashSet<T>().Set; if (Count != other.Count) { return(false); } var pQuery1 = this.OrderBy(e => e); var pQuery2 = other.OrderBy(e => e); var pEqual = pQuery1.SequenceEqual(pQuery2); return(pEqual); //var pQuery1 = this.OrderBy(e => e).GetEnumerator(); //var pQuery2 = other.OrderBy(e => e).GetEnumerator(); //var hasNext = pQuery1.MoveNext() && pQuery2.MoveNext(); //while (pQuery1.MoveNext() && pQuery2.MoveNext()) //{ // var pCmp = pQuery1.Current.CompareTo(pQuery2.Current); // if (pCmp != 0) // return false; //} //return true; }
public TermNumericalExpr SimplyGroupPow() { var exprs = new ExprCollection <NumericalExpr>(Exprs); var pDone = false; for (var i = 0; i < exprs.Count; i++) { for (var j = i + 1; j < exprs.Count;) { var e1 = exprs[i]; var _base = e1.GetPowBase(); if (_base is NumericalExpr n1) { var e2 = exprs[j]; var n2 = e2.GetPowBase(); if (n1 == n2) { var exp1 = e1.GetPowExp(); if (exp1 != null) { var exp2 = e2.GetPowExp(); if (exp2 != null) { var nexp = (exp1 + exp2).SimplySumNumericals(); if (nexp != null) { exprs[i] = MakePow(n1, nexp); pDone = true; exprs.RemoveAt(j); continue; } } } } j++; } } } if (!pDone) { return(null); } return(new TermNumericalExpr(Sign, exprs)); }
public override NumericalExpr SimplySumNumericals() { var exprs = new ExprCollection <NumericalExpr>(Exprs); var pDone = false; for (var i = 0; i < exprs.Count; i++) { var e1 = SimplyOrExpr(e => e.SimplySumNumericals(), exprs[i]); var num1 = e1.SimplyToInteger(); if (num1 != null) { var pDone1 = false; for (var j = i + 1; j < exprs.Count;) { var e2 = SimplyOrExpr(e => e.SimplySumNumericals(), exprs[j]); var num2 = e2.SimplyToInteger(); if (num2 != null) { num1 += num2; pDone = pDone1 = true; exprs.RemoveAt(j); continue; } j++; } if (pDone1) { exprs[i] = MakeNumber(num1); } } } return ((!pDone) ? null : (exprs.Count == 1) ? exprs.First() : MakeSum(exprs)); }
public int SetCompareTo(ExprCollection <T> other) { var pQuery1 = this.OrderBy(e => e).GetEnumerator(); var pQuery2 = other.OrderBy(e => e).GetEnumerator(); var hasNext1 = pQuery1.MoveNext(); var hasNext2 = pQuery2.MoveNext(); while (hasNext1 && hasNext2) { var pCmp = pQuery1.Current.CompareTo(pQuery2.Current); if (pCmp == 0) { hasNext1 = pQuery1.MoveNext(); hasNext2 = pQuery2.MoveNext(); } else { return(pCmp); } } return((!hasNext1 && !hasNext2) ? 0 : (!hasNext1) ? -1 : 1); }
public CalcResult IFactors(ECalcOptions options, CancellationToken cancelToken) { var ri = IFactorsResult(cancelToken); if (ri == null) { return(null); } var exprs = new ExprCollection(); var e1 = MakeTerm(false, ri.Select(q => q.i)); exprs.Add(this); exprs.Add(e1); var e2 = e1.SimplyGroupPow(); if (e2 != null) { exprs.Add(e2); } var r = new CalcResult { Result = exprs.Last() }; if (options.HasFlag(ECalcOptions.Explain)) { var e = MakeSimplies(exprs); r.Explain = IFactorsExplain(e, ri); } return(r); }
public SimplyExprs(ExprCollection exprs) : base(EExprTypeP.SimplyExprs) { Exprs = exprs; }
public TermNumericalExpr(bool sign, ExprCollection <NumericalExpr> exprs) : base(EExprTypeS.Term) { Sign = sign; Exprs = exprs; }
public SumNumericalExpr(ExprCollection <NumericalExpr> exprs) : base(EExprTypeS.Sum) { Exprs = exprs; }