Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Dimensioned Numbers In Java
Dimensioned Numbers In Java

Introduction
Computing in scientific and engineering areas often deals with manipulating numbers that represent physical entities, such as durations, weights, and forces. A common source of errors in scientific computing involves processing numbers that represent different kinds of entities, or that are related to different units, and utilizing the result for additional computation. A number is referred to as dimensioned when it relates to a specific entity such as distance, time, or temperature, and the number implies a particular unit of measure. A dimensionless number, also known as a nondimensional parameter, is a ratio of physical properties and conditions of such a nature that the resulting number has no defining unit of weight, duration, and so on.

There have been several attempts to add support for handling dimensioned numbers to programming languages. The goal was to ease programming and to make it less error prone. The concerns of scientists and engineers have apparently not been noticed by programming language developers, since we don't see support for dimensioned numbers built in to many programming languages. This is unfortunate not only for scientific computing, but also for object-oriented business and financial programming, which could also benefit from compiler and language-level dimensioned number support.

This article presents a simple proposal for supporting dimensioned numbers in Java. Application development using Java in scientific and engineering environments is not yet in the spotlight, since performance is still lagging behind other languages (Fortran, C, C++, Pascal) by an order of magnitude. This situation will improve within the next few years and Java's excellent power-complexity ratio gives it the potential to soon rank as language number one in scientific and engineering areas.

The proposed language extension involves two new keywords (dimension and unit), and an extension to the syntax of numeric types. It prevents mangling different kinds of physical entities, and it takes care of unit conversion. Conversion from and to scalar (plain numeric) values is only possible by specifying applicable units.

The extension mainly performs dimension checking at compile time; its only run-time involvement deals with unit conversion, as far as non-basic units are used. The proposal consists of four categories of language extensions, and two keywords. It uses Java support for packages. It does not use object-oriented features.

Even though Java currently lacks support for dimensioned numbers, you can already adopt a convenient programming style for dealing with units, as outlined at the end of this paper.

Base Dimensions
Some dimensions are more basic than others. There are five base dimensions in physics (that I recall):

  • distance
  • time
  • mass
  • temperature
  • electric charge

    For each of these dimensions we can define a primary unit:

  • meter
  • second
  • kilogram
  • Kelvin
  • Coulomb

    The dimension...unit... construct covers these base dimensions:
    dimension time - unit second;
    dimension distance - unit meter;
    dimension mass - unit kilogram;
    dimension temperature - unit Kelvin;
    dimension electricCharge - unit Coulomb;

    Internal machine representations of dimensioned variables are relative to the base units.

    Derived Dimensions
    Using the base dimensions, others may be expressed through multiplication and division, e.g.,

  • speed equals distance divided by time
  • acceleration equals speed divided by time
  • impulse equals mass times speed
  • force equals mass times acceleration

    The dimension...m - =... construct covers these derived dimensions:
    dimension speed - = distance - / time;
    dimension acceleration - = speed - / time;
    dimension impulse - = mass - * speed;
    dimension force - = mass - * acceleration;

    Derived Units
    Units are final variables of dimension types. The ones that are not defined with the base dimensions are derived. Their definition may suggest internal representation like integers, floats or doubles, but the actual representation is adapted at compile time to the highest precision applicable in the context.

    The final keyword is not needed:
    mass - gram - = kilogram / 1000;
    distance - kilometer - = 1000 * meter;
    time - minute - = 60 * seconds;
    time - hour - = 60 * minute;
    time - day - = 24 * hour;

    Dimensioned Numbers
    The actual usage of dimensions is in dimensioned numbers. These have a type made up of a numeric type (int, float, ...) and a dimension. Actual values are made up of a combination of numeric values (0, 1, 0.1, ...) and units. As with dimensions and units, multiplication and division on dimensioned numbers yield dimensioned numbers of possibly different dimensions. The examples in Listing 1 would be accepted by the compiler.

    These examples would produce a compile error, as seen in Listing 2.

    Physics Package
    The sample package in Listing 3 illustrates how a physics package might look once the dimension and unit keywords are added to Java.

    As shown in the physics package, dimensions can be derived from other dimensions and constants could be provided for common physics values.

    Finance Package
    A finance package would also be an interesting way to take advantage of dimensioned number support in Java. See Listing 4 for an example.

    The sample finance package shown brings up an interesting aspect of dimensioned number support in a programming language: that of non-constant units that are derived from variable dimensioned numbers.

    Computing Packages
    A computing package might also be of value. Such a package could greatly simplify the process of building and debugging applications which require reliable calculation of memory or disk space quantities or conversions between computer-oriented units of measure. Listing 5 shows such a package.

    Other dimensions and units would also apply in the computing package, such as CPU clock speed, system and network traffic load, or end-user frustration levels, as they wait for Java applets to execute within Netscape Navigator 2.0.

    Implementation
    Java compilers may adopt the proposed extension without major difficulty (if you disagree with this proposition, send me e-mail). However, full support will require a modification of the .class file format for the dimensioned numeric data types. This would call for a synchronized operation by all Java compiler builders and users. That can only be justified if the proposed extension has proved to be worthwhile to enough Java developers (and if Sun agrees).

    Therefore experiments are needed; the proof of the pudding is in the eating. We need to try out the extension, using preliminary support by compilers and preprocessors, that does not require changes to the class format. This support would be possible in the following way:

  • the original package files are named physics.dim instead of physics.java, etc
  • the compiler or preprocessor gets a command line hint to use the appropriate .dim files, e.g., guavac -d physics.dim - d finance.dim
  • files physics.java etc. are derived from the .dim files by only selecting the constant definitions; these become all double scalars

    An example for new physics.java is shown in Listing 6.

    Who is going to implement these ideas? At least for the time being, not me. I am extremely busy with other projects, e.g., see http://www.delftware.nl/scriptic/. So if you are a compiler builder, or if you want to contribute to a GNU Java compiler, please go ahead and let me know.

    Emulating Units in Java Today
    While no compiler support is available today for dimensions and units in Java, you may use the previous physics.java file to deal with physical units in your code now. Just forget about the double*length syntax etc, but write things like the following:

    double len = 1.5*kilometer;
    double t = 8.3*minute;
    System.out.println("Speed: " + ( (len/t) / (meter/second) ) +
    " m/s");

    This working style doesn't give you the full benefits of dimensional checking, but at least it will make your code more readable, and you will have less worry about units.

    About Andre Van Delft
    'Andre van Delft studied Mathematics and Business Administration in Holland. Then he joined the Department of Computer Science at Leiden University for four years. From 1989 on he has worked in Delftware Technology as consultant and software developer. His topics of interest are software engineering, reliability and parallel programming.

  • In order to post a comment you need to be registered and logged in.

    Register | Sign-in

    Reader Feedback: Page 1 of 1

    Enterprise Open Source Magazine Latest Stories . . .
    Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
    With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
    AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
    During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
    Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
    A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
    Subscribe to the World's Most Powerful Newsletters
    Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


    SYS-CON Featured Whitepapers
    ADS BY GOOGLE