Lizard - Script language for symbolic calculations, arbitrary large and precise numbers, parallel computing and more

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Lizard - Script language for symbolic calculations and m

Post by skywalk »

I agree the speed of x64 is not an advantage over x86. I use x64 because of memory limits with x86. That said, I rarely require x86 apps. The older PC's running below Windows 10 are terrible security risks and should be treated carefully.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Lizard - Script language for symbolic calculations and m

Post by jack »

I would like to use the dll in another basic but it's string handling is not compatible with PB, it's compatible with C
could someone post an example on how to use the dll from C ?
I could then adapt the C code to the other basic
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Lizard - Script language for symbolic calculations and m

Post by STARGÅTE »

I'm not sure if I'm right, but do I have to use then ProcedureCDLL for this DLL?
On the other hand, the DLL-function e.g. Kernel_OutputExpression() just gives a pointer to a null-terminated string, which to have to read. This should be also usable in C right?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Lizard - Script language for symbolic calculations and m

Post by jack »

STARGÅTE wrote:I'm not sure if I'm right, but do I have to use then ProcedureCDLL for this DLL?
On the other hand, the DLL-function e.g. Kernel_OutputExpression() just gives a pointer to a null-terminated string, which to have to read. This should be also usable in C right?
not sure about the first question, but as for the second question that should work in C, will have to test.
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Lizard - Script language for symbolic calculations and m

Post by STARGÅTE »

Dear all,

I'm happy to give you the first big update:
________________________________________
Lizard - Symbolic computation script language (Version 0.4.0-0005)
Contains the Lizard.dll (Windows x64 and x86), the Lizard.so (Linux x64), the Lizard.pbi, some examples for the integration in Pure Basic and a detailed documentation for Lizard with many examples.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
With this update, only one major feature has been added, but this is impressive (in terms of implementation and the following impact):
The new version allows the use of floating point numbers of almost any size and arbitrary precision!

With this feature, calculations like this one are now possible, where normal doubles would have their limits:

Code: Select all

In(1)   :=  123.456 ^ 6789
Out(1)   =  1.889456296024e14199

Code: Select all

In(2)   :=  Factorial(123456789.0)
Out(2)   =  2.853513e945335859

Code: Select all

In(3)   :=  1.00000000000000000000000000000000000000001 + 1
Out(3)   =  2.00000000000000000000000000000000000000001
In addition, the "Calculate()" function now has a required precision as a second parameter.
Constants, expressions and everything else can now be calculated as precisely as required:

Code: Select all

In(1)   :=  Calculate(Pi, 60)
Out(1)   =  3.14159265358979323846264338327950288419716939937510582097494

Code: Select all

In(2)   :=  Calculate(Log(10), 60)
Out(2)   =  2.30258509299404568401799145468436420760110148862877297603333

Code: Select all

In(3)   :=  Calculate(2^(1/2), 60)
Out(3)   =  1.41421356237309504880168872420969807856967187537694807317668
Of course, this new precision also takes into account all implemented functions and "tracks" the possible loss of precision in each operation:

Code: Select all

In(1)   :=  x = 123456.7890123456789012345678901234567890
Out(1)   =  1.234567890123456789012345678901234567890e5
In(2)   :=  Precision(x)
Out(2)   =  40.0915

Code: Select all

In(3)   :=  Cos(x)
Out(3)   =  0.0516848618965524102413372685985603
In(4)   :=  Precision( Cos(x) )
Out(4)   =  33.7128
Of course, "normal" floating point numbers are still treated as doubles in order to keep the speed advantage here.
There are also a few new functions such as: Factorial, Precision and a few more trigonometric functions.

So, have fun while testing these features and I will appreciate your feedback.

Edit: (2021-03-20) Download link changed to version 0.4.0-005: some bug fixes and a first version for Linux.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Lizard - Script language for symbolic calculations and more

Post by STARGÅTE »

Dear all,

