Recent

Author Topic: Symengine test  (Read 616 times)

srvaldez

  • Full Member
  • ***
  • Posts: 201
Symengine test
« on: April 25, 2026, 01:02:06 am »
small Symengine test https://symengine.org/
GitHub https://github.com/symengine/symengine

thanks to Claude AI for translating the FreeBasic code to FreePascal

you may get the 64-bit dlls from https://u.pcloud.link/publink/show?code=XZYItE5Z9pUOqUbv0D4uomhxKaaP7HyhH0kX

example output
Quote
z = "(x+y)^(-3)"-> (x + y)^(-3)
f = z * z -> (x + y)^(-6)
expand( f )-> (6*x*y^5 + 15*x^2*y^4 + 20*x^3*y^3 + 15*x^4*y^2 + 6*x^5*y + x^6 + y^6)^(-1)
1 / expand( f ) -> 6*x*y^5 + 15*x^2*y^4 + 20*x^3*y^3 + 15*x^4*y^2 + 6*x^5*y + x^6 + y^6
diff(1 / expand( f ), x) -> 30*x*y^4 + 60*x^2*y^3 + 60*x^3*y^2 + 30*x^4*y + 6*x^5 + 6*y^5

compute the first 5 derivatives of atan(x) at x
diff(atan( x ), x) -> (1 + x^2)^(-1)
-----------------------------
diff(atan( x ), x) -> -2*x/(1 + x^2)^2
-----------------------------
diff(atan( x ), x) -> 8*x^2/(1 + x^2)^3 - 2*(1 + x^2)^(-2)
-----------------------------
diff(atan( x ), x) -> 24*x/(1 + x^2)^3 - 48*x^3/(1 + x^2)^4
-----------------------------
diff(atan( x ), x) -> -288*x^2/(1 + x^2)^4 + 384*x^4/(1 + x^2)^5 + 24*(1 + x^2)^(-3)
-----------------------------

compute the first 5 derivatives of "atan(x)" at x
then evaluate at x = 0 and then divide by the respective factorial to get the taylor terms

diff(atan( x ), x): 1
---------------------------------
diff(atan( x ), x): 0
---------------------------------
diff(atan( x ), x): -1/3
---------------------------------
diff(atan( x ), x): 0
---------------------------------
diff(atan( x ), x): 1/5
---------------------------------

compute the first 5 derivatives of "1/2*x*(1-x^2)^(1/2)+1/2*asin(x)" at x
then evaluate at x = 0 and then divide by the respective factorial to get the taylor terms

diff(atan( x ), x) -> 1
---------------------------------
diff(atan( x ), x) -> 0
---------------------------------
diff(atan( x ), x) -> -1/6
---------------------------------
diff(atan( x ), x) -> 0
---------------------------------
diff(atan( x ), x) -> -1/40
---------------------------------

compute the first 5 derivatives of "1/2*(x-x^2)^(1/2)*x-1/4*(x-x^2)^(1/2)+1/8*arcsin(-1+2*x)+1/16*Pi" at x
then evaluate at x = 1/2 and then divide by the respective factorial to get the taylor terms

diff(atan( x ), x) -? 1/2
---------------------------------
diff(atan( x ), x) -? 0
---------------------------------
diff(atan( x ), x) -? -1/3
---------------------------------
diff(atan( x ), x) -? 0
---------------------------------
diff(atan( x ), x) -? -1/5
---------------------------------
fibonacci( 100 ) -> 354224848179261915075

evaluate "7/9" to 50 decimal digits
evalf: 0.77777777777777777777777777777777777777777777777778

« Last Edit: April 25, 2026, 01:05:27 am by srvaldez »

srvaldez

  • Full Member
  • ***
  • Posts: 201
Re: Symengine test
« Reply #1 on: April 27, 2026, 12:38:52 am »
I am curious, 2 people downloaded the dlls, 10 people had a look but didn't download
in case you are interested in building Symengine yourself, I used msys2 cmake and ninja
I extracted the Symengine archive then created a build folder inside Symengine
launch mingw64.exe, cd into the build folder, then
cmake .. -DBUILD_SHARED_LIBS=on -DWITH_GMP=on -DWITH_MPFR=on -DWITH_MPC=on
ninja

did the two people that downloaded the dlls successfully run the example?
what prevented the 10 people from downloading? security warning?
by the way, I had vcpkg build Symengine hoping that there would be fewer dlls and overall smaller size but the opposite was true, it was at least 2 times greater size and the Symengine version was not the latest plus it didn't support mpfr or mpc although it required the dlls to run

Boleeman

  • Hero Member
  • *****
  • Posts: 1158
Re: Symengine test
« Reply #2 on: April 28, 2026, 12:52:20 am »
Ah srvaldez,

when trying to access this thread on forum.lazarus.freepascal.org I came up with a redirect page saying cookies need to be enabled. Been having this problem lately, even though cookies are enabled in my Firefox browser.

I'm thinking probably those other 10 attempts likely had that same cookies problem !

srvaldez

  • Full Member
  • ***
  • Posts: 201
Re: Symengine test
« Reply #3 on: April 28, 2026, 12:55:46 am »
Hi Boleeman
were you able to compile and run the example?

Boleeman

  • Hero Member
  • *****
  • Posts: 1158
Re: Symengine test
« Reply #4 on: April 28, 2026, 01:30:51 am »
Hi srvaldez

"I love all things math related".

I was able to compile that example, but I did not see any result and there was no exe created?
Also ran your Symengine-pas code with dlls but got an error gmp.dll not present. Where can I get gmp.dll ?

I am running Windows 10.


« Last Edit: April 28, 2026, 01:36:08 am by Boleeman »

srvaldez

  • Full Member
  • ***
  • Posts: 201
Re: Symengine test
« Reply #5 on: April 28, 2026, 01:42:22 am »
Boleeman
libgmp-10.dll is in the package, I recommend making a copy of libgmp-10.dll and rename the copy gmp.dll
the reason for making a copy and renaming is that the other dlls that depend on libgmp-10.dll need to be able to find it
one could make a symbolic link but I am not versed in that

Boleeman

  • Hero Member
  • *****
  • Posts: 1158
Re: Symengine test
« Reply #6 on: April 28, 2026, 02:04:05 am »
Yes making a copy of libgmp-10.dll and renaming the copy gmp.dll worked and I saw the Symengine-pas

Ah srvaldez, I just realized I met you at the FreeBasic forum years ago.
I was experimenting with your fractal tree code at the time when Vb6 started going downhill in its support and I was looking for another programming language to learn.
I really loved all that math related code at the FreeBasic forum.
Nice to see you here on the Lazarus forum.
Are you still involved with GreenPeace (if I remember correctly)?


I also tried compiling the symengine_example.pas in the Symengine-pas folder but I get a project1.exe being made in "C:\Users\Admin\AppData\Local\Temp" but when I move that to the Symengine-pas folder and run it with the dlls I don't see the terminal screen coming up with the math evaluations (I just see a blank form).

Not sure if you could possibly provide the lazarus project file for the Symengine-pas folder example code?
« Last Edit: April 28, 2026, 02:11:24 am by Boleeman »

srvaldez

  • Full Member
  • ***
  • Posts: 201
Re: Symengine test
« Reply #7 on: April 28, 2026, 02:13:57 am »
I will try and ma a lazarus project, I rarely use it as I mostly do console programs, hopefully I will post it here by tomorrow

srvaldez

  • Full Member
  • ***
  • Posts: 201
Re: Symengine test
« Reply #8 on: April 28, 2026, 02:40:47 am »
here's lazarus project, hopefully it will compile and run
extract the files into the Symengine-pas folder

Boleeman

  • Hero Member
  • *****
  • Posts: 1158
Re: Symengine test
« Reply #9 on: April 28, 2026, 03:08:19 am »
Srvaldez, sorry about the late reply
(quickly went to the shops, as it is my day off work today)

That supplied project file worked.
Needed to copy all the dlls to the compile folder and then compiled.

Success. Now we have an evaluation engine for Lazarus. Cool.

Not sure if you are interested, but I translated a math calculator made by a Chinese programmer (mentioned in another thread a while ago)?

Thanks Srvaldez for supplying the working project files for Symengine. Much appreciated.

« Last Edit: April 28, 2026, 03:17:01 am by Boleeman »

 

TinyPortal © 2005-2018