Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs
r17797 r17820 934 934 var constBValue = Math.Round(constB.Value); 935 935 if (constBValue == 1.0) { 936 // root(a, 1) => a 936 937 return a; 937 938 } else if (constBValue == 0.0) { 938 return MakeConstant(1.0); 939 // root(a, 0) is not defined 940 //return MakeConstant(1.0); 941 return MakeConstant(double.NaN); 939 942 } else if (constBValue == -1.0) { 943 // root(a, -1) => a^(-1/1) => 1/a 940 944 return MakeFraction(MakeConstant(1.0), a); 941 945 } else if (constBValue < 0) { 946 // root(a, -b) => a^(-1/b) => (1/a)^(1/b) => root(1, b) / root(a, b) => 1 / root(a, b) 942 947 var rootNode = rootSymbol.CreateTreeNode(); 943 948 rootNode.AddSubtree(a); … … 988 993 double exponent = Math.Round(constB.Value); 989 994 if (exponent == 0.0) { 995 // a^0 => 1 990 996 return MakeConstant(1.0); 991 997 } else if (exponent == 1.0) { 998 // a^1 => a 992 999 return a; 993 1000 } else if (exponent == -1.0) { 1001 // a^-1 => 1/a 994 1002 return MakeFraction(MakeConstant(1.0), a); 995 1003 } else if (exponent < 0) { 1004 // a^-b => (1/a)^b => 1/(a^b) 996 1005 var powNode = powSymbol.CreateTreeNode(); 997 1006 powNode.AddSubtree(a); … … 1019 1028 return MakeConstant(((ConstantTreeNode)a).Value / ((ConstantTreeNode)b).Value); 1020 1029 } else if ((IsConstant(a) && ((ConstantTreeNode)a).Value != 1.0)) { 1030 // a / x => (a * 1/a) / (x * 1/a) => 1 / (x * 1/a) 1021 1031 return MakeFraction(MakeConstant(1.0), MakeProduct(b, Invert(a))); 1022 1032 } else if (IsVariableBase(a) && IsConstant(b)) { -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs
r17797 r17820 99 99 #region root rules 100 100 // cancellation 101 AssertEqualAfterSimplification("(root (variable 2.0 a) 0.0)", " 1.0");101 AssertEqualAfterSimplification("(root (variable 2.0 a) 0.0)", "NaN"); 102 102 // fixed point 103 103 AssertEqualAfterSimplification("(root (variable 2.0 a) 1.0)", "(variable 2.0 a)");
Note: See TracChangeset
for help on using the changeset viewer.