home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   sci.math.symbolic      Symbolic algebra discussion      10,432 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 9,122 of 10,432   
   oldk1331@gmail.com to All   
   Re: How should software compare complex    
   25 Jul 16 09:27:09   
   
   > 1.  It seems to me that you cannot always give a compile time error...   
   > Given an expression:   max(sqrt(X), Y).   
      
   But, when you want to compile a file for Axiom/FriCAS, you are in   
   library writing mode (in contrast with REPL mode), so everything   
   you write must have a type annotation like Haskell (see following   
   example).   
      
   By the time of writing "max(sqrt(X), Y)", compiler already knows the   
   type of X and Y, thus it can type checking sqrt(X), then type checking   
   max(...).   
      
   > Could you construct a minimal example of a program that has this error   
      
   Writing libraries for Axiom/FriCAS can be a bit verbose:   
      
   ---- example starts ----   
   )abbrev package TEST1 Test1   
   Test1(T: OrderedSet) : Exports == Implementation where   
     Exports == with   
       testmax1 : (T, T) -> T   
       testmax2 : (Integer, Complex Integer) -> Complex Integer   
     Implementation == add   
       testmax1(x,y) == max(x,y)   
       testmax2(x,y) == max(x,y)   
   ---- example ends ----   
      
   testmax1 is how you use max correctly: you declare x and y are of   
   type T which is OrderedSet.   
      
   testmax2 will fail at compile time:   
   ====== compile time error message ====   
      compiling exported testmax2 : (Integer,Complex Integer) -> Complex Integer   
   ****** comp fails at level 1 with expression: ******   
   error in function testmax2   
      
   ((|max| |x| |y|))   
   ****** level 1  ******   
   $x:= (max x y)   
   $m:= (Complex (Integer))   
   $f:=   
   ((((|y| # . #1=#) (|x| # . #2=#) (|y| . #1#) (|x| . #2#) ...)))   
      
      >> Apparent user error:   
      cannot compile (max x y)   
   ====== message ends =====   
      
   Invoke "testmax1(1,sqrt(-1))" in REPL gives this error:   
   ==== error message ====   
      There are 1 exposed and 0 unexposed library operations named testmax   
         having 2 argument(s) but none was determined to be applicable.   
         Use HyperDoc Browse, or issue   
                                )display op testmax   
         to learn more about the available operations. Perhaps   
         package-calling the operation or using coercions on the arguments   
         will allow you to apply the operation.   
      
      Cannot find a definition or applicable library operation named   
         testmax with argument type(s)   
                                  PositiveInteger   
                                  AlgebraicNumber   
      
         Perhaps you should use "@" to indicate the required return type,   
         or "$" to specify which version of the function you need.   
   ==== message ends ====   
      
   Another interesting note: Axiom/FriCAS can't do "max(1,sqrt(1))"   
   directly:   
      
   That's because by default sqrt(1) is of type AlgebraicNumber, and   
   no algorithm can compare any AlgebraicNumbers.   
      
   BUT, what you really want to do is to compare Integer and Roots of   
   Polynomials?  Then you are in the Domain of RealClosure:   
      
   sqrt1 := rootOf((x^2-1)::SUP FRAC INT,1)$RECLOS(FRAC INT)   
   max(1,sqrt1) -- gives 1   
      
   You can compare symbolic roots of polynomials in this RECLOS.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca