Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I need to specify that a variable is less than another, and greater than yet another, in a Mathematica program, because I will later apply a test to them that will determine what functional form to use. I also need Sign[] to give the correct answer. I tried using TagSet like this:

h /: (h>=d0) = True
h /: (h<=d1) = True

but this does not work with Sign[h-d0], for example, and

h /: Sign[h - d0] = 1;

fails because it says h is too deep.

An example of how I will use this:

f[x_] := Exp[ c Sign[h-x] ]

where x can take the values d0 or d1. (This will be used to set up boundary relations to solve for a set of coefficients to solve a PDE.) I suppose I could use some If statements to set the whole thing up, but thought it would be nicer to have a specification of the properties of h.

I'm sure this should be easy to do - any help is appreciated.

share|improve this question
    
Maybe you could just rescale $x$ to $\xi =x/h$, so you can work on ${\mathrm{sgn}}(1-\xi)$. –  Silvia Aug 18 '12 at 16:05
    
is it for numeric or analytic solution of PDE? –  Vitaliy Kaurov Aug 18 '12 at 16:23
    
Unprotect[Sign]; Sign[h - d0] = 1; –  Rolf Mertig Aug 18 '12 at 18:09

1 Answer 1

up vote 9 down vote accepted

Refine with assumptions might be useful. Quick example:

In[2]:= $Assumptions = x < y < z;

In[3]:= Refine[{Sign[x - y], Sign[z - x]}]

Out[3]= {-1, 1}
share|improve this answer
    
Thanks, Daniel, that's what I had in mind. I want the variable to acquire the property, so I can rely on it being evaluated properly in different contexts (If[h > d0, ...], or Sign[h-d0], etc). What I'm doing is having Mathematica solve a set of equations that are set up for a layered medium, where the behavior of some functions depends on whether the layer is above or below the source. I'll vote you up when I get the points! –  Tom Dickens Aug 19 '12 at 2:59
    
@TomDickens Sometimes it is better to use assumptions locally, e.g. Refine[{Sign[x - y], Sign[z - x]}, Assumptions -> x < y < z]. You might find useful answers to these questions : mathematica.stackexchange.com/questions/2404/… and mathematica.stackexchange.com/questions/4973/… –  Artes Aug 19 '12 at 19:36
1  
@TomDickens Pay attention to the difference between the second argument between Refine[expr,Assumptions ->assum], and Refine[expr, assum] e.g. see the documentatio of Refine. –  Artes Aug 19 '12 at 19:47
    
@Artes - Thanks for the valuable comments. My code is working now! Tom –  Tom Dickens Aug 20 '12 at 3:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.