Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Product.cs
1using System.Collections.Generic;
2using System.Numerics;
8
10{
15 {
25 {
26 }
27
31 public override string FunctionName => nameof(Product);
32
36 public override string[] Aliases
37 {
38 get { return new string[] { "prod", "∏" }; }
39 }
40
48 {
49 return new DoubleNumber(CalcProduct(Argument.Values));
50 }
51
57 public static double CalcProduct(double[] Values)
58 {
59 double Result = 1;
60 int i, c = Values.Length;
61
62 for (i = 0; i < c; i++)
63 Result *= Values[i];
64
65 return Result;
66 }
67
75 {
76 return new ComplexNumber(CalcProduct(Argument.Values));
77 }
78
84 public static Complex CalcProduct(Complex[] Values)
85 {
86 Complex Result = Complex.One;
87 int i, c = Values.Length;
88
89 for (i = 0; i < c; i++)
90 Result *= Values[i];
91
92 return Result;
93 }
94
102 {
103 return EvaluateProduct(Argument, this);
104 }
105
112 public static IElement EvaluateProduct(IVector Vector, ScriptNode Node)
113 {
114 return EvaluateProduct(Vector.VectorElements, Node);
115 }
116
123 public static IElement EvaluateProduct(ICollection<IElement> Elements, ScriptNode Node)
124 {
125 IRingElement Result = null;
126 IRingElement RE;
128
129 foreach (IElement E in Elements)
130 {
131 RE = E as IRingElement;
132 if (RE is null)
133 {
134 if (Elements.Count == 1)
135 return E;
136 else
137 throw new ScriptRuntimeException("Elements cannot be multiplied.", Node);
138 }
139
140 if (Result is null)
141 Result = RE;
142 else
143 {
144 Product = Result.MultiplyRight(RE);
145 if (Product is null)
146 Product = (IRingElement)Operators.Arithmetics.Multiply.EvaluateMultiplication(Result, RE, Node);
147
148 Result = Product;
149 }
150 }
151
152 if (Result is null)
153 return ObjectValue.Null;
154 else
155 return Result;
156 }
157
158 }
159}
Class managing a script expression.
Definition: Expression.cs:39
static Complex CalcProduct(Complex[] Values)
Calculates the product of a set of complex values.
Definition: Product.cs:84
override IElement EvaluateVector(DoubleVector Argument, Variables Variables)
Evaluates the function on a vector argument.
Definition: Product.cs:47
Product(ScriptNode Argument, int Start, int Length, Expression Expression)
Product(v), Prod(v)
Definition: Product.cs:23
static IElement EvaluateProduct(ICollection< IElement > Elements, ScriptNode Node)
Multiplies the elements of a vector.
Definition: Product.cs:123
static double CalcProduct(double[] Values)
Calculates the product of a set of double values.
Definition: Product.cs:57
override IElement EvaluateVector(ComplexVector Argument, Variables Variables)
Evaluates the function on a vector argument.
Definition: Product.cs:74
override string FunctionName
Name of the function
Definition: Product.cs:31
override IElement EvaluateVector(IVector Argument, Variables Variables)
Evaluates the function on a vector argument.
Definition: Product.cs:101
static IElement EvaluateProduct(IVector Vector, ScriptNode Node)
Multiplies the elements of a vector.
Definition: Product.cs:112
override string[] Aliases
Optional aliases. If there are no aliases for the function, null is returned.
Definition: Product.cs:37
ScriptNode Argument
Function argument.
Base class for funcions of one vector variable.
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
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
static readonly ObjectValue Null
Null value.
Definition: ObjectValue.cs:86
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
Basic interface for vectors.
Definition: IVector.cs:9
ICollection< IElement > VectorElements
An enumeration of vector elements.
Definition: IVector.cs:22