Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PSE P4.11 - DeepSelect(DoubleAngleFormulaFunc)
- Loading branch information
1 parent
f111f05
commit f0f9dd0
Showing
4 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Symbolism | ||
{ | ||
namespace DeepSelect | ||
{ | ||
public static class Extensions | ||
{ | ||
public static MathObject DeepSelect(this MathObject obj, Func<MathObject, MathObject> proc) | ||
{ | ||
var result = proc(obj); | ||
|
||
if (result is Power) | ||
{ | ||
return | ||
(result as Power).bas.DeepSelect(proc) ^ | ||
(result as Power).exp.DeepSelect(proc); | ||
} | ||
|
||
if (result is Or) | ||
return (result as Or).Map(elt => elt.DeepSelect(proc)); | ||
|
||
if (result is And) | ||
return (result as And).Map(elt => elt.DeepSelect(proc)); | ||
|
||
if (result is Equation) | ||
return | ||
(result as Equation).a.DeepSelect(proc) == | ||
(result as Equation).b.DeepSelect(proc); | ||
|
||
if (result is Sum) | ||
return | ||
new Sum() { elts = (result as Sum).elts.Select(elt => elt.DeepSelect(proc)).ToList() }.Simplify(); | ||
|
||
if (result is Product) | ||
return | ||
new Product() { elts = (result as Product).elts.Select(elt => elt.DeepSelect(proc)).ToList() }.Simplify(); | ||
|
||
return result; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters