Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9586 > unrolled thread
| Started by | "wb@wavebounce.com" <rob@wavebounce.com> |
|---|---|
| First post | 2012-04-13 08:48 +0000 |
| Last post | 2012-04-14 07:11 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Deleting expressions containing a certain head "wb@wavebounce.com" <rob@wavebounce.com> - 2012-04-13 08:48 +0000
Re: Deleting expressions containing a certain head A Retey <awnl@gmx-topmail.de> - 2012-04-14 07:11 +0000
| From | "wb@wavebounce.com" <rob@wavebounce.com> |
|---|---|
| Date | 2012-04-13 08:48 +0000 |
| Subject | Re: Deleting expressions containing a certain head |
| Message-ID | <jm8p89$ip5$1@smc.vnet.net> |
I'm not sure this quite meets the challenge. For example, Exp[I Pi} is not Complex but it "has a complex number in it" and appears in the output. Perhaps this is as it should be.
> Getting rid of any expression that has a complex number in it.
>
> How does one go about this?
>
list = {2^(Complex[2, 3]) + 3, 2, 3 x};
Select[list, FreeQ[#, Complex] &]
hth,
albert
[toc] | [next] | [standalone]
| From | A Retey <awnl@gmx-topmail.de> |
|---|---|
| Date | 2012-04-14 07:11 +0000 |
| Message-ID | <jmb7u6$r1v$1@smc.vnet.net> |
| In reply to | #9586 |
Hi,
> I'm not sure this quite meets the challenge.For example, Exp[I Pi}
> is not Complex but it "has a complex number in it" and appears in the
> output. Perhaps this is as it should be.
>
> list = {2^(Complex[2, 3]) + 3, 2, 3 x};
>
> Select[list, FreeQ[#, Complex]&]
>
You are of course right that pattern matching for Head Complex might not
be a robust method to match expressions that "have complex numbers in
them". For your example it is a matter of evaluation order, though.
Exp[I Pi] will be evaluated to -1 even before Select sees it, so I don't
think it is a valid counter example unless it is provided as a held
expression, like here:
Select[{a,1+I,Hold[Exp[I Pi]]},FreeQ[#, Complex] &]
one could make that work with e.g.:
Select[{a,1+I,Hold[Exp[I*Pi]]},FreeQ[#,Complex|HoldPattern[I]] &]
Note that we need HoldPattern here since otherwise I will immediately be
evaluated to Complex[0,1]. But of course when working with unevaluated
symbolic expressions the task "remove expressions that have complex
numbers in them" is probably not very well specified anyway. I think for
a great many use cases (probably even all where the task is meaningful
at all) the approach with checking for the appearance of head Complex
might be valid.
In the end it's of course for the OP to decide whether that is what he
wanted. I understood his question was about removing expressions
containing a certain head. If his ultimate goal was to remove
expressions "which have a complex number in it" your warning is
reasonable and the OP probably wants to make sure that this approach is
good enough for his use case.
cheers,
albert
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web