Changeset 17797 for trunk/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 12/22/20 08:48:27 (4 years ago)
- File:
-
- 1 edited
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 }
Note: See TracChangeset
for help on using the changeset viewer.