Dear Axiom (and FriCAS) developers,
After several attempts, the Haskell -- Axiom (FriCAS) interface by
String and named pipes (in Unix, Linux) seems starting to work.
The Haskell program uses for this the functions hPutStr, hGetLine
(see axiomIO below) which are similar to the C library functions
fputs, fgets.
The FriCAS part fifoFromA.input is as suggested by W.Hebish in his
earlier letter.
Here is the first practical example of the interface.
In the current DoCon (in Haskell), the method for the operation `factor'
is very slow for n > 10^10.
The below program uses the interface function `axiom' to program
factor' and to obtain fast the factorization list
[factor' i | i <- [10^12 .. (10^12 + 20)].
------------------------------------------------------------------------
module Main where
import System.IO (IOMode(..), Handle, openFile, hPutStr,
hGetLine, hFlush)
import System.IO.Unsafe (unsafePerformIO)
import DExport -- DoCon
main = putStr (showsn 1 pairs "\n")
where
j = 10^12 :: Integer
bound = 20
js = [j .. (j+bound)]
pairs = [(i, factor' i) | i <- js]
factor' :: Integer -> String
factor' n = axiom (showString "factor " $ shows n "\n") ""
-- the below code needs to join the DoCon library ------------------
axiom :: String -> String -> String
axiom str = showString (unsafePerformIO $ axiomIO toA fromA str)
dir = showString "/home/mechvel/docon/2.12/docon/source/demotest/"
toA_IO = openFile (dir "toA") WriteMode :: IO Handle
fromA_IO = openFile (dir "fromA") ReadMode
toA = unsafePerformIO toA_IO
fromA = unsafePerformIO fromA_IO
axiomIO :: Handle -> Handle -> String -> IO String
axiomIO h1 h2 str =
do
hPutStr h1 str
hFlush h1
str' <- hGetLine h2
return str'
--------------------------------------------------------------------
So, `main' outputs
[
...
(1000000000004,
"primeFactor(2::Integer,2)*(primeFactor(17::Integer,1)*
(primeFactor(149::Integer,1)*(primeFactor(197::Integer,1)*
primeFactor(501001::Integer,1))))"),
(1000000000005,
"primeFactor(3::Integer,1)*(primeFactor(5::Integer,1)*
primeFactor(66666666667::Integer,1))"),
...
]
fast enough.
***********************************************************************
The remaining problems are as follows.
0. FriCAS dependence on Lisp
----------------------------
My examples with Haskell, C -- FriCAS work under
Squeeze Debian Linux + GNU CLISP 2.48,
and they do not work under Lenny Debian Linux + GNU CLISP 2.44.1.
Is this due to the Lisp version?
a) Maybe FriCAS can message when loading:
"FriCAS 1.1.5 with Lisp = such and such version"
?
b) How long Axiom (FriCAS) is going to depend on Lisp ?
Will Aldor remove this dependence?
(there is also the question of the Aldor license, etc.)
1. Haskell safety
-----------------
I need to find out how to use unsafePerformIO, or how to avoid it, in
order the Haskell part to perform safely, when this `axiom' function is
set in the DoCon library in many places.
Because Haskell is purely functional (it is also `lazy' by default).
And introducing IO in the middle seems either to lead to great changes
in the whole source style or to a certain question of safety.
This needs studying.
If unlucky, this point may spoil the whole interface project.
2. Fast parsing
---------------
I hope, I can provide fast parsing on both ends. This hope bases on that
each time DoCon has both an internal data d and its string image dStr.
So, a special output with tags is possible for dStr, and a special
parsing (in Spad) on the Axiom end.
To make the Axiom end, I shall need to study more of Spad.
3. IO performance in FriCAS
---------------------------
For the exchange of short strings and without parsing,
Haskell -- FriCAS works about 15 times slower than Haskell -- C.
After (1) and (2) are done, this will become the bottleneck -- for the
calls of a small computation time.
I have the impression that the factor of 5 here is due to the interpreter
mode itself in the loop and another factor of 3, is may be, due to
readLine!, writeLine!.
This can be verified by running this loop separately, and with replacing
readLine! and writeLine! with something simple, say,
i : Integer := 100000
repeat
i := i - 1
if i = 0 then output "done"
if size?(lowerCase "ABC", 4) then output "size = 4"
-- something which does not use IO in the loop.
4. IO performance for named pipes
---------------------------------
After (1), (2) and (3) are done, this will become the bottleneck -- for
the calls of a small computation time.
I wonder whether the alternative approach of C interface + shared memory
will help.
Regards,
------
Sergei
[email protected]
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.