Exemplo n.º 1
0
 // candidate has been calculated so replace the primary with the candidate.
 public void ApplyCandidateExpressionList()
 {
     _expressionList.Clear();        // Give the garbage collector a heads up.
     _expressionList          = _candidateExpressionList;
     _candidateExpressionList = new CExpressionList();
     GC.Collect();
 }
Exemplo n.º 2
0
 // Construct a deep copy
 public CExpressionList(CExpressionList thatExpressionList) : base()
 {
     for (int i = 0; i < thatExpressionList.Count; ++i)
     {
         CExpression newExpression = new CExpression(thatExpressionList[i]);
         Add(newExpression);
     }
 }
Exemplo n.º 3
0
 // Construct shallow copy for purposes of display and printing
 public CExpressionList(CExpressionList thatExpressionList, bool bNotSense)
     : base()
 {
     for (int i = 0; i < thatExpressionList.Count; ++i)
     {
         CExpression thisExpression = thatExpressionList[i];
         if (!bNotSense || !thisExpression.ContainsSense())
         {
             Add(thisExpression);
         }
     }
 }
Exemplo n.º 4
0
 private void Init(CQuantityList thatQuantityList)
 {
     _intIndex                = -1;
     _isExact                 = false;
     _isComputational         = false;
     _isQED                   = false;
     _isSuppressed            = false;
     _isInteger               = false;
     _uncertainty             = new CNumber(0);
     _lowfence                = new CNumber();
     _highfence               = new CNumber();
     _candidate               = new CNumber();
     _expressionList          = new CExpressionList();
     _candidateExpressionList = new CExpressionList();
     _inverseQty              = null;
     _quantityList            = thatQuantityList;
 }
Exemplo n.º 5
0
 // Deep copy. Used in CQuantity::CalculateSubstitution and in deep copy constructors.
 public CQuantity(CQuantity thatQuantity)
 {
     Init(thatQuantity.QuantityList);
     _symbol          = new CSymbol(thatQuantity._symbol);
     _number          = new CNumber(thatQuantity._number);
     _uncertainty     = new CNumber(thatQuantity._uncertainty);
     _lowfence        = new CNumber(thatQuantity._lowfence);
     _highfence       = new CNumber(thatQuantity._highfence);
     _intIndex        = thatQuantity._intIndex;
     _inverseQty      = thatQuantity.InverseQty;
     _expressionList  = new CExpressionList(thatQuantity._expressionList);
     _isExact         = thatQuantity._isExact;
     _isComputational = thatQuantity._isComputational;
     _isQED           = thatQuantity._isQED;
     _isSuppressed    = thatQuantity._isSuppressed;
     _isInteger       = thatQuantity.IsInteger;
 }
Exemplo n.º 6
0
        public bool WriteExpressions(string strPath, string strLogPath)
        {
            bool         bSuccess      = true;
            StreamWriter swExpressions = null;
            string       strLine;

            try
            {
                swExpressions = new StreamWriter(strPath);
                for (int i = 0; i < this.Count; ++i)
                {
                    CQuantity thisQuantity = this[i].Qty;
                    strLine = thisQuantity.SimpleLabel + "\t= ";
                    CExpressionList thisExpressionList = thisQuantity.ExpressionList;
                    thisExpressionList.SuppressDupes();
                    if (thisExpressionList.Count > 0)
                    {
                        strLine += thisExpressionList[0].ToString();
                    }
                    swExpressions.WriteLine(strLine);
                    for (int j = 1; j < thisExpressionList.Count; ++j)
                    {
                        strLine = "\t= " + thisExpressionList[j].ToString();
                        swExpressions.WriteLine(strLine);
                    }
                }
            }
            catch (Exception e)
            {
                bSuccess = false;
                string strLogEntry = "\r\n Error writing expression file:" + e.Message;
                File.AppendAllText(strLogPath, strLogEntry);
            }
            finally
            {
                if (swExpressions != null)
                {
                    swExpressions.Close();
                }
            }

            return(bSuccess);
        }
Exemplo n.º 7
0
        // 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();
            }
        }