Re: Re(2): assumption, supposition?
- To: mathgroup at smc.vnet.net
- Subject: [mg15378] Re: [mg15375] Re(2): [mg15331] assumption, supposition?
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Tue, 12 Jan 1999 03:14:43 -0500
- Sender: owner-wri-mathgroup at wolfram.com
My last message below contained a few misprints which make the code unusable unless they are corrected. The correct definition of cond is: cond[expr_List,var_]:= SemialgebraicComponents[Join[expr,given],var]== SemialgebraicComponents[given,var] and the correct definition of sqrt consists of two statements: sqrt[x_^2/;cond[{x>0},variables]]:=x; sqrt[x_]:=Sqrt[x] On Sat, Jan 9, 1999, Andrzej Kozlowski <andrzej at tuins.ac.jp> wrote: >Pattern matching clearly is unsuitable for your purpose, since it >involves no deductions just mere "blind" substitution. However, one can >easily implement simple "deduction" of the kind you seem to want in >Mathematica, by making use of its ability to solve inequalities. There >are two p-ackages for this purpose, Algebra`InequalitySolve` and >Algebra`AlgebraicInequalities`. However, the former one is limited only >to inequalities in one variable, so the latter one seems to be the >right one to use here. I have written some code which, seems to me, to >do the sort of thing that you might want. It is rather clumsy and very >imperfect as I spent only minutes on writing it. It's only meant to >suggest the kind of thing that can be done. I hope that some real >expert on these matters might be induced to comment, and perhaps even >to develop a real package that will properly do what I am only hinting >at. Anyway, here is the idea. >First we load the Inequality Solving package. > >In[1]:= ><<Algebra`AlgebraicInequalities` > >Next we define the function we shall use for testing conditions: > >In[2]:= >cond[expr_List,var_]:= > SemialgebraicComponents[Join[eepr,given],var]== > SemialgebraicComponents[given,var] > >This function has two parameters: a list of conditions (inequalities) to >be tested and a list of variables var. It depends on one global >variable, given, which is also a list of inequalities. What cond does >is to join the inequalities in expr to those in given and check if the >solution of the joint set is the same as that of given alone. If this >is the case than the conditions in expr forllow from those in given and >are thus satisifed.This is how it works. We first set a value for >given. > > >In[3]:= >given={x>0,y>1} >Out[3]= >{x>0,y>1} >Next we test if x+y>1 follows from "given". In[4]:= >cond[{x+y>1},{x,y}] >Out[4]= >True > >On the other hand x+y>2 does not follow: In[5]:= >cond[{x+y>2},{x,y}] >Out[5]= >False > >Next, we can define sqrt a replacement for Sqrt which will do what you >wanted. Really, of course, one should do this with Power, but I shan't >bother. Also, I introduce another global variable, variables, which >probably is bad programming style, but again since this is only meant >as an illustration I shall not try to make it nicer: > >In[4]:= >sqrt[x_^2/;cond[{x>0},variables]]:=x sqrt[x_]:=Sqrt[x] > >Now we assign values to our global variables: > >given={x>0,v>x,w>x+1}; >variables={x,v,w}; > >We can see that sqrt behaves correctly on values which it knows as being >>0: In[5]:= >sqrt[w^2] >Out[5]= >w > >On the other hand, in the case of variables it does not know anything >about it behaves as before: >In[6]:= >sqrt[u^2] >Out[6]= > 2 >Sqrt[u ] > > >Andrzej > > > >On Fri, Jan 8, 1999, Erk Jensen <Erk.Jensen at cern.ch> wrote: > >>Probably I'm looking up the wrong keyword in Mathematica help, but I >>can't find what I'm looking for. Maybe that's because I've learned >>those expressions in german... >> >>My problem: >> >>I want Mathematica to assume that a certain condition is satisfied for >>the following algebraic transformations. More specifically: Let rho >>describe a radius coordinate. I know it is not negative real. So, for >>transformations of expressions containing rho, e.g. Sqrt[rho^2], I >>want assure Mathematica that 0 <= rho is in fact satisfied, and that it >>is consequently allowed to replace Sqrt[rho^2] by rho. How do I do >>that? >> >>My solution was >> >>Unprotect[Sqrt]; Sqrt[rho_^2] := rho/; 0 <= rho; Protect[Sqrt]; >> >>rho /: 0 <= rho = True; >> >>and this seems to work, but I wonder whether this is really the proper >>way. Since the TagSet I'm using here assigns the whole statement to >>rho, and ?rho results in >> >>Global`rho >>rho /: 0 <= rho = True >> >>so I still have my doubts ... >> >>Can some of you experts enlighten me? >> >>Thanks in advance >> -erk- > >>Andrzej Kozlowski wrote: >>> >>> It seems to me there is nothing wrong with what you are doing, but it is >>> rather limited. While indeed Sqrt[rho^2] will now return rho, >>> (rho^2)^(1/2) , (rho^3)^(1/3) will all behave as before. So you need to >>> modify the behaviour of Power rather than Sqrt. However, it seems to me >>> that the simplest way to achieve what you want is by using Abs[rho] in >>> place of rho in your formulas and then replacing Abs[rho] by rho in the >>> final output. Mathematica knows that (Abs[rho]^2)^(1/2) is Abs[rho] etc. >>> >> >>Thanks for your remark! >>1st part: it's even worse: if I set "rho /: 0 <= rho = True;" it will >>recognize >>0 <= rho as True, but not "rho >= 0" (!) so it doesn't actually do the >>checking, it just >>replaces "0 <= rho" by true. >> >>2nd part: this wouldn't help if my allowed range for rho would be say rho0 <= >>rho <= rho2! >>Which is actually what I have. >> >>I think I may go on with PowerExpand[Sqrt[x^2]] after all, that also >works for >>your >>examples ... but it's not exactly what I want. What I really want is best >>described by the >>option "Assumptions" of "Integrate"! >> >>Best regards, >> -erk- >> > > >Andrzej Kozlowski >Toyama International University >JAPAN >http://sigma.tuins.ac.jp/ >http://eri2.tuins.ac.jp/ > Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/ http://eri2.tuins.ac.jp/