Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6325073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:49:36+00:00 2026-05-24T16:49:36+00:00

I would like to get a List (ideally a set — discarding repetition —

  • 0

I would like to get a List (ideally a set — discarding repetition — but assuming there’s no direct way to do this I’ll just use Union) of the leaves from a given expression.

For example, the expression

ArcTan[(-1 + 2*x)/Sqrt[3]]/Sqrt[3]

has a LeafCount of 18:

  • -1 (3)
  • 2 (3)
  • 3 (2)
  • x
  • ArcTan
  • Plus
  • Power (2)
  • Rational (2)
  • Times (3)

so I would like something like

{-1, 2, 3, x, ArcTan, Plus, Power, Rational, Times}

Actually, I really just want the functions so

{ArcTan, Plus, Power, Rational, Times}

would be ideal — but presumably there’s some not-too-difficult way to filter these when I have them.

I’ve had some luck with

H[s_] := If[LeafCount[s] == 1, s, Head[s]]
H /@ Level[expr, 1, Heads -> True]
H /@ Level[expr, 2, Heads -> True]
(* ... *)

but I feel like there must be a better way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:49:38+00:00Added an answer on May 24, 2026 at 4:49 pm

    Your own solution does not seem bad:

    expr = ArcTan[(-1 + 2*x)/Sqrt[3]]/Sqrt[3];
    
    H[s_] := If[LeafCount[s] == 1, s, Head[s]]
    
    H /@ Level[exp, -1, Heads -> True] // Union
    
    {-1, 2, 3, ArcTan, Plus, Power, Rational, Times, x}

    Brett Champion’s method is more streamlined, but I would change it a little:

    Union@Cases[expr, h_[___] :> h, {0, -1}]
    

    This way you pick up a top level head, such as ArcTan in:

    expr = ArcTan[(-1 + 2*x)/Sqrt[3]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to get a list of the wireless networks available. Ideally this
I would like to get collection or list of Item objects, but I get
Would like to get a list of advantages and disadvantages of using Stored Procedures.
I would like to get some information on list of points that needs to
I would like to get the first item from a list matching a condition.
I would like to be able to get a list of all possible files
I would like to get data from from different webpages such as addresses of
I would like to get up-to-date information on Google's index of a website, and
I would like to get the path to the execution directory of a Windows
I would like to get the absolute position of an element in relation to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.