7
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Maybe you could just rescale $x$ to $\xi =x/h$, so you can work on ${\mathrm{sgn}}(1-\xi)$. $\endgroup$ Commented Aug 18, 2012 at 16:05
  • $\begingroup$ is it for numeric or analytic solution of PDE? $\endgroup$ Commented Aug 18, 2012 at 16:23
  • $\begingroup$ Unprotect[Sign]; Sign[h - d0] = 1; $\endgroup$ Commented Aug 18, 2012 at 18:09

1 Answer 1

9
$\begingroup$

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} 
$\endgroup$
4
  • $\begingroup$ 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! $\endgroup$ Commented Aug 19, 2012 at 2:59
  • $\begingroup$ @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/… $\endgroup$ Commented Aug 19, 2012 at 19:36
  • 1
    $\begingroup$ @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. $\endgroup$ Commented Aug 19, 2012 at 19:47
  • $\begingroup$ @Artes - Thanks for the valuable comments. My code is working now! Tom $\endgroup$ Commented Aug 20, 2012 at 3:17

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.