Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Invert.cs
1using System;
2using System.Collections.Generic;
6
8{
13 {
23 {
24 }
25
33 {
34 if (Operand is IRingElement E)
35 {
36 E = E.Invert();
37 if (E is null)
38 throw new ScriptRuntimeException("Operand not invertible.", this);
39 else
40 return E;
41 }
42 else if (Operand.IsScalar)
43 throw new ScriptRuntimeException("Operand not invertible.", this);
44 else
45 {
46 LinkedList<IElement> Elements = new LinkedList<IElement>();
47
48 foreach (IElement E2 in Operand.ChildElements)
49 Elements.AddLast(this.Evaluate(E2, Variables));
50
51 return Operand.Encapsulate(Elements, this);
52 }
53 }
54
61 public ScriptNode Differentiate(string VariableName, Variables Variables)
62 {
63 int Start = this.Start;
64 int Len = this.Length;
66
67 return this.DifferentiationChainRule(VariableName, Variables, this.op,
68 new Negate(
69 new Invert(
70 new Square(this.op, Start, Len, Expression),
71 Start, Len, Expression),
72 Start, Len, Expression));
73 }
74
81 public override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary<string, IElement> AlreadyFound)
82 {
83 if (!(CheckAgainst is EuclidianDomainElement E))
84 return PatternMatchResult.NoMatch;
85
86 IElement Inv = E.AssociatedEuclidianDomain.Divide(E.One, E);
87 if (Inv is null)
88 return PatternMatchResult.NoMatch;
89
90 return this.op.PatternMatch(Inv, AlreadyFound);
91 }
92
93 }
94}
Base class for all types of Euclidian domain elements.
Class managing a script expression.
Definition: Expression.cs:39
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
ScriptNode DifferentiationChainRule(string VariableName, Variables Variables, ScriptNode Argument, ScriptNode Differentiation)
Implements the differentiation chain rule, by differentiating the argument and multiplying it to the ...
Definition: ScriptNode.cs:195
virtual PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
Definition: ScriptNode.cs:169
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Base class for all unary operators.
Invert(ScriptNode Operand, int Start, int Length, Expression Expression)
Inversion operator.
Definition: Invert.cs:21
override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
Definition: Invert.cs:81
override IElement Evaluate(IElement Operand, Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
Definition: Invert.cs:32
ScriptNode Differentiate(string VariableName, Variables Variables)
Differentiates a script node, if possible.
Definition: Invert.cs:61
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
Basic interface for all types of ring elements.
Definition: IRingElement.cs:10
Base interface for lambda expressions.
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17