Changeset 17596
- Timestamp:
- 06/10/20 13:47:08 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/VectorTreeSimplifier.cs
r17593 r17596 1370 1370 if (IsConstant(node)) { // assumes scalar constant 1371 1371 return node; 1372 } else if (IsAddition(node) ) {1372 } else if (IsAddition(node) || IsSubtraction(node)) { 1373 1373 var terms = node.Subtrees; 1374 if (IsSubtraction(node)) { 1375 if (terms.Count() == 1) { 1376 terms = terms.Select(Negate); 1377 } else { 1378 var first = terms.First().ToEnumerable(); 1379 var remaining = terms.Skip(1).Select(Negate); 1380 terms = first.Concat(remaining).ToList(); 1381 } 1382 } 1383 1374 1384 var scalarTerms = terms.Where(IsScalarNode).ToList(); 1375 1385 var remainingTerms = terms.Except(scalarTerms).ToList(); … … 1399 1409 } else 1400 1410 throw new InvalidOperationException("Addition does not contain any terms to simplify."); 1401 } else if (IsMultiplication(node) ) {1411 } else if (IsMultiplication(node) || IsDivision(node)) { 1402 1412 var factors = node.Subtrees; 1413 if (IsDivision(node)) { 1414 if (factors.Count() == 1) { 1415 factors = factors.Select(Invert); 1416 } else { 1417 var first = factors.First().ToEnumerable(); 1418 var remaining = factors.Skip(1).Select(Invert); 1419 factors = first.Concat(remaining).ToList(); 1420 } 1421 } 1422 1403 1423 var scalarFactors = factors.Where(IsScalarNode).ToList(); 1404 1424 var remainingFactors = factors.Except(scalarFactors).ToList(); … … 1432 1452 if (IsConstant(node)) { // assumes scalar constant 1433 1453 return node; 1434 } else if (IsAddition(node) ) {1454 } else if (IsAddition(node) || IsSubtraction(node)) { 1435 1455 var terms = node.Subtrees; 1456 if (IsSubtraction(node)) { 1457 if (terms.Count() == 1) { 1458 terms = terms.Select(Negate); 1459 } else { 1460 var first = terms.First().ToEnumerable(); 1461 var remaining = terms.Skip(1).Select(Negate); 1462 terms = first.Concat(remaining).ToList(); 1463 } 1464 } 1465 1436 1466 var scalarTerms = terms.Where(IsScalarNode).ToList(); 1437 1467 var remainingTerms = terms.Except(scalarTerms).ToList(); … … 1455 1485 } else 1456 1486 throw new InvalidOperationException("Addition does not contain any terms to simplify."); 1457 } else if (IsMultiplication(node) ) {1487 } else if (IsMultiplication(node) || IsDivision(node)) { 1458 1488 var factors = node.Subtrees; 1489 if (IsDivision(node)) { 1490 if (factors.Count() == 1) { 1491 factors = factors.Select(Invert); 1492 } else { 1493 var first = factors.First().ToEnumerable(); 1494 var remaining = factors.Skip(1).Select(Invert); 1495 factors = first.Concat(remaining).ToList(); 1496 } 1497 } 1498 1459 1499 var scalarFactors = factors.Where(IsScalarNode).ToList(); 1460 1500 var remainingFactors = factors.Except(scalarFactors).ToList();
Note: See TracChangeset
for help on using the changeset viewer.