I've noticed that FriCAS doesn't have a numerical implementation of 
polylog's yet.
So I will have to interface some C/Fortran code. For that I have 
constructed a small
example:

test.c:
void testfun(double arg, double* realpart, double* imagpart)
{
    *realpart = 1.0 * arg;
    *imagpart = 3.14 * arg;
    return;
}
gcc -shared -o libtest.so test.c

test.lsp:
(sb-alien:load-shared-object "./libtest.so")
(defun testfun (arg)
    (sb-alien:with-alien ((repart (double-float) 0.0d0) (impart 
(double-float) 0.0d0))
        (sb-alien:alien-funcall
          (sb-alien:extern-alien "testfun" (sb-alien:function sb-alien:void 
(double-float) (* double-float) (* double-float)))
          arg (sb-alien:addr repart) (sb-alien:addr impart)
         )
        (complex repart impart)
    )
)

And I can successfully use that function within sbcl:
sbcl --load "test.lsp"
(testfun 10.0d0)
#C(10.0d0 31.400000000000002d0)

Within FriCAS I ran ")lisp (load "test.lsp")" and it
seems to parse/load the file successfully, but I can't directly use that 
function, i.e.  (testfun 10.0d0) within ")fin", and neither from within 
FriCAS as TESTFUN(1$DoubleFloat)$Lisp:

debugger invoked on a TYPE-ERROR in thread
#<THREAD "main thread" RUNNING {1002410103}>:
  The value
    0.0d0
  is not of type
    (SB-ALIEN:ALIEN (* T))
  from the function type declaration.

As it turns out, somehow I can not give it an initial value here, and I 
just have to declare it with (repart (double-float)), which is fine, but I 
am wondering why.

The final step for me is to convert the SExpression into a FriCAS 
Complex(DoubleFloat). For that I looked into the SExpression domain, and it 
seems to be easiest to instead return (list repart impart) and then have 
something like: 

testfun(xx) == 
    res := TESTFUN(xx :: DoubleFloat)$Lisp
    complex(float car res, float car cdr res) 

Presumably I could convert this into Complex(DoubleFloat) within the Lisp 
code directly with some SPADCALL calls? But the current way seems to be 
perfectly fine, but I am wondering if this is the right/recommended way to 
do it. Overall I'm really happy how easy this turned out to be.

Thanks,
Tobias

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/5eb8ad23-5c3e-4b0b-8810-9cccdc42d999n%40googlegroups.com.

Reply via email to