calling FriCAS functions from Lisp

41 views
Skip to first unread message

Dima Pasechnik

unread,
Apr 20, 2024, 5:47:02 AM4/20/24
to FriCAS - computer algebra system
How does one do this?
(with ECL or SBCL).

Presumably if one makes a FriCAS fasl library (how?), it should be possible to call FriCAS functions from Lisp without going through files or pipes.

That's certainly possible (and used in Sage) with Maxima.

Thanks
Dima

 

Qian Yun

unread,
Apr 20, 2024, 5:58:37 AM4/20/24
to fricas...@googlegroups.com
There is https://github.com/oldk1331/fricas0,
where fricas exists in the form of pure lisp,
but it is not in the sense of a "traditional lisp library"
by ASDF or DEFPACKAGE.

I can look into this direction.

- Qian

Dima Pasechnik

unread,
Apr 20, 2024, 6:21:36 AM4/20/24
to fricas...@googlegroups.com
On Sat, Apr 20, 2024 at 10:58 AM Qian Yun <oldk...@gmail.com> wrote:
There is https://github.com/oldk1331/fricas0,
where fricas exists in the form of pure lisp,
but it is not in the sense of a "traditional lisp library"
by ASDF or DEFPACKAGE.

I can look into this direction.

Thanks. Yes, please, ASDF/DEFPACKAGE.
This would be a step towards a possibility to call SBCL FriCAS from C or Python or others, via
(something that would speed up interfaces, such as Sage's interface to FriCAS).

Dima


- Qian

On 4/20/24 17:47, Dima Pasechnik wrote:
> How does one do this?
> (with ECL or SBCL).
>
> Presumably if one makes a FriCAS fasl library (how?), it should be possible
> to call FriCAS functions from Lisp without going through files or pipes.
>
> That's certainly possible (and used in Sage) with Maxima.
>
> Thanks
> Dima
>
>   
>

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/f325257c-70b5-47a0-8eb7-b7d9411cee3c%40gmail.com.

Waldek Hebisch

unread,
Apr 20, 2024, 7:48:43 AM4/20/24
to fricas...@googlegroups.com
Look at 'contrib/load-fricas.lisp' and 'contrib/mk_shlib.lisp'.
'contrib/mk_shlib.lisp' makes ECL .fas (really a C shared library).
Currently 'contrib/load-fricas.lisp' is broken with sbcl, one needs to
add an extra line loading GMP support (I will fix this shortly,
after more testing). In both cases usage has changed a bit: one
needs to set FRICAS environment variable to location of build tree.
Both files contain instructions about use.

--
Waldek Hebisch

Martin R

unread,
Apr 20, 2024, 8:33:56 AM4/20/24
to FriCAS - computer algebra system
Dear all & especially Dima!

Here is a thread from a previous attempt that might be useful:


I think it would be best to start with an ECL interface, I would expect this to be easier and would probably cover a lot of use cases.

I think that the basic design of the current interface is not so bad, it works relatively reliably.  It should be easy to rewrite it so that FriCASElement_parse_and_eval is replaced by traversing the InputForm directly, instead of converting it to a string.  This would solve all the memory problems.

Best wishes,

Martin

Dima Pasechnik

unread,
Apr 20, 2024, 4:18:13 PM4/20/24
to FriCAS - computer algebra system
On Saturday, April 20, 2024 at 12:48:43 PM UTC+1 Waldek Hebisch wrote:
On Sat, Apr 20, 2024 at 02:47:02AM -0700, Dima Pasechnik wrote:
> How does one do this?
> (with ECL or SBCL).
>
> Presumably if one makes a FriCAS fasl library (how?), it should be possible
> to call FriCAS functions from Lisp without going through files or pipes.
>
> That's certainly possible (and used in Sage) with Maxima.

Look at 'contrib/load-fricas.lisp' and 'contrib/mk_shlib.lisp'.
'contrib/mk_shlib.lisp' makes ECL .fas (really a C shared library).
Currently 'contrib/load-fricas.lisp' is broken with sbcl, one needs to
add an extra line loading GMP support (I will fix this shortly,
after more testing).

in sbcl build,
/full_path_to_FriCAS_build_directory/src/interp/
has no src/interp/ - so this seems to be broken too. 
Or probably there is a confusion of terms, as there is a build directory,
build/x86_64-linux-gnu/, containing bin/ and lib/, but no src/

It should be very easy to convert this
file into a template (.in) that is filled in by ./configure with the correct values.

 Anyhow, if instead I use the location of the source directory, with src/interp present, I get
"Package C does not exist." error.

$ sbcl <mk_shlib.lisp
This is SBCL 2.4.3, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* FOO
* FOO
NIL
NIL
*
; file: /mnt/opt/fricas/src/interp/../lisp/fricas-package.lisp
; in: DEFMACRO IN-PACKAGE
;     (DEFMACRO FRICAS-LISP::IN-PACKAGE (PACKAGE &REST FRICAS-LISP::OPTIONS)
;       `(IN-PACKAGE ,PACKAGE))
; --> SB-INT:NAMED-DS-BIND SB-INT:BINDING*
; ==>
;   (LET* ((#:G0
;           (SB-C::CHECK-DS-LIST/&REST (CDR #:EXPR) 1 1
;                                      '(# PACKAGE &REST FRICAS-LISP::OPTIONS)))
;          (PACKAGE (POP #:G0))
;          (FRICAS-LISP::OPTIONS #:G0))
;     (DECLARE (SB-C::CONSTANT-VALUE PACKAGE FRICAS-LISP::OPTIONS))
;     (BLOCK FRICAS-LISP::IN-PACKAGE `(IN-PACKAGE ,PACKAGE)))
;
; caught STYLE-WARNING:
;   The variable OPTIONS is defined but never used.
;
; compilation unit finished
;   caught 1 STYLE-WARNING condition
T
*
debugger invoked on a SB-INT:SIMPLE-READER-PACKAGE-ERROR in thread
#<THREAD tid=29834 "main thread" RUNNING {10042A80A3}>:
  Package C does not exist.

    Line: 29, Column: 23, File-Position: 848

    Stream: #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDIN* {10000208B3}>

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [CONTINUE ] Use the current package, COMMON-LISP-USER.
  1: [RETRY    ] Retry finding the package.
  2: [USE-VALUE] Specify a different package
  3: [UNINTERN ] Read the symbol as uninterned.
  4: [SYMBOL   ] Specify a symbol to return
  5: [ABORT    ] Exit debugger, returning to top level.

