Skip to main content

alexanderschunk's Blog

JMath a Java API for doing math

Posted by alexanderschunk on April 18, 2010 at 10:52 AM PDT

<h1>JMath: A Java API for doing Math</h1>
<p>Hello. I would like to introduce JMath project. JMath is math API for doing serious math with Java.</p>
<p>With JMath you can do linear algebra, set calculations, general math calculations such as arithmetics, fractions and the like.</p>
<p>Also, with JMath you will be able to do serious statistics.</p>

<h1>Origin of JMath</h1>
<p>Origin of JMath is the former LinAlg API. LinAlg API is part of JMath is now being developed by SysConsult IT Consulting Company.</p>
<p>Main development cycle has been slept for almost over two years but it has been redeveloped with new features coming soon.</p>

<h1>License</h1>
<p>JMath and LinAlg project are under distributed under a GPL license. For more information visit jmath.java.dev.</p>

<h1>Coming soon</h1>
<p>There will be more features of JMath coming soon. Also i will provide demos for JMath and LinAlg API.</p>

Related Topics >>

Comments

;)

;)

Are you censoring comments?

I notice that a previous comment about a java based freeware for numerical computing has somehow been removed.

that's not cool at all.

access question

At the moment, the project at jmath.dev.java.net does not appear to be publicly available. Any idea when others can see it?

Pending approval

Hello, i have now set a license and an owners message. The project is still pending approval by java.net I dont know how long this takes but i will add further information and source files to the project soon. If you want to have a look at JMath i can send you zip file with source code. Hope to get the rest of JMath finished this week. regards Alexander

Java Closures: Functions or Objects?

Posted by alexanderschunk on January 23, 2008 at 11:56 AM PST

Java Closures? What are they?

The question wheather closures are functions or objects came to my mind when reading several proposals concerning on closures. It looks like most authors regard them as both - functions and objects but giving not a real and concrete distinction in what case a closure is a function - or functional object - and an object.

For example in Neil Gafters vision for closures, closures seem to be both functions or an anonymous function or method and objects - or even classes beecause its possible to extend a class or template from a closure.

I think, if we follow the traditional closure syntax and usage - like in lisp or Perl where closures are regarded as procedures or sub routines. I have difficulties to imagíne a case where it makes sense or its practical to have the ability to extend a template or class from a closure as follows:

class MyClass
extends
{ int x, int y => int }

or any such nomenclature. If a closure is nothing more than an anonymous function why do we need extend them to real object types? Is it just enough to have a short hand for anonymous methods in which the BGGA Syntax would just be enough?

I even have diffiuclty to see what a class or object like:

{int x, int y => int }

in the above example would describe or what power closures provide to describe real world entitities. To me closures are to abstract to describe real world entities i would only allow them as a short hand for anonymous functions or methods as used in Lisp or Perl.

Also it would make sense to allow closures as parameters for normal methods i.g:

int myClosureMethod(int x, {int y, int z = > int }){
//something
}

but dont apply them on classes or templates because templates are already a very powerful feature to describe real world entities.

Comments

The disadvantage of the approach BGGA takes is that the following is confusing:

executor.execute( { => ...; } ); // OK

But

{ => void } toBeRun = { => ...; }; executor.execute( toBeRun ); // Oops

The problem I foresee is that the syntax for a function type is so similar to the syntax for a closure that other people, like myself, will be surprised that the two aren't interchangeable and BGGA could choose to make them interchangeable. Much as a literal 1 (analogous to a closure literal) is interchangeable with an int (analogous to a function type).

A further reason to make function types and closures one in the same, is that as BGGA stands you need function types for recursion:

{ int => int } factorial = { x => x <= 1 ? 1 : x * factorial( x - 1 ) };

Alex, you are mixing up closures and function types. A closure is a block of code (or call it inner method or function) that closes over something (e.g., variables). A function type like Neal defines it is a kind of object oriented helper to enable defining fields, variables, or parameters to take closures as a value. As there is no such thing as a standalone method type for a variable in Java, making instances of anonymous types/classes a container for closures seems rational. In doing so, Java allows for extending such function types as any other type. In Lisp, you don't have types so you don't need to cope with them. In Java (for now) they are mandatory.

LinAlg API: Full List of Features

Posted by alexanderschunk on January 21, 2008 at 1:24 AM PST

New Feautures: Eigenvalues and triple scalar product

The next release of LinAlg API will provide methods to compute Eigenvalues and the triple scalar product.

Eigenvalues and the triple scalar product are common and helpful mathematical features that are useful for solving a lot of common math problems.

