本文整理汇总了C#中Expression.EqualsZero方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.EqualsZero方法的具体用法?C# Expression.EqualsZero怎么用?C# Expression.EqualsZero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression.EqualsZero方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Matches
public override bool Matches(Expression E, MatchContext Matched)
{
Expression matched;
if (Matched.TryGetValue(Right, out matched))
{
if (Left.Matches(E ^ Binary.Divide(1, matched), Matched))
return true;
}
// x^0 = 1.
if (E.EqualsOne() && Right.Matches(0, Matched))
return true;
// 0^x = 0.
if (E.EqualsZero() && Left.Matches(0, Matched))
return true;
Binary PE = E as Power;
if (!ReferenceEquals(PE, null) && Matched.TryMatch(() => Left.Matches(PE.Left, Matched) && Right.Matches(PE.Right, Matched)))
return true;
// If the exponent matches 1, E can match left.
if (Matched.TryMatch(() => Right.Matches(1, Matched) && Left.Matches(E, Matched)))
return true;
if (Right.IsInteger() && Left.Matches(ComputerAlgebra.Power.New(E, Binary.Divide(1, Right)).Evaluate(), Matched))
return true;
return false;
}
示例2: Analyze
public static Expression Analyze(Analysis Mna, string Name, Node Anode, Node Cathode, Expression R)
{
// i = V/R
if (R.EqualsZero())
{
return Conductor.Analyze(Mna, Name, Anode, Cathode);
}
else
{
Expression i = (Anode.V - Cathode.V) / R;
Mna.AddPassiveComponent(Anode, Cathode, i);
return i;
}
}
示例3: Matches
public override bool Matches(Expression E, MatchContext Matched)
{
// if E is zero, any term can match to zero to succeed.
if (E.EqualsZero())
return Terms.Any(i => i.Matches(0, Matched));
// Move the constants in this pattern to E.
IEnumerable<Expression> PTerms = Terms;
IEnumerable<Expression> Constants = PTerms.OfType<Constant>();
if (Constants.Any())
{
E = Binary.Divide(E, New(Constants)).Evaluate();
PTerms = PTerms.Except(Constants, RefComparer);
}
IEnumerable<Expression> ETerms = TermsOf(E);
// Try starting the match at each term of the pattern.
foreach (Expression p in PTerms)
{
// Remaining terms of the pattern.
Expression P = New(PTerms.ExceptUnique(p, RefComparer));
// If p is a variable, we have to handle the possibility that more than one term of E might match this term.
if (p is Variable)
{
// Check if p has already been matched. If it has, treat it as a constant and match the rest of the terms.
Expression matched;
if (Matched.TryGetValue(p, out matched))
{
// p has already been matched. Remove it out of E and match the remainder of the pattern.
if (P.Matches(E / matched, Matched))
return true;
}
else
{
// Try matching p to the various combinations of the terms of E.
for (int i = 1; i <= ETerms.Count(); ++i)
{
foreach (IEnumerable<Expression> e in ETerms.Combinations(i))
if (Matched.TryMatch(() =>
p.Matches(New(e), Matched) &&
P.Matches(New(ETerms.ExceptUnique(e, RefComparer)), Matched)))
return true;
}
// Try matching p to identity.
if (Matched.TryMatch(() => p.Matches(1, Matched) && P.Matches(E, Matched)))
return true;
}
}
else
{
// If p is not a variable, try matching it to any of the terms of E.
foreach (Expression e in ETerms)
if (Matched.TryMatch(() =>
p.Matches(e, Matched) &&
P.Matches(New(ETerms.ExceptUnique(e, RefComparer)), Matched)))
return true;
}
}
return false;
}