Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17811


Ignore:
Timestamp:
12/31/20 15:39:28 (4 years ago)
Author:
gkronber
Message:

#2968: integer powers are included directly in the expression instead of the list of coefficients.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs

    r17685 r17811  
    2929using HeuristicLab.Core;
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    31 using Microsoft.SqlServer.Server;
    3231
    3332namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    3938        // operators
    4039        if (token == "+" || token == "-" || token == "OR" || token == "XOR" ||
    41             token == "*" || token == "/" || token == "AND" ||
    42             token == "^") {
     40            token == "*" || token == "/" || token == "AND") {
    4341          strBuilder.Append("(");
    4442          FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, constants);
     
    4745            strBuilder.Append(" ").Append(token).Append(" ");
    4846            FormatRecursively(subtree, strBuilder, numberFormat, formatString, constants);
     47          }
     48
     49          strBuilder.Append(")");
     50        } else if (token == "^") {
     51          // handle integer powers directly
     52          strBuilder.Append("(");
     53          FormatRecursively(node.Subtrees.First(), strBuilder, numberFormat, formatString, constants);
     54
     55          var power = node.GetSubtree(1);
     56          if(power is ConstantTreeNode constNode && Math.Truncate(constNode.Value) == constNode.Value) {
     57            strBuilder.Append(" ").Append(token).Append(" ").Append(constNode.Value.ToString(formatString, numberFormat));
     58          } else {
     59            strBuilder.Append(" ").Append(token).Append(" ");
     60            FormatRecursively(power, strBuilder, numberFormat, formatString, constants);
    4961          }
    5062
     
    131143        } else if (node.Symbol is Constant) {
    132144          var constNode = node as ConstantTreeNode;
    133           if(constants==null && constNode.Value < 0) {
     145          if (constants == null && constNode.Value < 0) {
    134146            strBuilder.Append("(").Append(constNode.Value.ToString(formatString, numberFormat))
    135147                      .Append(")"); // (-1
Note: See TracChangeset for help on using the changeset viewer.