The Eigenvalues are computed by solving the linear equation det(A-lambda*In) where A is a Matrix, lambda a free parameter and In the identity matrix. We can simplify this by simply determening the det(a) of the Matrix with a parameter and omitting the multplication with the identity matrix since a value multplied by 1 results in the same value.

And the multiplication by the identity matrix just means: multiply all diagonal components of the matrix by 1 that is m11, m22, m33 and m44 if you have a 4x4 matrix.

The triple scalar product is simply computed by computing the volume of three 3D Vectors by multiplying all components of the three 3D Vectors and perform some + and - operations on them.

Comments

Why would one use LinAlg vs. JAMA? I'm not expert enough in either to know. I'm just looking for what the difference in focus is from your perspective. Thanks for the info.

My View on Closures: Part 2

Posted by alexanderschunk on January 20, 2008 at 5:09 AM PST

No more symbols please>

In my last Blog i did make some suggestions to get rid of the redundand => syntax of closures. I suggested to use := and to invent a keyword i.g. block or function to highlight the fact that closures are functional objects - basicall Neil Gafter regards them as equivalent to anonymous methods however i think there is no strict distinction in Gafters proposal wheather a closure is a pure function or an object

According to Neil Gafter, a closure object needs to be invoked by calling the invoke() method for a particular closure. The invoke method can have parameters i.g.:

{ int x => x + 1 } //closure definition
{ int x = > x + 1 }invoke(10); //call closure with 10 as parameter

So if a closure is a function in this case - besides the fact that its also an object - a closure object - then i think it would make sense to declare this whole block of statemens as a function:

function { int x => x+ 1}(int);

In my last Blog i said that the => symbol is redundant and suggested to use := as a variation of =. With this variation the closure would be written as:

function{
int x := x+ 1;
}(int);
//call closure with 10 as argument
function{ int x:=x+1 }(10);

This syntax could also be used to simply define getters that return values:

function {int x:=10;}(); //always returns 10

int s = function sum{int x, int y := x+y }(3, 5); //call sum with 3 and 5 as parameters

Local variables

Also its possible to declare local variables in closures:

function{
int j = 0;
int i=3;
switch(i){
   //some switch statements
  case 1: j++;
  case 2: j--;
  }
}();

Thus using a function keyword makes clear that a closure is both a function and an object that can be invoked. The invocation is executed by adding the () parantheses to the statement.

Related Topics >>

Comments

In my proposal:

http://www.artima.com/weblogs/viewpost.jsp?thread=182412

Your example would be either:

method int (int x) {x+1} // without type inference method(x) {x+1} // with optional type inference

I like the notation @(int x,int y)(x+y).

But is there any there there in closures but just some syntactic sugar? A lot of articles suggest that it's just a bunch of hooey.

I like the introduction of the keyword "function" because its familiar to me from ECMAScript.

It would be great, if the ECMAScript syntax for closures would be introduced into Java. I think, this syntax would immediately be familiar to many people.

Note! In this case a closure would be implemented as class with constructors i.g.:

public class C{ public C(){ //standard constdruction } public C(int x){ //construction with one parameter } public C(int x, ...){ /construction with one and more parameters }

So in this case the standard constructor would be called for a simple closure statement i.g.:

function { int x=3, int y=5; int sum := x + y }();

whereas the constructor with parameters would be called for a closure with parameters:

function sum{int x; int y; int sum:=x+y}(3, 6};

In this case the () represant the fact that closures are both functions and objects or in other words functional objects.

}

Yet Another Closures Proposal

Posted by alexanderschunk on January 17, 2008 at 9:47 AM PST

First: Getting rid of =>

Basically, when i read all the proposals, comments and pros and cons on closures in Java the first thing i would get rid of is the obviously redundant => declaration.

So in case of block statements the following would be allowed:

{
int x = 0;
int y = 3;
int sum:= x+ y;
}

As i understood it right, => has at least two meanings. It means return for functions and := or = in the other case.

Replace => by := for assignments

I would use := for assignments rather than => simply because := is more naturial to mathematicians and logicians and is usually used to describe an assignment in math and logics. This could be used as outlined above:

{
int x = 4;
int y = 3;
int z = 3;
int sum:=x+y+z; //assignment
}

Use a function keyword instead of {int, int => int} syntax

For the function declaration, i would suggest to use a keyword rather than a symbol. Why not invent a function keyword that has a similar meaning like => i.g.:

public int function add(int x, int y){
return x + y;
}

In the other case, i would use := instad of => because the arrow direction implies to read it left to right rather than right to left and there is no <= to represant the invert direction.

Use a block keyword to declare block statements

Rather than just simply type closures i would invent a block keyword that defines a block of anonymous statements:

//only valid for anonymous block statements, not be used in loops 
//itereations

block{
int x = 3;
int y = 4;

}

So with these language features you could write a simple to read Java code that is clear and understandable by everyone:

class MyClass{
//declare a function type
public int function add(int x, int y){
    return x + y;
}
public int function sub(int x, int y){
  return x - y;
}
public void function(List<int> intList){
    for(int i = 0; i < 10; i++){
        intList.add(i);
     }
  }
public static void main(String[] args){
  
  //declare a closures block
   block{
     int x = 4;
     int y = 3;
    System.out.println("x + y" + (x+y));
    }
  }
}

}
Related Topics >>

