Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs
r17180 r17797 933 933 var constB = b as ConstantTreeNode; 934 934 var constBValue = Math.Round(constB.Value); 935 if (constBValue .IsAlmost(1.0)) {935 if (constBValue == 1.0) { 936 936 return a; 937 } else if (constBValue .IsAlmost(0.0)) {937 } else if (constBValue == 0.0) { 938 938 return MakeConstant(1.0); 939 } else if (constBValue .IsAlmost(-1.0)) {939 } else if (constBValue == -1.0) { 940 940 return MakeFraction(MakeConstant(1.0), a); 941 941 } else if (constBValue < 0) { … … 987 987 var constB = b as ConstantTreeNode; 988 988 double exponent = Math.Round(constB.Value); 989 if (exponent .IsAlmost(0.0)) {989 if (exponent == 0.0) { 990 990 return MakeConstant(1.0); 991 } else if (exponent .IsAlmost(1.0)) {991 } else if (exponent == 1.0) { 992 992 return a; 993 } else if (exponent .IsAlmost(-1.0)) {993 } else if (exponent == -1.0) { 994 994 return MakeFraction(MakeConstant(1.0), a); 995 995 } else if (exponent < 0) { … … 1018 1018 // fold constants 1019 1019 return MakeConstant(((ConstantTreeNode)a).Value / ((ConstantTreeNode)b).Value); 1020 } else if ((IsConstant(a) && !((ConstantTreeNode)a).Value.IsAlmost(1.0))) {1020 } else if ((IsConstant(a) && ((ConstantTreeNode)a).Value != 1.0)) { 1021 1021 return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a))); 1022 1022 } else if (IsVariableBase(a) && IsConstant(b)) { … … 1094 1094 // b is not constant => make sure constant is on the right 1095 1095 return MakeSum(b, a); 1096 } else if (IsConstant(b) && ((ConstantTreeNode)b).Value .IsAlmost(0.0)) {1096 } else if (IsConstant(b) && ((ConstantTreeNode)b).Value == 0.0) { 1097 1097 // x + 0 => x 1098 1098 return a; … … 1210 1210 foreach (var unchangedSubtree in unchangedSubtrees) 1211 1211 sum.AddSubtree(unchangedSubtree); 1212 if ( !constant.IsAlmost(0.0)) {1212 if (constant != 0.0) { 1213 1213 sum.AddSubtree(MakeConstant(constant)); 1214 1214 } … … 1268 1268 if (wi < 0) throw new ArgumentException(); 1269 1269 return MakeBinFactor(node1.Symbol, node1.VariableName, node1.VariableValue, node1.Weight * node0.Weights[wi]); 1270 } else if (IsConstant(b) && ((ConstantTreeNode)b).Value .IsAlmost(1.0)) {1270 } else if (IsConstant(b) && ((ConstantTreeNode)b).Value == 1.0) { 1271 1271 // $ * 1.0 => $ 1272 1272 return a; 1273 } else if (IsConstant(b) && ((ConstantTreeNode)b).Value .IsAlmost(0.0)) {1273 } else if (IsConstant(b) && ((ConstantTreeNode)b).Value == 0.0) { 1274 1274 return MakeConstant(0); 1275 1275 } else if (IsConstant(b) && IsVariableBase(a)) { … … 1419 1419 prod.AddSubtree(unchangedSubtree); 1420 1420 1421 if ( !constantProduct.IsAlmost(1.0)) {1421 if (constantProduct != 1.0) { 1422 1422 prod.AddSubtree(MakeConstant(constantProduct)); 1423 1423 } -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs
r17796 r17797 272 272 #region do not drop subtrees with small weights 273 273 AssertEqualAfterSimplification("(* 1e-14 (variable 1.0 a))", "(variable 1e-14 a)"); 274 AssertEqualAfterSimplification("(+ 1e-14 (variable 1.0 a))", "(+ 1e-14 (variable 1.0 a))"); 274 AssertEqualAfterSimplification("(+ (variable 1.0 a) 1e-14)", 275 "(+ (variable 1.0 a) 1e-14)"); 275 276 // a scenario where a term with small weight can have large effect 276 AssertEqualAfterSimplification("(+ (* 1e-14 (pow (variable 1.0 a) 10)) 1.0)",277 "(+ (* 1e-14 (pow (variable 1.0 a) 10)) 1.0)");277 AssertEqualAfterSimplification("(+ (* (pow (variable 1.0 a) 10) 1e-14) 1.0)", 278 "(+ (* (pow (variable 1.0 a) 10) 1e-14) 1.0)"); 278 279 // a test case (from ticket #2985) 279 AssertEqualAfterSimplification("(+ 5.9323E-002 (* 5.5606E-016 (exp (variable 3.5861E+001 a))))",280 "(+ 5.9323E-002 (* 5.5606E-016 (exp (variable 3.5861E+001 a))))");280 AssertEqualAfterSimplification("(+ (* (exp (variable 3.5861E+001 a)) 5.5606E-016) 5.9323E-002)", 281 "(+ (* (exp (variable 3.5861E+001 a)) 5.5606E-016) 5.9323E-002)"); 281 282 #endregion 282 283 }
Note: See TracChangeset
for help on using the changeset viewer.