Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7136


Ignore:
Timestamp:
12/06/11 17:07:10 (13 years ago)
Author:
mkommend
Message:

#1686: Corrected the usage of parenthesis in the latex formatter.

File:
1 edited

Legend:

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

    r7038 r7136  
    9090    private void FormatBegin(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    9191      if (node.Symbol is Addition) {
    92         strBuilder.Append(@" ");
     92        strBuilder.Append(@" ( ");
    9393      } else if (node.Symbol is Subtraction) {
    9494        if (node.SubtreeCount == 1) {
    95           strBuilder.Append(@"- ");
     95          strBuilder.Append(@"- ( ");
    9696        } else {
    97           strBuilder.Append(@" ");
     97          strBuilder.Append(@" ( ");
    9898        }
    9999      } else if (node.Symbol is Multiplication) {
     
    109109          strBuilder.Append(@" \cfrac{1}{" + node.SubtreeCount + @"}");
    110110        }
    111         strBuilder.Append(@" ");
     111        strBuilder.Append(@" ( ");
    112112      } else if (node.Symbol is Logarithm) {
    113         strBuilder.Append(@"\log ");
     113        strBuilder.Append(@"\log ( ");
    114114      } else if (node.Symbol is Exponential) {
    115         strBuilder.Append(@"\exp ");
     115        strBuilder.Append(@"\exp ( ");
    116116      } else if (node.Symbol is Sine) {
    117         strBuilder.Append(@"\sin ");
     117        strBuilder.Append(@"\sin ( ");
    118118      } else if (node.Symbol is Cosine) {
    119         strBuilder.Append(@"\cos ");
     119        strBuilder.Append(@"\cos ( ");
    120120      } else if (node.Symbol is Tangent) {
    121         strBuilder.Append(@"\tan ");
     121        strBuilder.Append(@"\tan ( ");
    122122      } else if (node.Symbol is GreaterThan) {
    123         strBuilder.Append(@"  ");
     123        strBuilder.Append(@"  ( ");
    124124      } else if (node.Symbol is LessThan) {
    125         strBuilder.Append(@"  ");
     125        strBuilder.Append(@"  ( ");
    126126      } else if (node.Symbol is And) {
    127         strBuilder.Append(@"   ");
     127        strBuilder.Append(@"   ( ");
    128128      } else if (node.Symbol is Or) {
    129         strBuilder.Append(@"   ");
     129        strBuilder.Append(@"   ( ");
    130130      } else if (node.Symbol is Not) {
    131         strBuilder.Append(@" \neg ");
     131        strBuilder.Append(@" \neg ( ");
    132132      } else if (node.Symbol is IfThenElse) {
    133         strBuilder.Append(@" \operatorname{if}  0 < ");
     133        strBuilder.Append(@" \operatorname{if}  ( 0 < ");
    134134      } else if (node.Symbol is Constant) {
    135135        strBuilder.Append("c_{" + constants.Count + "} ");
     
    159159      } else if (node.Symbol is InvokeFunction) {
    160160        var invokeNode = node as InvokeFunctionTreeNode;
    161         strBuilder.Append(invokeNode.Symbol.FunctionName + @" ");
     161        strBuilder.Append(invokeNode.Symbol.FunctionName + @" ( ");
    162162      } else if (node.Symbol is StartSymbol) {
    163163        strBuilder.Append("Result & = ");
     
    166166        strBuilder.Append(" ARG+" + argSym.ArgumentIndex + " ");
    167167      } else if (node.Symbol is Derivative) {
    168         strBuilder.Append(@" \cfrac{d ");
     168        strBuilder.Append(@" \cfrac{d ( ");
    169169      } else if (node.Symbol is TimeLag) {
    170170        var laggedNode = node as ILaggedTreeNode;
    171171        currentLag += laggedNode.Lag;
    172172      } else if (node.Symbol is Power) {
    173         strBuilder.Append(@"");
     173        strBuilder.Append(@" ( ");
    174174      } else if (node.Symbol is Root) {
    175         strBuilder.Append(@"");
     175        strBuilder.Append(@" ( ");
    176176      } else if (node.Symbol is Integral) {
    177177        // actually a new variable for t is needed in all subtrees (TODO)
    178178        var laggedTreeNode = node as ILaggedTreeNode;
    179         strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 ");
     179        strBuilder.Append(@"\sum_{t=" + (laggedTreeNode.Lag + currentLag) + @"}^0 ( ");
    180180      } else if (node.Symbol is VariableCondition) {
    181181        var conditionTreeNode = node as VariableConditionTreeNode;
     
    184184        p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - c_{" + constants.Count + @"}   ";
    185185        constants.Add(conditionTreeNode.Threshold);
    186         strBuilder.Append(@" " + p + @"\cdot ");
     186        strBuilder.Append(@" ( " + p + @"\cdot ");
    187187      } else {
    188188        throw new NotImplementedException("Export of " + node.Symbol + " is not implemented.");
     
    216216        strBuilder.Append(@" < ");
    217217      } else if (node.Symbol is And) {
    218         strBuilder.Append(@" > 0  \land ");
     218        strBuilder.Append(@" > 0  ) \land (");
    219219      } else if (node.Symbol is Or) {
    220         strBuilder.Append(@" > 0  \lor ");
     220        strBuilder.Append(@" > 0  ) \lor (");
    221221      } else if (node.Symbol is Not) {
    222222        throw new InvalidOperationException();
    223223      } else if (node.Symbol is IfThenElse) {
    224         strBuilder.Append(@" , ");
     224        strBuilder.Append(@" ) , (");
    225225      } else if (node.Symbol is ProgramRootSymbol) {
    226226        strBuilder.Append(@"\\" + Environment.NewLine);
     
    231231        strBuilder.Append(@"\\" + Environment.NewLine + " & ");
    232232      } else if (node.Symbol is Power) {
    233         strBuilder.Append(@" ^ { \operatorname{round} ");
     233        strBuilder.Append(@") ^ { \operatorname{round} (");
    234234      } else if (node.Symbol is Root) {
    235         strBuilder.Append(@" ^ {  \cfrac{1}{ \operatorname{round} ");
     235        strBuilder.Append(@") ^ {  \cfrac{1}{ \operatorname{round} (");
    236236      } else if (node.Symbol is VariableCondition) {
    237237        var conditionTreeNode = node as VariableConditionTreeNode;
    238         string p = @"1 /  1 + \exp - c_{" + constants.Count + "} ";
     238        string p = @"1 / ( 1 + \exp ( - c_{" + constants.Count + "} ";
    239239        constants.Add(conditionTreeNode.Slope);
    240         p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - c_{" + constants.Count + @"}   ";
     240        p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - c_{" + constants.Count + @"} ) ) )   ";
    241241        constants.Add(conditionTreeNode.Threshold);
    242         strBuilder.Append(@" +  1 - " + p + @" \cdot ");
     242        strBuilder.Append(@" +  ( 1 - " + p + @" ) \cdot ");
    243243      } else {
    244244        throw new NotImplementedException("Export of " + node.Symbol + " is not implemented.");
     
    248248    private void FormatEnd(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    249249      if (node.Symbol is Addition) {
    250         strBuilder.Append(@" ");
     250        strBuilder.Append(@" ) ");
    251251      } else if (node.Symbol is Subtraction) {
    252         strBuilder.Append(@" ");
     252        strBuilder.Append(@" ) ");
    253253      } else if (node.Symbol is Multiplication) {
    254254      } else if (node.Symbol is Division) {
     
    260260        }
    261261      } else if (node.Symbol is Average) {
    262         strBuilder.Append(@" ");
     262        strBuilder.Append(@" ) ");
    263263      } else if (node.Symbol is Logarithm) {
    264         strBuilder.Append(@" ");
     264        strBuilder.Append(@" ) ");
    265265      } else if (node.Symbol is Exponential) {
    266         strBuilder.Append(@" ");
     266        strBuilder.Append(@" ) ");
    267267      } else if (node.Symbol is Sine) {
    268         strBuilder.Append(@" ");
     268        strBuilder.Append(@" ) ");
    269269      } else if (node.Symbol is Cosine) {
    270         strBuilder.Append(@" ");
     270        strBuilder.Append(@" ) ");
    271271      } else if (node.Symbol is Tangent) {
    272         strBuilder.Append(@" ");
     272        strBuilder.Append(@" ) ");
    273273      } else if (node.Symbol is GreaterThan) {
    274         strBuilder.Append(@" ");
     274        strBuilder.Append(@" ) ");
    275275      } else if (node.Symbol is LessThan) {
    276         strBuilder.Append(@" ");
     276        strBuilder.Append(@" ) ");
    277277      } else if (node.Symbol is And) {
    278         strBuilder.Append(@" > 0   ");
     278        strBuilder.Append(@" > 0 ) ) ");
    279279      } else if (node.Symbol is Or) {
    280         strBuilder.Append(@" > 0   ");
     280        strBuilder.Append(@" > 0 ) ) ");
    281281      } else if (node.Symbol is Not) {
    282         strBuilder.Append(@" ");
     282        strBuilder.Append(@" ) ");
    283283      } else if (node.Symbol is IfThenElse) {
    284         strBuilder.Append(@"   ");
     284        strBuilder.Append(@" ) ) ");
    285285      } else if (node.Symbol is Constant) {
    286286      } else if (node.Symbol is LaggedVariable) {
     
    298298      } else if (node.Symbol is Defun) {
    299299      } else if (node.Symbol is InvokeFunction) {
    300         strBuilder.Append(@" ");
     300        strBuilder.Append(@" ) ");
    301301      } else if (node.Symbol is StartSymbol) {
    302302      } else if (node.Symbol is Argument) {
    303303      } else if (node.Symbol is Derivative) {
    304         strBuilder.Append(@" }{dt} ");
     304        strBuilder.Append(@" ) }{dt} ");
    305305      } else if (node.Symbol is TimeLag) {
    306306        var laggedNode = node as ILaggedTreeNode;
    307307        currentLag -= laggedNode.Lag;
    308308      } else if (node.Symbol is Power) {
    309         strBuilder.Append(@" } ");
     309        strBuilder.Append(@" ) } ");
    310310      } else if (node.Symbol is Root) {
    311         strBuilder.Append(@" } } ");
     311        strBuilder.Append(@" ) } ) } ");
    312312      } else if (node.Symbol is Integral) {
    313313        var laggedTreeNode = node as ILaggedTreeNode;
    314         strBuilder.Append(@" ");
     314        strBuilder.Append(@" ) ");
    315315      } else if (node.Symbol is VariableCondition) {
    316316        strBuilder.Append(@"\left) ");
Note: See TracChangeset for help on using the changeset viewer.