Comments

There seems to be a bug in the html keyword. Just add a function name and an int parameter type for the List in the addItem() function.

public void function addList(List intList){ for(int i =0; i < 10; i++){ intList.add(i); } }

Puh. Hard to get things right

Note: The list function sample should be run as follows:

public void function addItems(List intList){ for(int i =0;i < 10; i++){ intList.add(i); } }

i like this propsal btw ... i hate => shits they are SOOO rubish bla.

Haha. Look liks the ampersand symbol followed by the keyword int produces the integral symbol. So, mentally replace &int with: & int

One other thing I noticed as I read the second time... Where are the function variables and how do you invoke closures passed as method arguments? Classic examples: public void doSomething(int y, &int closure()) { return i + closure(); } // Inline doSomething(2, {return 3;}); // 5 // Variable &int a() = {return 4;}; doSomething(1, &a); // 5 Both of these are really the benefits of closures. I'm not sure what your idea is providing to be honest.

Adding keywords is necessarily difficult and makes backwards compatibility a challenge. Recall in JDK 1.5 the addition of the enum keyword was somewhat difficult for existing code. I doubt adding two keywords will be considered, but good luck with the proposal.

*uah*
What's next? The DWIM* operator?

Why are people so obsessed to get his/her own favorite language construct into Java? If you want closures, use a language that has clean support for it (not just as an ugly afterthought).
This: "How can we add more (junk) to Java instead of fix already known problems" is a good sign that Java is on the way to become the COBOL of the 21st century.

Instead of adding complexity that make things simpler in some situation but more complicated overall, start reducing complexity!

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Let's not forget that Java once started and was successful exactly because of that attitude!

--
*) the "Do what I mean" Operator is still missing from Java

This proposal is so clean, it does not even propose closures. Is this posting meant as a parody?

This is by far the cleanest Closures proposal I've read so far. I'm still not sure we should add Closures to Java but this proposal makes me give it more serious consideration.

A prototype of this syntax would go a long way in convincing me (and others) that Closures are a good thing.

why function as a keyword. Is it a reserved name? I'd like something more definitve, like oh, closure.

Very good proposal for a good closure syntax. I like it.

The add function would have been declared prior using it like a normal method. You could do it as follows:

public int function add(int x, int y){ return x + y; } public static void main(String[] args){ int x = 4, y = 4; int res = add(4, 4); }

Where in int res=int function add(x, y) is it made known to the compiler that res involves +? If I change x and y after int res=int function add(x, y) will the value that res returns change?

Actually its not really a proposal. Its just some suggestions to integrate closures into Java.

And using => for functions is not the way i want to programm. I prefer:

public static void main(String[] args){ int y = 5; int x = 4; int res = int function add(x, y); System.out.println("result: " + res); }

I like this syntax much better. It's actually readable. If I wanted more symbols in language, I'd use Perl.

I'm having difficulty seeing any part of this as a closure.

Please translate this to your proposal:

public static void main(String[] args) {
. . int y=5;
. . {int => int} addY={int x => x+y};
. . System.out.println(addY.invoke(2));
. . y=10;
. . System.out.println(addY.invoke(2));
}

What you showed in your last comment is a different syntax for a static method, and not a closure.

I suggest you spend some time reading the Wikipedia article about closures, and trying them out in various languages.

Basically, when i read all the proposals, comments and pros and cons on closures in Java the first thing i would get rid of is the obviously redundant => declaration.

Wrong approach. The right one would be to get rid of all the closure fanboyz.

LinAlg API CVS trunk is open

Posted by alexanderschunk on January 12, 2008 at 2:57 AM PST

LinAlg API CVS trunk is open

There is a first source files upload avaiable for LinAlg API in CVS trunk. To check out the sources simply use your favorite CVS access programm and type the following commands:

cvs -d :pserver:username@cvs.dev.java.net:/cvs login
:pserver:username@cvs.dev.java.net:/cvs checkout linalg

