Can I create new expression from hashset<expression>?

(Tyetis) #1

Can I create new expression from hashset ?
in other words, I have expression tree (sum, product, power) and i filtered power terms and create new expression


x^3 + y^2 + x + y 8

i want to x^3 + y^2

(Christoph Rüegg) #2

I’m not sure I understand what you’re trying to achieve. Where is the mentioned hash set supposed to come into play?

(Tyetis) #3

in C#;

Expression aleft = Infix.ParseOrThrow(“x^3 + x^2 + 8 + x”);
HashSet<Expression> generated_exp = ((Expression.Product)aleft).Item.Where(n => n.IsPower);

i want to create new expression using "generated_exp " variable and like this "x^3 + x^2"
so i want to get just power terms

(Christoph Rüegg) #4

You can use Operators.sumSeq to build a sum based on an enumerable of expressions.

But I realize we need to improve the API here. I guess in C# this function should be called something along the lines of Operators.SumOfEnumerable.

(Tyetis) #5

thanks. this really worked for me.

I’ll write here when I have another question

good work