예제 #1
0
        private IHSExplicitVector <HSEdgeState> __qwStepFunction(HSEdgeState basisState)
        {
            List <HSEdgeState> v2edgeStates = new List <HSEdgeState>();

            double n = basisState.Vertex2.GraphEdges.Count();
            IAlgebraicExpression r = IAlgebraicExpression.RealNumber((n - 2.0d) / n);
            IAlgebraicExpression t = IAlgebraicExpression.RealNumber(2.0d / n);

            foreach (QGEdge edge in basisState.Vertex2.GraphEdges)
            {
                HSEdgeState edgeState;
                if (edge.Vertex1 == basisState.Vertex2)
                {
                    edgeState = new HSEdgeState(edge.Vertex1, edge.Vertex2);
                }
                else
                {
                    edgeState = new HSEdgeState(edge.Vertex2, edge.Vertex1);
                }

                // Skip the reflected state
                if (edgeState.Vertex2 != basisState.Vertex1)
                {
                    v2edgeStates.Add(edgeState);
                }
            }

            var vectorTerms = v2edgeStates.Select(s => new VectorTerm <HSEdgeState>(s, !basisState.Vertex2.IsMarked() ? t : -t));

            vectorTerms = vectorTerms.Prepend((new HSEdgeState(basisState.Vertex2, basisState.Vertex1),
                                               !basisState.Vertex2.IsMarked() ? -r : r));

            return(IHSExplicitVector <HSEdgeState> .VectorValue(vectorTerms));
        }
예제 #2
0
        private IHSExplicitVectorValue <HSEdgeState> __qwGetStartVector(IQGVertex startVertex)
        {
            List <HSEdgeState> edgeStates = new List <HSEdgeState>();

            double n = startVertex.GraphEdges.Count();
            IAlgebraicExpression coefficient = IAlgebraicExpression.RealNumber(1.0d / Math.Sqrt(n));

            foreach (QGEdge edge in startVertex.GraphEdges)
            {
                HSEdgeState edgeState;
                if (edge.Vertex1 == startVertex)
                {
                    edgeState = new HSEdgeState(edge.Vertex1, edge.Vertex2);
                }
                else
                {
                    edgeState = new HSEdgeState(edge.Vertex2, edge.Vertex1);
                }

                edgeStates.Add(edgeState);
            }

            var vectorTerms = edgeStates.Select(s => new VectorTerm <HSEdgeState>(s, coefficient));

            return(IHSExplicitVector <HSEdgeState> .VectorValue(vectorTerms));
        }
        public virtual TVector ScalarProduct(IAlgebraicExpression scalar)
        {
            var retTerms = new Dictionary <TBasis, IAlgebraicExpression>(this.Terms);

            foreach (var kvp in this.Terms)
            {
                retTerms[kvp.Key] = scalar.Multiply(kvp.Value);
            }

            return(this.NewExplicitVectorValue(retTerms));
        }
        public virtual IAlgebraicExpression InnerProduct(TVector other)
        {
            if (other is IExplicitVectorValue <TVector, TBasis> v)
            {
                IList <IAlgebraicExpression> squares = new List <IAlgebraicExpression>();
                foreach (var term in this)
                {
                    if (v.ContainsBasisTerm(term.BasisVector))
                    {
                        squares.Add(term.Coefficient.Multiply(v[term.BasisVector]));
                    }
                }

                return(IAlgebraicExpression.Sum(squares));
            }

            return(IExplicitGeneralizedVector <TVector, TBasis> .InnerProductOperation(this.AsExpressionType(), other));
        }
예제 #5
0
        public override IAlgebraicExpression InnerProduct(IHSExplicitVector <TBasis> other)
        {
            if (other is HSExplicitVectorValue <TBasis> v)
            {
                IList <IAlgebraicExpression> squares = new List <IAlgebraicExpression>();
                foreach (var term in this)
                {
                    if (v.ContainsBasisTerm(term.BasisVector))
                    {
                        squares.Add(term.Coefficient.ComplexConjugate().Multiply(v[term.BasisVector]));
                    }
                }

                return(IAlgebraicExpression.Sum(squares));
            }

            return(IHSExplicitVector <TBasis> .InnerProductOperation(this.AsExpressionType(), other));
        }
 public IAlgebraicExpression this[TBasis basisVector]
 => this.Terms.ContainsKey(basisVector) ? this.Terms[basisVector] : IAlgebraicExpression.RealNumber(0);
        public virtual IAlgebraicExpression Length()
        {
            var squares = this.Select(term => term.Coefficient.Multiply(term.Coefficient));

            return(IAlgebraicExpression.Sum(squares).SquareRoot());
        }
예제 #8
0
        public override IAlgebraicExpression Length()
        {
            var squares = this.Select(term => term.Coefficient.ComplexConjugate().Multiply(term.Coefficient));

            return(IAlgebraicExpression.Sum(squares).SquareRoot());
        }
예제 #9
0
 public IAlgebraicExpression Evaluate(MathContext context) => IAlgebraicExpression.RealNumber(this.Value);
예제 #10
0
 public IAlgebraicExpression Add(IAlgebraicExpression other)
 => (other is RealNumber rn) ? new RealNumber(this.Value + rn.Value) : IAlgebraicExpression.Addition(this, other);