// This comparison returns true if log is within standard difference // of otherquantity.log. public bool IsEquivalent(CQuantity otherQuantity) { return(_number.IsEquivalent(otherQuantity.Number)); }
// Substitute every term of each expression to form potential new expressions public void CalculateSubstitution(int intMaxFactors, bool bFirstPass) { int intLimit = _expressionList.Count; double dblLogThis = this.Log; CExpressionList thisExpressionList; // Integers are never substituted. if (!this._isInteger) { // On first pass initialize from the established expression list. // On subsequent passes build on previous candidate list. if (bFirstPass) { thisExpressionList = new CExpressionList(_expressionList); _candidateExpressionList = new CExpressionList(_expressionList); } else { thisExpressionList = new CExpressionList(_candidateExpressionList); } // Limit this to only the expressions that are already in the list. intLimit = thisExpressionList.Count; // for each expression in this quantity's expression list for (int i = 0; i < intLimit; ++i) { CExpression baseExpression = thisExpressionList[i]; CNumber baseNumber = new CNumber(baseExpression.Log, false); int intNumeratorLimit = baseExpression.Numerator.Count; int intDenominatorLimit = baseExpression.Denominator.Count; // for each factor in the numerator for (int intFactorIndex = 0; intFactorIndex < intNumeratorLimit; ++intFactorIndex) { CFactor baseFactor = baseExpression.Numerator[intFactorIndex]; CQuantity baseQuantity = new CQuantity(baseFactor.Qty); // Integers are never substituted. // Computational intermediates are never substituted. They are expanded on printout. if (!baseQuantity._isInteger /* && !baseQuantity._isComputational*/) { // for each expression associated with the numerator factor for (int k = 0; k < baseQuantity.ExpressionList.Count; ++k) { CExpression insertExpression = new CExpression(baseQuantity.ExpressionList[k]); if (!insertExpression.ContainsSymbol(this.Symbol)) { CExpression newExpression = new CExpression(baseExpression); newExpression.SubstituteIntoNumerator(intFactorIndex, insertExpression); CNumber newNumber = new CNumber(newExpression.Log, false); if (!baseNumber.IsEquivalent(newNumber)) { // !!! error double dblLogTest = newExpression.Log; // testing only } newExpression.Normalize(); if (newExpression.SymbolCount <= intMaxFactors) { _candidateExpressionList.Add(newExpression); } } } } } // for each factor in the denominator for (int intFactorIndex = 0; intFactorIndex < intDenominatorLimit; ++intFactorIndex) { CFactor baseFactor = baseExpression.Denominator[intFactorIndex]; CQuantity baseQuantity = new CQuantity(baseFactor.Qty); // Integers are never substituted. // Computational intermediates are never substituted. They are expanded on printout. if (!baseQuantity._isInteger /* && !baseQuantity._isComputational*/) { for (int k = 0; k < baseQuantity.ExpressionList.Count; ++k) { // for each expression associated with the denominator factor CExpression insertExpression = new CExpression(baseQuantity.ExpressionList[k]); if (!insertExpression.ContainsSymbol(this.Symbol)) { CExpression newExpression = new CExpression(baseExpression); newExpression.SubstituteIntoDenominator(intFactorIndex, insertExpression); CNumber newNumber = new CNumber(newExpression.Log, false); if (!baseNumber.IsEquivalent(newNumber)) { // !!! error double dblLogTest = newExpression.Log; // testing only } newExpression.Normalize(); if (newExpression.SymbolCount <= intMaxFactors) { _candidateExpressionList.Add(newExpression); } } } } } _candidateExpressionList.SuppressDupes(); _candidateExpressionList.SuppressTautology(this); } GC.Collect(); } }