Skip to main content
Tweeted twitter.com/StackMma/status/749561396589895680
edited tags
Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
added 616 characters in body
Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44

Can somebody help me with a function f such that it extract all sub expressions (i.e. looking down the expression tree) from any expression given to it and also a list of heads it encounters as it moves down the expression tree.

For example, f@(Sin[Log[Cos[a], Tan[Log[a, b]]]] // Inactivate) gives { { Inactive[Sin][Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]]], Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]], Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]], a, Inactive[Log][a,b], a, b }, { Inactive[Sin], Inactive[Log], Inactive[Cos], Inactive[Tan], Inactive[Log] } }

Note: order of occurrence and duplicacy must be maintained

Explanation of Order of sub expressions (also the order in which heads are removed to move to the next sub expression)

first the full expression

enter image description here

next the expression starting from the second level (Head Inactive[Sin] is removed)

enter image description here

next the two expressions at level 3 (Head Inactive[Log] is removed)

enter image description here

enter image description here

next the two expression at level 4 from left to right (next the Head Inactive[Cos] and then Inactive[Tan] is removed moving from left to right)

enter image description here

enter image description here

finally the two expressions at the last level from left to right (lastly the Head Inactive[Log] is removed to arrive at the last level)

enter image description here

enter image description here

This is the general order i want to have for sub expressions and the also the order of removal of Heads.

Can somebody help me with a function f such that it extract all sub expressions (i.e. looking down the expression tree) from any expression given to it and also a list of heads it encounters as it moves down the expression tree.

For example, f@(Sin[Log[Cos[a], Tan[Log[a, b]]]] // Inactivate) gives { { Inactive[Sin][Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]]], Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]], Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]], a, Inactive[Log][a,b], a, b }, { Inactive[Sin], Inactive[Log], Inactive[Cos], Inactive[Tan], Inactive[Log] } }

Note: order of occurrence and duplicacy must be maintained

Explanation of Order

first the full expression

enter image description here

next the expression starting from the second level

enter image description here

next the two expressions at level 3

enter image description here

enter image description here

next the two expression at level 4 from left to right

enter image description here

enter image description here

finally the two expressions at the last level from left to right

enter image description here

enter image description here

This is the general order i want to have.

Can somebody help me with a function f such that it extract all sub expressions (i.e. looking down the expression tree) from any expression given to it and also a list of heads it encounters as it moves down the expression tree.

For example, f@(Sin[Log[Cos[a], Tan[Log[a, b]]]] // Inactivate) gives { { Inactive[Sin][Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]]], Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]], Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]], a, Inactive[Log][a,b], a, b }, { Inactive[Sin], Inactive[Log], Inactive[Cos], Inactive[Tan], Inactive[Log] } }

Note: order of occurrence and duplicacy must be maintained

Explanation of Order of sub expressions (also the order in which heads are removed to move to the next sub expression)

first the full expression

enter image description here

next the expression starting from the second level (Head Inactive[Sin] is removed)

enter image description here

next the two expressions at level 3 (Head Inactive[Log] is removed)

enter image description here

enter image description here

next the two expression at level 4 from left to right (next the Head Inactive[Cos] and then Inactive[Tan] is removed moving from left to right)

enter image description here

enter image description here

finally the two expressions at the last level from left to right (lastly the Head Inactive[Log] is removed to arrive at the last level)

enter image description here

enter image description here

This is the general order i want to have for sub expressions and the also the order of removal of Heads.

added 616 characters in body
Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44

Can somebody help me with a function f such that it extract all sub expressions (i.e. looking down the expression tree) from any expression given to it and also a list of heads it encounters as it moves down the expression tree.

For example, f@(Sin[Log[Cos[a], Tan[Log[a, b]]]] // Inactivate) gives { { Inactive[Sin][Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]]], Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]], Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]], a, Inactive[Log][a,b], a, b }, { Inactive[Sin], Inactive[Log], Inactive[Cos], Inactive[Tan], Inactive[Log] } }

Note: order of occurrence and duplicacy must be maintained

Explanation of Order

first the full expression

enter image description here

next the expression starting from the second level

enter image description here

next the two expressions at level 3

enter image description here

enter image description here

next the two expression at level 4 from left to right

enter image description here

enter image description here

finally the two expressions at the last level from left to right

enter image description here

enter image description here

This is the general order i want to have.

Can somebody help me with a function f such that it extract all sub expressions (i.e. looking down the expression tree) from any expression given to it and also a list of heads it encounters as it moves down the expression tree.

For example, f@(Sin[Log[Cos[a], Tan[Log[a, b]]]] // Inactivate) gives { { Inactive[Sin][Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]]], Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]], Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]], a, Inactive[Log][a,b], a, b }, { Inactive[Sin], Inactive[Log], Inactive[Cos], Inactive[Tan], Inactive[Log] } }

Note: order of occurrence and duplicacy must be maintained

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Can somebody help me with a function f such that it extract all sub expressions (i.e. looking down the expression tree) from any expression given to it and also a list of heads it encounters as it moves down the expression tree.

For example, f@(Sin[Log[Cos[a], Tan[Log[a, b]]]] // Inactivate) gives { { Inactive[Sin][Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]]], Inactive[Log][Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]]], Inactive[Cos][a], Inactive[Tan][Inactive[Log][a, b]], a, Inactive[Log][a,b], a, b }, { Inactive[Sin], Inactive[Log], Inactive[Cos], Inactive[Tan], Inactive[Log] } }

Note: order of occurrence and duplicacy must be maintained

Explanation of Order

first the full expression

enter image description here

next the expression starting from the second level

enter image description here

next the two expressions at level 3

enter image description here

enter image description here

next the two expression at level 4 from left to right

enter image description here

enter image description here

finally the two expressions at the last level from left to right

enter image description here

enter image description here

This is the general order i want to have.

added 616 characters in body
Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44
Loading
added 90 characters in body
Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44
Loading
added 179 characters in body
Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44
Loading
added 118 characters in body
Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44
Loading
Source Link
user13892
  • 9.8k
  • 2
  • 15
  • 44
Loading