home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!news.service.uci.edu!network.ucsd.edu!sdcc12!oba!mstankus
- From: mstankus@oba.ucsd.edu (Mark Stankus)
- Newsgroups: sci.math.symbolic
- Subject: Inequalities posting: Convert1.m
- Message-ID: <41348@sdcc12.ucsd.edu>
- Date: 20 Nov 92 19:34:37 GMT
- References: <41345@sdcc12.ucsd.edu>
- Sender: news@sdcc12.ucsd.edu
- Organization: Mathematics @ UCSD
- Lines: 93
- Nntp-Posting-Host: oba.ucsd.edu
-
- (* :Title: Convert1 // Mathematica 2.0 *)
-
- (* :Author: Mark Stankus (mstankus).
- Based on the work of David Hurst (dhurst)
- in the file NCTools.m
- *)
-
- (* :Context: Convert1` *)
-
- (* :Summary:
- Convert1 is similar to Convert1, but only works
- for commutative expressions. Convert1 does
- not depend on any NCAlgebra code.
- *)
-
- (* :Alias:
- *)
-
- (* :Warnings:
- *)
-
- (* :History:
- :8/26/92 Wrote code. (mstankus)
- :10/18/92 Adapted Convert1 from Convert2. (mstankus)
- *)
- BeginPackage["Convert1`"];
-
- Clear[Convert1];
-
- Convert1::usage =
- "Convert1[expr] is a variant of Convert1[expr] which is \
- recursive and follows a slightly different ordering.";
-
- Begin["`Private`"];
-
- (*
- Change input given in the wrong format to the
- correct format with a head of Equal.
- *)
- Convert1[x_Plus] := Convert1[x==0];
-
- Convert1[x_Rule] := Convert1[x[[1]]==x[[2]]];
-
- Convert1[x_RuleDelayed] := Convert1[x[[1]]==x[[2]]];
-
- Convert1[x_List] := Map[Convert1,x];
-
- Convert1[True] :=
- Module[{},
- Print["Warning from Convert1: Converting True"];
- Return[0->0]
- ];
-
- Convert1[False] :=
- Module[{},
- Print[" :-( Severe Warning from Convert1: Converting False"];
- Abort[];
- Return[0->0]
- ];
-
- (*
- The important code.
- *)
- Convert1[x_Equal]:= Convert1[Equal[x[[1]]-x[[2]],0]] /; Not[x[[2]]===0]
-
- Convert1[x_Equal]:=
- Module[{expr,expr2,orderedlist,left,right,coeff,
- var,temp},
- expr = Expand[x[[1]]];
- If[Head[expr]===Plus,expr2 = Apply[List,expr];
- ,expr2 = {expr};
- ];
- orderedlist = Sort[expr2];
- left = orderedlist[[-1]];
- right = -expr + left;
- If[Head[left]==Times, coeff= left[[1]];
- left = left/coeff;
- right = right/coeff;
- ];
- var = Unique[];
- temp = right/.left->right;
- If[Not[FreeQ[temp,var]],
- Print["Using the rule ",left->right];
- Print["leads to an infinite loop."];
- ];
- Return[left->right]
- ] /; x[[2]]===0
-
- End[];
- EndPackage[]
- --
- mstankus
- mstankus@oba
-