If you are using NetBeans you just need to configure the CVSRoot path and the set the checkout options. There seems to be a problem with NetBeans CVS under Windows but if you have a Linux CVS client that should work well.

We will provide further CVS sources for different OS and Java platforms in the future. So far you need to become a member of LinAlg API project and download the sources and .jar files from the document/files section.

Related Topics >>

LinAlg API: 20 fellows make up a Community

Posted by alexanderschunk on January 9, 2008 at 7:12 AM PST

20 Fellows make up a Community

The twentieth member has joined the LinAlg API community. Members background ranges from computer sciences and software engineers with up to 5 years of experience in Java programming and with industry background.

In particular in the last two month many people joined LinAlg API and asked for help in developing or porting LinAlg API to other platforms.

Thats a great news and i hope and will look forward to get more fellows that want to contribute and help improving LinAlg API. We are on a good way.

Related Topics >>

LinAlg API: Christmas Present

Posted by alexanderschunk on December 22, 2007 at 2:20 AM PST

Christmas Releases

In my last Blog i said that LinAlg API is finished. This is still true yet i did add some more features to it and revealed two new ports for mobile and 64 bit platforms as a special christmas release :).

Features

With this release LinAlg API now offers core features for the following mathematical types and a bit more:

  • 2D and 3D Vectors
  • Matrices
  • complex numbers
  • Quaternions
  • Algorithms
  • Geomtools

To download release 2.0 of LinAlg API go to the LinAlg API project page at linalg.dev.java.net.

Thanks to the contributors

This 2.0 release of LinAlg API would not have been possible without the help of the many contributors that joined LinAlg API and helped testing it or porting it to other systems. Special thanks goes to Morton Gulbrandtsen - working on a Solaris and Debian port -, David Clavel and Steven Martin who first joind LinAlg API and gave a good feedback.

Merry Christmas and a Happy new Year...

... to the Java community and the rest of the world from the LinAlg API team.

Related Topics >>

LinAlg API: Finished

Posted by alexanderschunk on December 17, 2007 at 11:14 AM PST

LinAlg API: its finished

Yes. Finally, i got it done. LinAlg API now offers all the things i wanted to see it have. Sure, there are some things to do here and there but basically all features from my todo list are now implemented and exist at an almost complete level. The Quaternion class needs to be finished yet this is something i will do in the next couple of weeks however the Quaternion class already provides some basic operations for Quaternions you can work with with.

LinAlg API: Scope and Features

From the very beginning i wanted to write an almost complete linear algebra API that offers basic features to do linear algebra with Java. Now, lets have a short look at what features LinAlg API provides with this stable release:

  • 2D and 3D Vector arithmetics
  • Matrix operations - both array based and non array-based
  • Complex Number operations
  • Quaternions - still something on the todo list
  • Algorithms - yes, there is a general Gaussian algorithm now
  • Demos, Docs, Tutorials

Sure, there are some things you wont find in LinAlg API that some people may find useful yet the Todo list has not been closed :). Another important thing - that has nothing todo with its implementation - is the growing number of interesting people and developers that join the project. Some of them give feedback others not but its a good feeling to see that there are people that like the project and want to help make it better.

Sure, i am still looking for volunteers, testers and developers to test and help improve LinAlg API so if you are interested feel free to joint the project.

Demos, Docs, Tutorials

There are a few demos available that demonstrate the core features of LinAlg API, a tutorial for beginners and a whitepaper for those interested in background information. I will start writing a JCP for those interested in using LinAlg API for their own implementations. Basically using LinAlg API is rather simple - no matter if you use it for developing apps or to develop your own linear algebra API. I will provide more tutorials and information on implementation issues in the near future.

Related Topics >>

Mercurial at home

Posted by alexanderschunk on December 13, 2007 at 10:55 AM PST

Mercurial at home

Since the beginning of OpenJDK i followed the discussion about the mercurial move. Since the main job of porting over the sources from subversion CVS to Mercurial - that is the Mercurial transition - is done i wanted to test Mercurial myself at home.

As a Windows user i was looking for a Windows download and found one at the Mercurial download page. Having installed Mercurial on my machine i did run the hg test command and got a list of help commands for the other mercurial commands.

After experimenting with other commands i found that for each command it is required to add the hg command which i find a bit of "repeat yourself." and thought i got myself writing a few batch files to do the job.

Having a few batch files to create and update repositories i found that having a GUI application for Mercurial that displays the repositories and their files would be even better. I am not aware about how good Java would do the job here but i think it should be possible to have an application that goes over all files in the directories of the repositories and shows the files connected to them.

Related Topics >>