Long time to find a definition or applicable library operation

29 views
Skip to first unread message

Kurt Pagani

unread,
Jan 4, 2020, 5:53:08 PM1/4/20
to FriCAS - computer algebra system
I've been confronted with the following oddness when accidentally a wrong entry (i.e. 1 instead of a symbol) is used:

(1) -> foo(L:List Symbol):OutputForm == first [outputForm(s)$OutputForm for s in L]

(2) -> foo [a,b,c,1]
   Compiling function foo with type List(Symbol) -> OutputForm
   Conversion failed in the compiled user function foo .

   Cannot convert the value from type List(Polynomial(Integer)) to List
      (Symbol) .

(4) -> foo [a,b,c,d,e,1]
   Conversion failed in the compiled user function foo .

   Cannot convert the value from type List(Polynomial(Integer)) to List
      (Symbol) .

(5) -> foo [a,b,c,d,e,f,1]
   Conversion failed in the compiled user function foo .

   Cannot convert the value from type List(Polynomial(Integer)) to List
      (Symbol) .

time needed grows exponentially with the length of the list !?
 foo [a,b,c,d,e,f,g,1] hangs already ...

This is an isolated example. The same occurs whether compiled or interpreted (as below).
What's going on?  

--- same

foo.spad
)abbrev domain FOO foo
foo() : Exports == Implementation where  
  Exports == with   
    mkfoo : Integer -> %
    dsp: (%,List Symbol) -> OutputForm   
  Implementation == Integer add
    Rep := Integer 
    mkfoo(x:Integer) == x@% 
    dsp(x:%,il:List Symbol):OutputForm ==
      l:List OutputForm := [outputForm(s)$OutputForm for s in il]
      first l

Example: dsp(5,[a,b,c,d,s,r])

foo.input:
dsp(x:Integer,il:List Symbol):OutputForm ==
  l:List OutputForm := [outputForm(s)$OutputForm for s in il]
  first l

Example: dsp(5,[a,b,c,d,5,5,t,s,r,s,s,s,s]) (killed after 1h)

Thanks
Kurt

oldk1331

unread,
Jan 5, 2020, 9:37:56 PM1/5/20
to fricas...@googlegroups.com
You can see what is happening by
")set message bottom on".

It seems to try various type conversions (involving polynomial types)
and fail eventually.

There are other places where a correct program needs long time to type
check.
In that case, adding additional explicit type hints/conversion helps.

- Qian
> --
> You received this message because you are subscribed to the Google
> Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to fricas-devel...@googlegroups.com
> <mailto:fricas-devel...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/fricas-devel/a9c97164-5fce-499b-a951-8cea68846b6f%40googlegroups.com
> <https://groups.google.com/d/msgid/fricas-devel/a9c97164-5fce-499b-a951-8cea68846b6f%40googlegroups.com?utm_medium=email&utm_source=footer>.

Ralf Hemmecke

unread,
Jan 6, 2020, 5:20:48 AM1/6/20
to fricas...@googlegroups.com
Indeed it's a problem with conversion. The following returns quickly

