Re: Condition for pure functions
- To: mathgroup at smc.vnet.net
- Subject: [mg59808] Re: [mg59797] Condition for pure functions
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Mon, 22 Aug 2005 02:48:28 -0400 (EDT)
- Organization: Mathematics & Statistics, Univ. of Mass./Amherst
- References: <200508210751.DAA26612@smc.vnet.net>
- Reply-to: murray at math.umass.edu
- Sender: owner-wri-mathgroup at wolfram.com
Perhaps the following?
( UnitStep[#] Sin[#] + (1 - UnitStep[#]) Tan[#] )&
Better than your version with Which, you could use Piecewise, as in:
Piecewise[{{Tan[#], # < 0}, {Sin[#], # â?¥ 0}}] &
(Piecewise may handled better by other functions than Which).
Wonseok Shin wrote:
> Hello everyone,
>
> Suppose that f[x] is defined as:
>
> f[x_ /; x > 0] := Sin[x];
> f[x_ /; x <= 0] := Tan[x];
>
> How can transform the above definition into a pure function?
>
> I know
>
> f = Which[# > 0, Sin[#], # <= 0, Tan[#]] &
>
> is a one solution. But is there any clever way to use Condition (/;)
> instead of Which[...] ?
>
>
--
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
- References:
- Condition for pure functions
- From: "Wonseok Shin" <wssaca@gmail.com>
- Condition for pure functions