/// <summary> /// Apply the resolution rule to passed clauses /// </summary> /// <param name="node1"></param> /// <param name="node2"></param> /// <returns>The list of formulas, which is a the logical consequence of input clauses</returns> public static IEnumerable <INode> Resolve(INode node1, INode node2) { var rule = RulesLibrary.GetResolutionRule(); var instances = rule.SelectWhere(node1, node2); return(instances.Select(ins => rule .Apply(ins) .Where(z => z.Children.Length > 0) .ToArray()) .Select(nodes => nodes.Length == 1 ? nodes[0] : new MultipleOr(nodes)) .ToList()); }
/// <summary> /// Calculate partial differentiation of function, represented as syntax tree /// </summary> /// <param name="node">Function tree</param> /// <param name="index">Index of variable</param> /// <param name="variable">Variable symbol</param> /// <returns></returns> public static INode Differentiate(INode node, int index = 0, String variable = "") { var varIndex = index; var varName = NodeElementNames.GetVariableNodeNames().ElementAt(index); var rules = RulesLibrary.GetSimplificationRules().ToList(); rules.AddRange(RulesLibrary.GetDifferentiationRules()); if (variable.Equals("") || NodeElementNames.GetVariableNodeNames().IndexOf(variable) == -1) { return(RulesLibrary.ApplyRules(new Dif <double>(node, VariableNode.Make <double>(varIndex, varName)), rules.ToArray())); } varIndex = NodeElementNames.GetVariableNodeNames().IndexOf(variable); varName = variable; return(RulesLibrary.ApplyRules(new Dif <double>(node, VariableNode.Make <double>(varIndex, varName)), rules.ToArray())); }
/// <summary> /// Simplify tree, using simplification rules from <see cref="RulesLibrary"/> /// </summary> /// <param name="tree"></param> /// <returns></returns> public static INode Simplify(INode tree) { return(RulesLibrary.ApplyRules(tree, RulesLibrary.GetSimplificationRules())); }