//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public Algebraic add(Algebraic p) throws JasymcaException public override Algebraic add(Algebraic p) { if (p is Rational) { return(p.add(this)); } if (p is Polynomial) { if (v.Equals(((Polynomial)p).v)) { int len = Math.Max(a.Length, ((Polynomial)p).a.Length); Algebraic[] csum = new Algebraic[len]; for (int i = 0; i < len; i++) { csum[i] = coefficient(i).add(((Polynomial)p).coefficient(i)); } return((new Polynomial(v, csum)).reduce()); } else if (v.smaller(((Polynomial)p).v)) { return(p.add(this)); } } Algebraic[] _csum = Poly.clone(a); _csum[0] = a[0].add(p); return((new Polynomial(v, _csum)).reduce()); }
public bool Equals(SamplerTextureKey other) { if (Sampler == null && other.Sampler == null) { return(Texture.Equals(other.Texture)); } if (Sampler == null || other.Sampler == null) { return(false); } return(Sampler.Equals(other.Sampler) && Texture.Equals(other.Texture)); }
public void EvaluateExpression_Boxed_Context(string exprText, Variable expected, bool expectedEqual) { Variable variable = ParseAndEval(exprText); if (expectedEqual) { Assert.True(variable.Equals(expected)); } else { Assert.False(variable.Equals(expected)); } }
public void Predicates() { IPredicate v1 = new Variable("one"); IPredicate v2 = new Variable("two"); IPredicate i1 = new Individual("one"); IPredicate i2 = new Individual("two"); Assert.AreEqual(v1, new Variable("one"), "Similar Variables"); Assert.IsFalse(v1.Equals(v2), "Different Variables"); Assert.IsFalse(v1.Equals(i2), "Variable differs from Individual"); Assert.AreEqual(i1, new Individual("one"), "Similar Individuals"); Assert.IsFalse(i1.Equals(i2), "Different Variables"); Assert.IsFalse(i2.Equals(v1), "Individual differs from Variable"); }
public virtual Algebraic coefficient(Variable v, int n) { if (v.Equals(_v)) { return(coefficient(n)); } Algebraic c = Symbolic.ZERO; for (int i = 0; i < Coeffs.Length; i++) { var ci = Coeffs[i]; if (ci is Polynomial) { c = c + (( Polynomial )ci).coefficient(v, n) * (new Polynomial(_v) ^ i); } else if (n == 0) { c = c + ci * (new Polynomial(_v) ^ i); } } return(c); }
public static void R25() { // Create a timeseries to work with. Timeseries ts1 = Timeseries.RandomTimeseries(1); ts1.Rename("Test1"); if (ts1.Length != 1) { throw new Exception("Unexpected number of variable."); } // The only timeseries should now be named "Test1" Variable v = ts1["Test1"]; if (ts1["Test1"].Name != "Test1") { throw new Exception("Unexpected name."); } // Add a new variable. Should not affect the existing variable. // Verify that indexor still return the right object. ts1["Test"] = ts1["Test1"].Sma(12); if (ts1.Length != 2) { throw new Exception("Unexpected number of variable."); } if (v.Equals(ts1["Test1"]) == false) { throw new Exception("Wrong object returned."); } }
// // PROTECTED METHODS // // Note: You can subclass and override this method in order // to re-implement the OCCUR-CHECK?() to always // return false if you want that to be the default // behavior, as is the case with Prolog. // Note: Implementation is based on unify-bug.pdf document by Peter Norvig: // http://norvig.com/unify-bug.pdf protected bool occurCheck(IMap <Variable, Term> theta, Variable var, FOLNode x) { // ((equal var x) t) if (var.Equals(x)) { return(true); // ((bound? x subst) } else if (x is Variable && theta.ContainsKey(x as Variable)) { // (occurs-in? var (lookup x subst) subst)) return(occurCheck(theta, var, theta.Get(x as Variable))); // ((consp x) (or (occurs-in? var (first x) subst) (occurs-in? var // (rest x) subst))) } else if (x is Function && x is Function) { // (or (occurs-in? var (first x) subst) (occurs-in? var (rest x) // subst))) Function fx = (Function)x; foreach (Term fxt in fx.getArgs()) { if (occurCheck(theta, var, fxt)) { return(true); } } } return(false); }
public void Integer_with_same_value_are_Equal() { var a = new Variable(100); var b = new Variable(100); a.Equals(b).Should().BeTrue(); }
public void Float_with_same_value_are_Equal() { var a = new Variable(50.25f); var b = new Variable(50.25f); a.Equals(b).Should().BeTrue(); }
public override Algebraic mult(Algebraic x) { if (x.Equals(Zahl.ZERO)) { return(x); } if (x is Zahl) { return(new Exponential(a[1].mult(x), a[0].mult(x), expvar, exp_b)); } if (x is Exponential && expvar.Equals(((Exponential)x).expvar)) { Exponential xp = (Exponential)x; Algebraic r = Zahl.ZERO; Algebraic nex = exp_b.add(xp.exp_b); if (nex.Equals(Zahl.ZERO)) { r = a[1].mult(xp.a[1]); } else { r = new Exponential(a[1].mult(xp.a[1]), Zahl.ZERO, expvar, nex); } r = r.add(a[0].mult(xp)); r = r.add(mult(xp.a[0])); r = r.reduce(); return(r); } return(poly2exp(base.mult(x))); }
public void String_with_different_values_are_not_Equal() { var a = new Variable("vara"); var b = new Variable("varb"); a.Equals(b).Should().BeFalse(); }
public void Basic() { Variable v = new Variable("v"); Assert.IsTrue(v.Equals(new Variable("v") as object)); _ = Assert.ThrowsException <NullReferenceException>(() => v.GetDefault <object>()); }
/// <summary> /// Evaluates the tokens bound to this AggregatorNode and generates the list of InferredFacts. /// </summary> internal void Evaluate() { int cntOfEarlierConditions = lhs.Count - 1; VariableSubstituter vs = null; for (int i = cntOfEarlierConditions; i >= 0; i--) { Condition earlier_cond = lhs[i]; if (earlier_cond.ConditionType == ConditionType.Positive) { for (int f2 = 0; f2 < 3; f2++) { Variable o = earlier_cond.Fields[f2] as Variable; if (o != null && o.Equals(_groupBy)) { vs = new VariableSubstituter(); vs.FieldNumber = f2; vs.NumberOfLevelsUp = (cntOfEarlierConditions - i); vs.BindingPair.Variable = o; f2 = 3; i = -1; //escape loop of cntOfEarlierConditions } } } } if (vs == null) { throw new ApplicationException("Bad rule"); } Dictionary <Term, List <WME> > sorter = new Dictionary <Term, List <WME> >(); foreach (Token token in _aggregatorNode.Items) { Token ptoken = token.GetTokenUp(vs.NumberOfLevelsUp); Term key = ptoken.WME.Fields[vs.FieldNumber]; if (sorter.ContainsKey(key)) { List <WME> list = sorter[key]; if (list.Contains(token.WME) == false) { list.Add(token.WME); } } else { List <WME> list = new List <WME>(); list.Add(token.WME); sorter.Add(key, list); } } foreach (KeyValuePair <Term, List <WME> > pair in sorter) { Term val = _aggregator.Evaluate(pair.Value); _inferredFacts.Add(new Activation(new WME(pair.Key, _aggregator.Alias, val), _conditionType)); } }
public void EvaluateForStatement(string exprText, Variable expected) { VariableContext context = new VariableContext(); Variable variable = ParseAndEval(exprText, context); Assert.True(variable.Equals(expected)); }
public override bool Equals(object obj) { Substitution other = obj as Substitution; return(other != null && Variable.Equals(other.Variable) && SubstitutionTerm.Equals(other.SubstitutionTerm)); }
public void String_with_same_value_are_Equal() { var a = new Variable("vara"); var b = new Variable("vara"); var result = a.Equals(b); result.Should().BeTrue(); }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns> /// The result of analysis. /// </returns> public override IExpression Analyze(Variable exp) { if (exp.Equals(Variable)) { return(new Number(1)); } return(exp.Clone()); }
public void Equals() { Variable variable1 = new Variable("X"); Variable variable2 = new Variable("Y"); Variable variable3 = new Variable("X"); Assert.AreEqual(variable1, variable3); Assert.AreEqual(variable3, variable1); Assert.AreEqual(variable1.GetHashCode(), variable3.GetHashCode()); Assert.IsFalse(variable1.Equals(null)); Assert.IsFalse(variable1.Equals(123)); Assert.IsFalse(variable1.Equals("foo")); Assert.AreNotEqual(variable1, variable2); Assert.AreNotEqual(variable2, variable1); }
public override Algebraic Value(Variable item, Algebraic x) { if (item.Equals(this)) { return(x); } return(new Polynomial(this)); }
public void ShouldCreateVariables() { PrologMachine pm = new PrologMachine(); Variable v1 = pm.GetVariable(0); Variable v2 = pm.GetVariable(0); Assert.IsTrue(v1.Equals(v2)); Assert.AreEqual("_0", v1.ToString()); }
public override bool Equals(object obj) { var other = obj as Universal; if (other == null) { return(false); } return(Variable.Equals(other.Variable) && Expression.Equals(other.Expression)); }
/// @cond DOXYGEN_SHOULD_SKIP_THIS public override bool Equals(object obj) { Substitution s = obj as Substitution; if (s == null) { return(false); } return(Variable.Equals(s.Variable) && SubValue.Equals(s.SubValue)); }
////////////////////////////////////////////////////////////////////////////////// public static bool tryUnify(Variable lv1, Variable lv2, Substitution s) { Debug.Assert(lv1.type.isEquivalent(lv2.type)); Debug.Assert(!s.hasMap(lv1.variable)); Debug.Assert(!s.hasMap(lv2.variable)); if (lv1.Equals(lv2)) { return(true); } s.composeWith(new Substitution(lv1.variable, lv2)); return(true); }
public override bool Equals(object obj) { if (obj is ParserAction parserAction) { if (Action.Equals(parserAction.Action) && ShiftState.Equals(parserAction.ShiftState) && (Variable?.Equals(parserAction.Variable) ?? false)) { return(Handle?.ToList().SequenceEqual(parserAction.Handle) ?? false); } } return(false); }
// A method to test Variable binding static void TestVariableBinding() { System.Console.WriteLine("====================="); System.Console.WriteLine("Testing Variable Binding:"); Variable var1 = new Variable(new E(), 01); Variable var2 = new Variable(new E(), 02); Variable var3 = new Variable(new T(), 03); if (var1.Equals(var1.Bind(123, var2))) { System.Console.WriteLine("Could not bind var1 to var2 because their IDs " + "were not equal; good! This should happen"); } if (var1.Equals(var1.Bind(01, var3))) { System.Console.WriteLine("Could not bind var1 to var3 because their semantic types " + "were not equal; good! This should happen"); } if (var2.Equals(var1.Bind(01, var2))) { System.Console.WriteLine("Successfully bound 2 variables with matching IDs and semantic types!"); } System.Console.WriteLine("====================="); }
protected override Algebraic Add(Algebraic a) { if (a is Rational) { return(a + this); } if (a is Polynomial) { var p = ( Polynomial )a; if (_v.Equals(p._v)) { int len = Math.Max(Coeffs.Length, p.Coeffs.Length); var csum = new Algebraic[len]; for (int i = 0; i < len; i++) { csum[i] = coefficient(i) + p.coefficient(i); } return((new Polynomial(_v, csum)).Reduce()); } else if (_v.Smaller(p._v)) { return(a + this); } } var _csum = Poly.Clone(Coeffs); _csum[0] = Coeffs[0] + a; return((new Polynomial(_v, _csum)).Reduce()); }
public void Parse_SingleVaribaleExpression() { // arrange string expression = "var1"; //act bool parsedWell = BrigitExpressionParser.Preprocess(expression); var exp = BrigitExpressionParser.Parse(expression); var expected = new Variable("var1"); // assert bool checker = parsedWell && expected.Equals(exp); Assert.AreEqual(true, checker); }
public override bool Equals(object other) { if (null == other) { return(false); } if (this == other) { return(true); } if (GetType().Equals(other.GetType())) { return(itsVariable.Equals(((VariableExpression)other).itsVariable)); } return(false); }
public virtual int degree(Variable v) { if (v.Equals(v)) { return(a.Length - 1); } int degree = 0; for (int i = 0; i < a.Length; i++) { int d = Poly.degree(a[i], v); if (d > degree) { degree = d; } } return(degree); }
/// <summary> /// Makes UnaryAssignment instruction type from NoOperation /// </summary> /// <param name="left_value">Left value (variable only)</param> /// <param name="right_value">Right value (variable only, can be the same as a left value)</param> /// <param name="operation">Unary operation</param> public static void UnaryAssignment(Instruction ins, Variable left_value, Variable right_value, Instruction.UnaryOperationType operation) { if (ins.statementType != Objects.Common.StatementType.NoOperation) { throw new ObfuscatorException("Only NoOperation instruction can be modified to other type!"); } if (left_value == null) { throw new ObfuscatorException("Wrong parameter passing: missing left value."); } if (right_value == null) { throw new ObfuscatorException("Wrong parameter passing: missing right value."); } string op = string.Empty; switch (operation) { case Instruction.UnaryOperationType.ArithmeticNegation: op = "-"; break; case Instruction.UnaryOperationType.LogicalNegation: op = "!"; break; default: throw new ObfuscatorException("Unsupported unary operation type."); } ins.RefVariables.Clear(); ins.RefVariables.Add(left_value); if (!left_value.Equals(right_value)) { ins.RefVariables.Add(right_value); } ins.statementType = Objects.Common.StatementType.UnaryAssignment; ins.TACtext = string.Join(" ", left_value.name, ":=", op, right_value.name); }
public void CopyVariable(Variable dest, Variable source) { // if the source/dest copies pointers (references), then we need // to make their values equal. if (!dest.Equals(source)) { this.SetLocationAssigned(dest); } if ((dest.Type != null && !dest.Type.IsValueType) || (source.Type != null && !source.Type.IsValueType)) { ISymValue svalue = this.egraph[ValueOf, this.egraph[source]]; this.egraph[ValueOf, this.egraph[dest]] = svalue; } // if one of the two is a pointer type, we furthermore make the target assigned if ((source.Type != null && source.Type.IsPointerType) || (dest.Type != null && dest.Type.IsPointerType)) { this.SetAssignedRef(source); } }