Mathematica Mathematica : Pulling inputs from a function; methodology question.

AI Thread Summary
The discussion revolves around creating a replacement rule for a custom Heaviside function, HeavisideTheta, which takes an arbitrary number of function inputs. The goal is to transform the HeavisideTheta function into a series of "If" statements based on its inputs. Initially, the user sought a method to express the HeavisideTheta function as a product of conditional statements for each input. After some clarification and adjustments to the syntax, a solution was proposed that utilizes an array format to achieve the desired output. The final replacement rule successfully converts HeavisideTheta[a, b, c] into a product of "If" statements, effectively checking each input for positivity.
Hepth
Science Advisor
Gold Member
Messages
457
Reaction score
40
I have a heaviside function:

Code:
HeavisideTheta[a,b,c,d,e,...]

where the letters correspond to functions, and the number of functions is arbitrary.

I want to make a replacement so that
Code:
HeavisideTheta[a_]:> If[a>0,1,0]
HeavisideTheta[a_,b_]:>If[a>0,1,0] If[b>0,1,0]
or something similar.
I wish to take the inputs to the heaviside function, and create an "If" statement out of them.

So if I have a function that contains this HeavisideTheta, I can do a replacement as:

Code:
F[x,y]/.{HeavisideTheta[a__]:> Product[If[a[[i]]>0,1,0],{i,1,Length[a]}]
(though that obviously won't work)Any suggestions?
 
Last edited:
Physics news on Phys.org
Hepth said:
Any suggestions?

You could tidy up your post so that it's readable!
 
PeroK said:
You could tidy up your post so that it's readable!

Is that any better?
 
I solved it, you use the sequence inside of a bracket to make it an array:

Code:
HeavisideTheta[a, b, c] /. {HeavisideTheta[a__] :> Product[If[{a}[[i]] > 0, 1, 0], {i, 1, Length[{a}]}]}
gives
Code:
If[a > 0, 1, 0] If[b > 0, 1, 0] If[c > 0, 1, 0]
 

Similar threads

Replies
4
Views
2K
Replies
5
Views
5K
Replies
3
Views
2K
Replies
14
Views
7K
Replies
15
Views
2K
Back
Top