here is the next big update for Lizard:
________________________________________
Lizard - Symbolic computation script language (Version 0.4.2-0001)
Contains the Lizard.dll (Windows x64 and x86), the Lizard.so (Linux x64), the Lizard.pbi, some examples for the integration in Pure Basic and a detailed documentation for Lizard with many examples.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
This update brings the following features:
  1. Some changes in the naming of functions: Set -> Define, SetDelayed -> DefineDelayed, Table -> Iterate.
  2. Completely new pattern matching engine to fix many accumulated bugs.
  3. There are a number of new functions, mainly of mathematical nature, such as the completion of the trigonometric and hyperbolic functions, Expand, Fibonacci and Binomial, more functions for complex numbers like Conjugate, Im or Re, constants like EulerMascheroni or GoldenRatio and functions for working with sets such as Union or Intersection.
  4. Last but not least, I also added two new functions, SubDefine and SubDefineDelayed, which do a slightly different kind of assignment, which enables, facilitates and optimizes the overloading of built-in operators. An example is given in the download.
The later, can be used to define dates, times or special numbers like 2.0 ± 0.3 as approx(2.0, 0.3).
With the new functions SubDefine (@=) and SubDefineDelayed (@:=) you can overload built-in functions like + or * to do normal calculation with your special numbers.

Code: Select all

In(1)   :=  approx(x?, dx?) + approx(y?, dy?) @:= approx(x+y, dx+dy)

Code: Select all

In(2)   :=  approx(2.0, 0.3) + approx(1.0, 0.1) + approx(4.0, 0.2)
Out(2)   =  approx(7.0, 0.6)

So, have fun while testing these features and I will appreciate your feedback.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Lizard - Script language for symbolic calculations, arbitrary large and precise numbers and more

Post by jack »

hello STARGÅTE :)
I am testing Lizard and I am very impressed with it's performance, may I ask what programming language you used ?
also, it would be handy to have an evalf(expresion [, number of digits]) where the second argument is optional
and how about the ability to set the precision to some number of digits ?
from testing I have noticed that 1.0/x is evaluated to machine precision but 1.00000000000000000000000000000000000/x is evaluated with precision of the number of digits in the constant
I am familiar with maple CAS and sometimes I need to numerically solve a problem with a certain precision especially for ill conditioned set of linear equations
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Lizard - Script language for symbolic calculations, arbitrary large and precise numbers and more

Post by STARGÅTE »

Dear jack,
nice to hear, that you are impressed. It is one of my major projects and I sill work on a next update.
It is completely written in Pure Basic ! and the code for arbitrary sized integers and floats are written in ASM.
If you want to calculate an expression with any kind of precision, you can use Calculate (link to the documentation).
For exmaple:

Code: Select all

In(1)   :=  Calculate(Cos(2^10), 50)
Out(1)   =  0.98735361821984829524651338092244419111051208085007
With this, you can also set the precision of an expression. However, the precision of a floating point number can only be reduced not increases.
Usually small numbers like 4.25 are handled as a normal double (64 bit), so it is not possible to use Calculate(4.25, 50) to increase its precision.
Here you have to use exact values/expressions or numbers with more explicit digits, as you noticed.
The precision of numbers are tracked during all calculations, to give the correct result depending on the input. See more
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Lizard - Script language for symbolic calculations, arbitrary large and precise numbers and more

Post by jack »

hello STARGÅTE :)
may I ask a big favor?
would you post a modifed Example6_Console.pb to use Import instead of including Lizard.pbi which uses interface and without using Module ?
I am trying to use the Lizard.dll with FreeBasic and that would help me along the way
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Lizard - Script language for symbolic calculations, arbitrary large and precise numbers and more

Post by STARGÅTE »

I'm not sure if I understand you correct, but here is the import version:

Code: Select all

; Import the Lizard DLL
Import "Lizard.lib"
  Kernel_Initialize.i()
  Kernel_Version.i()
  Kernel_InputExpression.i(String.s)
  Kernel_EvaluateExpression.i(*Expression)
  Kernel_OutputExpression.i(*Expression)
  Kernel_FreeExpression.i(*Expression)
EndImport

; Processing the console input into Lizard and then output them.
Procedure Command()
	
	Static EvaluationCount.i = 1
	Protected Input.s, Output.s
	Protected *Expression
	
	PrintN("")
	ConsoleColor(11, 0)
	Print(LSet("In("+EvaluationCount+")", 7)+" :=  ")
	ConsoleColor(15, 0)
	
	Input = Input()
	*Expression = Kernel_InputExpression(Input)
	If *Expression
		*Expression = Kernel_EvaluateExpression(*Expression)
		If *Expression
			Output = PeekS(Kernel_OutputExpression(*Expression), -1, #PB_Unicode)
			Kernel_FreeExpression(*Expression)
			ConsoleColor(3, 0)
			Print(LSet("Out("+EvaluationCount+")", 8)+" =  ")
			ConsoleColor(7, 0)
			PrintN(Output)
		EndIf
	EndIf
	
	EvaluationCount + 1
	
EndProcedure


; Open a console
OpenConsole("Lizard - Console")

; Lizard always has to be initialized first.
If Kernel_Initialize()
	PrintN( "Lizard kernel has been initialized." )
Else
	PrintN( "Lizard kernel initialization failed!" )
	Input()
	End
EndIf

; Main loop
Repeat
	Command()
ForEver
There are a few more function in the DLL, but they are not imported.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Lizard - Script language for symbolic calculations, arbitrary large and precise numbers and more

Post by jack »

thank you :D
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Lizard - Script language for symbolic calculations, arbitrary large and precise numbers and more

Post by jack »

hello STARGÅTE :)
in one of your example script you implement symbolic differentiation it would nice to have symbolic integration as well and perhaps numerical integration also
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Lizard - Script language for symbolic calculations, arbitrary large and precise numbers and more

Post by STARGÅTE »

jack wrote: Tue May 24, 2022 5:26 pm hello STARGÅTE :)
in one of your example script you implement symbolic differentiation it would nice to have symbolic integration as well and perhaps numerical integration also
That's right. Since differentiation have strict rules, it is very easy to add this as the first official package for Lizard.
However, for symbolic integration there are books with hundreds of pages for each special case. I'm not sure if there is a short-time implementation for this.
Probably, here, a first implementation is restricted to polynomial expressions and single functions. I will take a look.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Lizard - Script language for symbolic calculations, arbitrary large and precise numbers and more

Post by STARGÅTE »

Dear all,

nine months has been past, so I would like to provide you with a new update for Lizard.
________________________________________
Lizard - Symbolic computation script language (Version 0.4.3-0002)
Contains the Lizard.dll (Windows x64 and x86), the Lizard.so (Linux x64), the Lizard.pbi, some examples for the integration in Pure Basic and a detailed documentation for Lizard with many examples.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
The main purpose of this update was to scan the entire function library for bugs and to fix them (and there were a lot :oops:).
Of course, besides the bug fixes, there are also a few new functions like Count and Contain, Flatten and Nest as well as a few numeric functions like ShiftLeft, Bernoulli, Numerator and queries like IsPrime. More in the change log of the documentation.
There is also a new example for plotting functions and I have also revised the documentation a bit.

So, have fun while testing these features and I will appreciate your feedback.

Edit: Hot-Fix from 0.4.3-0001 to 0.4.3-0002, solved WIndows 7 problem.
Last edited by STARGÅTE on Sun Jun 05, 2022 3:22 pm, edited 2 times in total.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Lizard - Script language for symbolic calculations, arbitrary large and precise numbers and more

Post by Little John »

Dear STARGÅTE,

thank you very much!
You are a programming genius.
Well, I know ... this is old news. :-)
Post Reply