dsp(x, ['a,'b,'c,'d,'5,'5,'t,'s,'r,'s,'s,'s,'s])

The problem seems to be that you have the number 5 in your list.
If you evaluate [a,b,c,d,5,5,t,s,r,s,s,s,s] in a session, you get

(18) -> [a,b,c,d,5,5,t,s,r,s,s,s,s]

(18) [a, b, c, d, 5, 5, t, s, r, s, s, s, s]
Type: List(Polynomial(Integer))

You give FriCAS the task to figure out how to convert from Polynomial
Integer to Symbol.

(19) -> p := (a::Polynomial(Integer))

(19) a
Type: Polynomial(Integer)
(20) -> p::Symbol

(20) a
Type: Symbol
(21) -> q := (5::Polynomial(Integer))

(21) 5
Type: Polynomial(Integer)
(22) -> 5::Symbol

Cannot convert the value from type PositiveInteger to Symbol .

Ralf

Kurt Pagani

unread,
Jan 6, 2020, 11:22:44 AM1/6/20
to fricas...@googlegroups.com
Hi Qian, thank you! I wasn't aware of "bottom on". Now it's evident what's the
crux of the matter. Although I suspected something like this, I wouldn't expect
the interpreter being so persistent.
Quoting (as Ralf already suggested) helps, nevertheless it might be a pitfall.

Greetings
Kurt

Kurt Pagani

unread,
Jan 6, 2020, 12:11:46 PM1/6/20
to FriCAS - computer algebra system
Hi Ralf, thanks.
Perhaps I should have mentioned the origin: even with quoting and type hints it's quite error-prone.
I'm wondering if there is a possibility to limit (time) the process?
BTW the function name doesn't matter (foo instead of display etc.)

)abbrev domain IDXOBJ IndexedObject
IndexedObject() : Exports == Implementation where
   
  OF   ==> OutputForm
  LOF  ==> List OF
  INT  ==> Integer
  SYM  ==> Symbol
  CTOF ==> CoercibleTo OutputForm
  CTEX ==> ConvertibleTo TexFormat
 
  Exports == Join(CTOF, CTEX) with
 
    construct : List Integer -> %
    display : (%, Symbol, List Symbol) -> OutputForm
    coerce : List Integer -> %
   
  Implementation == add
 
    -- [n1,n2,...]; nj=+-1 ; +1:upper, -1:lower
    Rep := List Integer
   
    construct(x:List Integer):% ==
      empty? x => x
      x1:List Integer:=[abs n for n in x]
      x1 = [1 for m in 1..#x1] => x@%
      error "Expecting [+- 1, +- 1, +- 1, +- 1,...]"     
     
    coerce(x:List Integer):% ==
      empty? x => x
      x1:List Integer:=[abs n for n in x]
      --x1 = expand(1..#x1) => x@%
      x1 = [m for m in 1..#x1] => [sign n for n in x]@%
      error "Expecting [+- 1, +- 2, +- 3, +- 4,...]"
     
    label(x:%):List Integer == [n*x.n for n in 1..#x]
   
    display(x:%,b:Symbol,il:List Symbol):OF ==
      #x ~= #il => error "err ..."
      U:(INT,SYM)->OF:= (m,s)+->if m>0 then outputForm(s)$OF else hspace(1)$OF
      L:(INT,SYM)->OF:= (m,s)+->if m<0 then outputForm(s)$OF else hspace(1)$OF
      UX:OF:=hconcat [U(n,il.(abs n)) for n in label x]
      LX:OF:=hconcat [L(n,il.(abs n)) for n in label x]
      bas:OF:=outputForm(b)$OF
      scripts(bas, [LX,UX])$OF      

    coerce(x:%):OF ==
      S:List Symbol:=[string(n)$String::Symbol for n in 1..#x]
      display(x,'X,S)

---
   IndexedObject is now explicitly exposed in frame initial
   IndexedObject will be automatically loaded when needed from
      /Users/kfp/Desktop/work/spad/IDXOBJ.NRLIB/IDXOBJ

(2) -> display(J,'Q,['a,'b,'c,'d,'e,'f])
   There are 1 exposed and 0 unexposed library operations named display
      having 3 argument(s) but none was determined to be applicable.
      Use HyperDoc Browse, or issue
                             )display op display
      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
      display with argument type(s)
                                 Variable(J)
                                 Variable(Q)
                  List(OrderedVariableList([a,b,c,d,e,f]))
     
      Perhaps you should use "@" to indicate the required return type,
      or "$" to specify which version of the function you need.

(2) -> J:=[1,2,-3,4,-5,-6]::IDXOBJ

         12 4
   (2)  X
           3 56
                                                          Type: IndexedObject
(3) -> display(J,'Q,['a,'b,'c,'d,'e,'f])

         ab d
   (3)  Q
           c ef
                                                             Type: OutputForm
(4) -> display(K,Q::Symbol,['a,'b,'c,'d,'e,'f]@List Symbol)
   There are 1 exposed and 0 unexposed library operations named display
      having 3 argument(s) but none was determined to be applicable.
      Use HyperDoc Browse, or issue
                             )display op display
      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
      display with argument type(s)
                                 Variable(K)
                                   Symbol
                                List(Symbol)
     
      Perhaps you should use "@" to indicate the required return type,
      or "$" to specify which version of the function you need.

(4) -> -- takes 50s :(

Reply all
Reply to author
Forward
0 new messages