Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

You can actually Delete the head of the expression, which is part 0:

Delete[#, 0] & /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

With version 10 operator formsoperator forms:

Delete[0] /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

One case of interest may be held expressions. If our expression is:

expr = HoldComplete[2 + 2];

And the head we wish to remove is Plus, we cannot use these:

Identity @@@ expr
Sequence @@@ expr
expr /. Plus -> Identity
expr /. Plus -> Sequence
Replace[expr, _[x__] :> x, 1]

All produce e.g.:

HoldComplete[Identity[2, 2]]  (* or Sequence *)

We can use Delete or FlattenAt:

Delete[expr, {1, 0}]
FlattenAt[expr, 1]
HoldComplete[2, 2]
HoldComplete[2, 2]

You could also use a pattern that includes the surrounding expression on the right-hand-side, as demonstrated herehere, e.g.:

expr /. h_[_[x__]] :> h[x]
HoldComplete[2, 2]

Notes

As the documentation for Delete reads:

Deleting the head of a whole expression makes the head be Sequence.

Delete[Cos[a], 0]
Sequence[a]

Since this resolves to a in normal evaluation this should usually not be an issue.

You can actually Delete the head of the expression, which is part 0:

Delete[#, 0] & /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

With version 10 operator forms:

Delete[0] /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

One case of interest may be held expressions. If our expression is:

expr = HoldComplete[2 + 2];

And the head we wish to remove is Plus, we cannot use these:

Identity @@@ expr
Sequence @@@ expr
expr /. Plus -> Identity
expr /. Plus -> Sequence
Replace[expr, _[x__] :> x, 1]

All produce e.g.:

HoldComplete[Identity[2, 2]]  (* or Sequence *)

We can use Delete or FlattenAt:

Delete[expr, {1, 0}]
FlattenAt[expr, 1]
HoldComplete[2, 2]
HoldComplete[2, 2]

You could also use a pattern that includes the surrounding expression on the right-hand-side, as demonstrated here, e.g.:

expr /. h_[_[x__]] :> h[x]
HoldComplete[2, 2]

Notes

As the documentation for Delete reads:

Deleting the head of a whole expression makes the head be Sequence.

Delete[Cos[a], 0]
Sequence[a]

Since this resolves to a in normal evaluation this should usually not be an issue.

You can actually Delete the head of the expression, which is part 0:

Delete[#, 0] & /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

With version 10 operator forms:

Delete[0] /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

One case of interest may be held expressions. If our expression is:

expr = HoldComplete[2 + 2];

And the head we wish to remove is Plus, we cannot use these:

Identity @@@ expr
Sequence @@@ expr
expr /. Plus -> Identity
expr /. Plus -> Sequence
Replace[expr, _[x__] :> x, 1]

All produce e.g.:

HoldComplete[Identity[2, 2]]  (* or Sequence *)

We can use Delete or FlattenAt:

Delete[expr, {1, 0}]
FlattenAt[expr, 1]
HoldComplete[2, 2]
HoldComplete[2, 2]

You could also use a pattern that includes the surrounding expression on the right-hand-side, as demonstrated here, e.g.:

expr /. h_[_[x__]] :> h[x]
HoldComplete[2, 2]

Notes

As the documentation for Delete reads:

Deleting the head of a whole expression makes the head be Sequence.

Delete[Cos[a], 0]
Sequence[a]

Since this resolves to a in normal evaluation this should usually not be an issue.

added 163 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

You can actually Delete the head of the expression, which is part 0:

Delete[#, 0] & /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

With version 10 operator forms:

Delete[0] /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

One case of interest may be held expressions. If our expression is:

expr = HoldComplete[2 + 2];

And the head we wish to remove is Plus, we cannot use these:

Identity @@@ expr
Sequence @@@ expr
expr /. Plus -> Identity
expr /. Plus -> Sequence
Replace[expr, _[x__] :> x, 1]

All produce e.g.:

HoldComplete[Identity[2, 2]]  (* or Sequence *)

We can use Delete or FlattenAt:

Delete[expr, {1, 0}]
FlattenAt[expr, 1]
HoldComplete[2, 2]
HoldComplete[2, 2]

You could also use a pattern that includes the surrounding expression on the right-hand-side, as demonstrated here, e.g.:

expr /. h_[_[x__]] :> h[x]
HoldComplete[2, 2]

Notes

As the documentation for Delete reads:

Deleting the head of a whole expression makes the head be Sequence.

Delete[Cos[a], 0]
Sequence[a]

Since this resolves to a in normal evaluation this should usually not be an issue.

You can actually Delete the head of the expression, which is part 0:

Delete[#, 0] & /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

One case of interest may be held expressions. If our expression is:

expr = HoldComplete[2 + 2];

And the head we wish to remove is Plus, we cannot use these:

Identity @@@ expr
Sequence @@@ expr
expr /. Plus -> Identity
expr /. Plus -> Sequence
Replace[expr, _[x__] :> x, 1]

All produce e.g.:

HoldComplete[Identity[2, 2]]  (* or Sequence *)

We can use Delete or FlattenAt:

Delete[expr, {1, 0}]
FlattenAt[expr, 1]
HoldComplete[2, 2]
HoldComplete[2, 2]

You could also use a pattern that includes the surrounding expression on the right-hand-side, as demonstrated here, e.g.:

expr /. h_[_[x__]] :> h[x]
HoldComplete[2, 2]

Notes

As the documentation for Delete reads:

Deleting the head of a whole expression makes the head be Sequence.

Delete[Cos[a], 0]
Sequence[a]

Since this resolves to a in normal evaluation this should usually not be an issue.

You can actually Delete the head of the expression, which is part 0:

Delete[#, 0] & /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

With version 10 operator forms:

Delete[0] /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

One case of interest may be held expressions. If our expression is:

expr = HoldComplete[2 + 2];

And the head we wish to remove is Plus, we cannot use these:

Identity @@@ expr
Sequence @@@ expr
expr /. Plus -> Identity
expr /. Plus -> Sequence
Replace[expr, _[x__] :> x, 1]

All produce e.g.:

HoldComplete[Identity[2, 2]]  (* or Sequence *)

We can use Delete or FlattenAt:

Delete[expr, {1, 0}]
FlattenAt[expr, 1]
HoldComplete[2, 2]
HoldComplete[2, 2]

You could also use a pattern that includes the surrounding expression on the right-hand-side, as demonstrated here, e.g.:

expr /. h_[_[x__]] :> h[x]
HoldComplete[2, 2]

Notes

As the documentation for Delete reads:

Deleting the head of a whole expression makes the head be Sequence.

Delete[Cos[a], 0]
Sequence[a]

Since this resolves to a in normal evaluation this should usually not be an issue.

deleted 354 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

You can actually Delete the head of the expression, which is part 0:

Delete[#, 0] & /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

One case of interest may be held expressions. If our expression is:

expr = HoldComplete[2 + 2];

And the head we wish to remove is Plus, we cannot use these:

Identity @@@ expr
Sequence @@@ expr
expr /. Plus -> Identity
expr /. Plus -> Sequence
Replace[expr, _[x__] :> x, 1]

All produce e.g.:

HoldComplete[Identity[2, 2]]  (* or Sequence *)

We can use Delete or FlattenAt:

Delete[expr, {1, 0}]
FlattenAt[expr, 1]
HoldComplete[2, 2]
HoldComplete[2, 2]

You could also use a pattern that includes the surrounding expression on the right-hand-side, as demonstrated here, e.g.:

expr /. h_[_[x__]] :> h[x]
HoldComplete[2, 2]

Notes

  1. Be aware that when there is no surrounding expression Sequence will appear in the output:

     Delete[Cos[a], 0]
    
    Sequence[a]
    

    Since this resolves to a in normal evaluation this should usually not be an issue.

  2. The documentation for Delete reads:

    Deleting the head of a whole expression makes the head be Sequence. »

    This is incorrect, at least as I read it, as demonstrated by my example using HoldComplete[2 + 2]. Since HoldComplete will hold Sequence expressions if this were true Sequence would appear in the output but it does not.

As the documentation for Delete reads:

Deleting the head of a whole expression makes the head be Sequence.

Delete[Cos[a], 0]
Sequence[a]

Since this resolves to a in normal evaluation this should usually not be an issue.

You can actually Delete the head of the expression, which is part 0:

Delete[#, 0] & /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

One case of interest may be held expressions. If our expression is:

expr = HoldComplete[2 + 2];

And the head we wish to remove is Plus, we cannot use these:

Identity @@@ expr
Sequence @@@ expr
expr /. Plus -> Identity
expr /. Plus -> Sequence
Replace[expr, _[x__] :> x, 1]

All produce e.g.:

HoldComplete[Identity[2, 2]]  (* or Sequence *)

We can use Delete or FlattenAt:

Delete[expr, {1, 0}]
FlattenAt[expr, 1]
HoldComplete[2, 2]
HoldComplete[2, 2]

You could also use a pattern that includes the surrounding expression on the right-hand-side, as demonstrated here, e.g.:

expr /. h_[_[x__]] :> h[x]
HoldComplete[2, 2]

Notes

  1. Be aware that when there is no surrounding expression Sequence will appear in the output:

     Delete[Cos[a], 0]
    
    Sequence[a]
    

    Since this resolves to a in normal evaluation this should usually not be an issue.

  2. The documentation for Delete reads:

    Deleting the head of a whole expression makes the head be Sequence. »

    This is incorrect, at least as I read it, as demonstrated by my example using HoldComplete[2 + 2]. Since HoldComplete will hold Sequence expressions if this were true Sequence would appear in the output but it does not.

You can actually Delete the head of the expression, which is part 0:

Delete[#, 0] & /@ {Cos[a], Sin[b], Tan[c]}
{a, b, c}

One case of interest may be held expressions. If our expression is:

expr = HoldComplete[2 + 2];

And the head we wish to remove is Plus, we cannot use these:

Identity @@@ expr
Sequence @@@ expr
expr /. Plus -> Identity
expr /. Plus -> Sequence
Replace[expr, _[x__] :> x, 1]

All produce e.g.:

HoldComplete[Identity[2, 2]]  (* or Sequence *)

We can use Delete or FlattenAt:

Delete[expr, {1, 0}]
FlattenAt[expr, 1]
HoldComplete[2, 2]
HoldComplete[2, 2]

You could also use a pattern that includes the surrounding expression on the right-hand-side, as demonstrated here, e.g.:

expr /. h_[_[x__]] :> h[x]
HoldComplete[2, 2]

Notes

As the documentation for Delete reads:

Deleting the head of a whole expression makes the head be Sequence.

Delete[Cos[a], 0]
Sequence[a]

Since this resolves to a in normal evaluation this should usually not be an issue.

added 23 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading
added 380 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading
added 188 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading