View Full Version : Fun with Riemann, problems with Freebasic DLLs
Hi all,
Nothing serious, kind of toying with Riemann's Zeta function - TBGL data is placed in a List, so the animation works fine.
However the calculation is slow (and complex).
I could speed it up a lot when using the Gamma function if it accepts complex numbers.
So on a website of a French university I found fbmath which is capable doing this.
Now when compiling the FB source into a dll (fbc -dll .... ), the dll is created but TB can not read it (TB function are declared the way it should be etc ... ) TB gives no error upon declaration , but when calling the function ....
FB creates Win32 DLL's or not ???? not ActiveX dlls ????
..; if someone else knows a DLL with Complex Gamma functions ... it may be lnGamma etc ... also fine ...
In the animation it's all about where the "fingers" come to gether - the 1 M$ question is the proof that all non trivial roots are 0.5 + i(something).
best Rob -- thanks in advance
mike lobanovsky
21-12-2013, 15:11
Nothing serious ... the 1 M$ question ...
Nothing serious, you say? Well, well... :)
Looks very, very impressive though a bit slow indeed.
Assuming 3eta is written in Russian ("З" is a Russian equivalent of "Z"), can I also have your sources for the offending FreeBasic library? I don't believe the DLL can't be properly compiled. The crowd would've had the FB devs decimated ages ago for such an outstanding failure.
Thanks in advance,
Hi Mike,
Well, normally the Z is written in Greek, and as cyrillic is closer to Greek than Latin script ..... ;-)
It's not a DLL yet - I attached the source of the modules,
I probably do the things the wrong way in FB , the functions/subs are declared "export" and compiled with the "-dll" switch , the DLL is generated but trying 3 examples on the web (just copy/paste into FB : one for EXCELL , one for RapidQ and one I forgot for what - none of these works in TB ).
The examples are rather confusing - one of them uses a function declaration at the start , the others not. (well, infact I don't understand it at all - one gives at the start
Declare Function X Lib .... alias .... ( ) as .. and later (rather bizar you have to include the name of the DLL on forehand ?? )
Function X (..) as .. EXPORT
Anyway TB gives as error message ... X not found ....
The intention is just to have something re-usable , with the source it will be no problem to write it in oxygen or so -- but if it's already done, imho it's a kind of waste of time ..
The code I wrote is poor -- 3(x) grows very slow -- 3(0) -> infinity , but my method delivers (50 iterations iirc) only 50
(for 3(-1) I only get 51*25 )
Some what more difficult 3(1) -> infinity (the harmonic series) , but it grows even a lot slower (after 1000 iterations , only 1/1000 is added to the result) , maybe I reach 5 ? ;-)
That 3(1) = inf. is not so difficult to prove ....
but that 3(2)=piČ/6 is something else -- it was known as the Basel problem , Euler was to first to solve it -- many tried without success .
The problem is that in the mean time dozens of hypothesi are proven only correct if the Riemann can be proven.
There is a relation with prime numbers and the 3eta , found by Euler : as Riemann mentions here (first fomula)
http://upload.wikimedia.org/wikipedia/commons/c/cb/Ueber_die_Anzahl_der_Primzahlen_unter_einer_gegebenen_Gr%C3%B6sse.pdf
;-) best Rob
hello RobbeK and mike lobanovsky
I tried o compile the bmath ib as a dll but failed, however, it shouldn't be too hard to just extract the needed functions and convert them to thinbasic.
<off topic>
am I the only person that has problems with this forum?
I mean missing keystrokes?
I find myself having to constantly insert missing keystrokes, it's extremely annoying.
</off topic>
mike lobanovsky
22-12-2013, 05:18
@Jack:
1. Judging by the FB code, it isn't yet ready to be compiled as a DLL. Please see my requests to Rob below.
2. Exactly. Yet not to thinBasic but rather to O2 as we need all the speed of machine code there is in its underlying assembly.
3. No, I've got no problems with this forum except for its unusual and somewhat dizzying complexity. Perhaps you should address your question and symptoms explicitly to some mod or admin that's responsible for, or has access to, the forum's server in order to assist you.
@Rob:
Thanks for the FB code. But I'll have to distract you from your creative work some more:
1. What are the exact function or functions that you need to be exportable from this library in order to resolve this thread's immediate tasks?
2. What is the exact list of all fuctions in the source code, barring helper modules and functions, that you think should be exportable in order for this library to become multi-purpose and helpful from a scientific/mathematical point of view?
And a final question to both of you:
If you have a compiled FB binary for this library, either working or not, can you upload it here for me to dowload and investigate what's really wrong with its export table? We'll delete it from the forum as soon as I download it for my purposes. Hopefully we'll be able to upload another working version of it as soon as it's ready.
Thanks,
Charles Pegge
22-12-2013, 13:37
Most of the complex functions could be run directly on the FPU. Oxygen has special macros for implementing FPU math directly without the overhead of calling functions. If your complex.bas algorithms are good, Rob then I would like to have a go at porting them into this high-performance format. Would that be useful?
Thanks Charles, Jack & Mike ...
Well , I only need a few things from the code, and I want to expand it with some new functions (Beta, Stirling approx. etc ... )
@Mike : attached the source , the dll , the tbasic file and a copy from the FB's help file (as said probably I'm doing just something stupid).
@Charles : yes , great -- I can make some extensions if you wish ..
Also attached a more recent and complete source .
best Rob
Oops, yes , Charles .. when I use a by O2 generated DLL in TB, everything's fine - except TB exits with an error. (I mean on exit of the prog).
and .. floating point oddities -- trying some other compilers to generate DDL's it seems the floating point formats sometimes do not match - O2 worked fine in TB and Lisp , the Aurora compilers outputs not compatible stuff (tried all the possible floating point possib. (Aurora is a kind of C compiler - I can give a copy if one likes, I have the freeware version ).
mike lobanovsky
23-12-2013, 13:19
Hello Rob,
Thanks for the zips. You can remove testdll.rar now as I've got my copy.
See you,
[EDIT] Rob,
Your FB test DLL and also the one recompiled on my PC work perfect. You problem is incorrect thinBasic declaration of the function export. thinBasic "Alias" is case-sensitive (FBSL's are not) and must name the function exactly as it appears in the DLL's export table.
Please use any PE executable header viewer, e.g. Dependency Walker (http://www.dependencywalker.com/) to examine FB DLL exports. You'll see that FB capitalizes and also mangles (http://en.wikipedia.org/wiki/Name_mangling) exported function names (FBSL de-mangles them automatically).
You should change your declaration as follows:
Declare Function add2 Lib "testdll.dll" Alias "ADD2@8" (ByVal x As Long , ByVal y As Long ) As Long
MsgBox (,Str$(add2(8,9)))
and you'll get your test rig up and running flawlessly.
The same principles apply to building and declaring the French university code. :)
That's simply fantastic ;-)
Completely unaware about mangling - demangling I think there's a possibilty I gave it up after a few more tries.
"Dependency Walker" ! - wow, great.
OK - the door is open now , time for some coding.
thanks again for your help and sharing your expert help - merry Xmas (but iirc in your country the 7th of Januar ?)
Rob
mike lobanovsky
24-12-2013, 00:42
It was my pleasure to help, Rob, and Merry Xmas to you too! Christmas is celebrated in my country twice; first by catholics on December 25 and then on January 7 by the orthodox Julian calendar. My date is December 25 but cheers to you on the both occasions!
:drink: / :drink:
Charles Pegge
24-12-2013, 07:55
Hi Mike & Rob,
Name Mangling can be avoided by enclosing your FreeBasic exported functions in an extern block. I do this for compiling Oxygen.dll.
Extern "Windows-MS"
...
End Extern
mike lobanovsky
24-12-2013, 16:35
Thanks for the tip Charles,
I haven't had much personal experience with FB DLL compilation to figure it out off-hand without looking into the actual source and output first.
http://www.fbsl.net/phpbb2/images/smilies/icon_ml_noel.gif
Thanks Charles !
needs -lang fb , correct ?
best regards ... Rob
Charles Pegge
25-12-2013, 10:05
Extern "Windows-MS"
It is a well hidden secret, Mike. :)
Rob, the only compiler switch I use with freebasic DLL compiling is -dll
:occasion:
Merry Christmas all!
John Spikowski
25-12-2013, 21:52
Extern...End Extern (http://lampiweb.com/help/freebasic/KeyPgExternBlock.html)
Good to know. Thanks Charles.