(SB-IMPL::READER-FIND-PACKAGE "C" #<SYNONYM-STREAM :SYMBOL SB-SYS:*STDIN* {10000208B3}> T)
0]

Dima

Waldek Hebisch

unread,
Apr 20, 2024, 4:44:48 PM4/20/24
to fricas...@googlegroups.com
On Sat, Apr 20, 2024 at 01:18:13PM -0700, Dima Pasechnik wrote:
>
>
> On Saturday, April 20, 2024 at 12:48:43 PM UTC+1 Waldek Hebisch wrote:
>
> On Sat, Apr 20, 2024 at 02:47:02AM -0700, Dima Pasechnik wrote:
> > How does one do this?
> > (with ECL or SBCL).
> >
> > Presumably if one makes a FriCAS fasl library (how?), it should be
> possible
> > to call FriCAS functions from Lisp without going through files or pipes.
> >
> > That's certainly possible (and used in Sage) with Maxima.
>
> Look at 'contrib/load-fricas.lisp' and 'contrib/mk_shlib.lisp'.
> 'contrib/mk_shlib.lisp' makes ECL .fas (really a C shared library).
> Currently 'contrib/load-fricas.lisp' is broken with sbcl, one needs to
> add an extra line loading GMP support (I will fix this shortly,
> after more testing).
>
>
> in sbcl build,
> /full_path_to_FriCAS_build_directory/src/interp/
> has no src/interp/ - so this seems to be broken too.
> Or probably there is a confusion of terms, as there is a build directory,
> build/x86_64-linux-gnu/, containing bin/ and lib/, but no src/

In FriCAS documentation build directory means directory where
you run 'configure'. 'build', 'src' and 'target' are just
subdirectores of the build directory. If you do in source
build, then you also have source stuff (mostly in 'src' poluting
build directory).

> It should be very easy to convert this
> file into a template (.in) that is filled in by ./configure with the
> correct values.

Well, they are really templates so that user can customize them as
needed. We could do the substitution and put the result in the
contrib subdirectory of the build tree. However, after installing
FriCAS user may delete build directory, and both use things that
are not part of normal installation. I guess that for ECL we
could add extra target building shared library (library should
be usable without build tree, it only depends on files in final
installation). But sbcl part was really for people who want to
tweak it.

> Anyhow, if instead I use the location of the source directory, with
> src/interp present, I get
> "Package C does not exist." error.
>
> $ sbcl <mk_shlib.lisp

'mk_shlib.lisp' is ECL-only. I guess I should change
"Works with ECL." into "Works only with ECL."


--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages