Skip to content

Catching Up


I want to catch up with what I’ve implemented so far.

This is not what’s new, but rather a glimpse on what I’ve done and still remembering it

I really need to organize my thoughts about what is happening in this project

the scattering thoughts are frightening me :S

Tensor Parsing:

I want to add Tensor badly in Qs because I wasn’t able to understand it I had to include it

however I’ve Added Tensor parsing

Qs> <|4 3;3 2| 4 5; 5 3 |>

Yes this is a 3rd rank tensor  or you may see it as a two matrices in the Z-Axis

what about 4th Tensor (You may ask) ??!!   Bear with me I am still thinking of a natural syntax to add it.

also I would like to remind my self that Stress tensor is a 2nd rank tensor (which looks like matrix but with special operations)

using <|…|>  syntax you can define also zero rank tensor up to 3rd rank tensor (what will I do with this?? I don’t KNOW)


yes I included the text at last (I was struggling against putting text in Qs, but it was necessary :S or let me say I couldn’t come up with another strategy.

Qs> ml = “c d e f g a b c>”;

Qs> Music:Play(ml + ” ” ml);     #Music:Play is an extension function that play midi and the music library is 100% implemented by me (I mean sequencer part and music DSL as it contains eastern tones also – another story indeed)

and yes you can add text to text, also imagine you can add text to number

Qs> 4 + “44”

DimensionlessQuantity: 48 <1>

but the opposite is will not act like this (because I am casting to the left type always – which is the first one in fact)

What is meant by adding text is to differentiate between sending text to functions and sending other types.

so Windows:MessageBox  function now accept Text

Windows:MessageBox(“Hello There”)  will result into messagebox ofcourse (just try it)

to escape quotation mark  use back slash “\”hello\””


I like it 🙂 (do you ?!? :):))

Function Extensions

With C# or any .Net language frankly {put static class with static functions under Qs.Modules namespace}

the class name becomes namespace in Qs.

– I’ve enhanced the function binding so you can write your C# native function with native numerical type and I will cast it to you without you notice it ( no more QsValue as a parameter type), however this will add other processing lag (but who cares 😀 everything is cached after this)

also I can map vector to array of numbers so use ff(int[] ia)  declaration 🙂 it will work

Why I was enhancing the extension functions {simply because I am planning to include OpenGL } asking me why :O :O :O ??

silly, every numerical system has a 3d device to render to it.

but frankly I am thinking of visualizing Scalars, vectors, and tensors into 3d conceptual drawings

however OpenGL  is  a very far idea


don’t forget the Graph:Plot(xvector, y1vector)  it really draws and I consumed a free opensource library to do it.

may be a freakin plot but hey it works and I can visualize some quick samples indeed.

Function Named Arguments

Quantity System Engine can consume different declaration to the function with the same name

however you must change the parameter names

that’s why you can call the function with named arguments (shhsh  argument==parameter so I use it interchangeably)

all the following are correct declarations

f(x) = x

f(y) = y^1.5

f(z) = z^2

f(er) = er/4

f(g) = g+9/g^2

Note:  the first function name declared is the (default function) the one you call it without specify named arguments

to call any of these functions use the ‘=’ equal sign


Function Variables

Now you can treat the functions as normal variables because they are inherited from QsValue (internal structure of Qs)

so that when declaring

u(x) = x^2

v(x) = x/2

w(x) = x*9

r = @u+@v+@w      #  <==   this sum all functions and generate new function in r

r(x) = x^2+x/2+x*9

and don’t worry about parameters, as they are merged for you with any number of them

all basic operations supported (simply I merge the function declaration text with the desired operator :))

HOWEVER this is going to change after I put the symbolic algebra library 🙂 (another library I am making) 😦 😦

What about named argument functions??!! (clever question)

imagine you have a x-component speed in u function

u(x) = x

u(y) = y/2

u(z) = z^2.1

you can write

u = @u(x) + @u(y) +@u(z)

and yes

Qs> u(3,4,5)   #IT WILL Work

because you may not remember but I encode the functions in the memory based on their arguments number also

so u(x,y,z) now is the default function of u in 3 arguments 😉  (impressive for me I admit)


my beloved feature.

sequence now can return a function series

for example

e[n](x) ..> x^n/n!

e[1](1)  gives 1

however calling the sequence without specify argument (IN argument enables sequence)

e[1]  gives _(x) = x^1/1!

and you can assign it to a function also

let me make it fast

exp = e[0++20]


_(x) = (x^0/0!) + (x^1/1!) + (x^2/2!) + (x^3/3!) + (x^4/4!) + (x^5/5!) + (x^6/6!) + (x^7/7!) + (x^8/8!) + (x^9/9!) + (x^10/10!) + (x^11/11!) + (x^12/12!) + (x^13/13!) + (x^14/14!) + (x^15/15!) + (x^16/16!) + (x^17/17!) + (x^18/18!) + (x^19/19!) + (x^20/20!)

which when you can call your exp normally


Shifting Operators

I’ve added ‘>>‘ right shift as C family  and ‘<<‘ left shift

simply the operators is shifting vectors and matrices

not implemented yet for tensors

and also you will find these operators starting of Qs release  Changeset 39690

I hope I listed things that I remembered for now

and chaao 😀

‘When-Otherwise’ Condition Expression

In Quantity System Calculator (DLR)  I’ve implemented a new way of conditional expression that can be written continuously and fits into one line.

I called it  ‘when-otherwise’ expression

‘[true result] when [test] otherwise [false result] when …’

let us define a simple function with it

f(x)  = x when x< 10 otherwise x^2 when x<20 otherwise x^5

I know that I am going against the famous ‘if-then’ statement, however ‘if-then’ statement is an imperative syntax, and I needed a functional statement that fits in one line.

when I was thinking about this new syntax I also didn’t ignore the question syntax of C,C++, C#

‘Test?True Part, False Part’ , but also this syntax is somehow complex to use, and give me a headache actually.

thats why I invented it this way. You can see that the result part precede the condition part and the syntax is truly easy to remember (hard to type) but easy to extend.

About Scalar and Vector

Few Words

In my design of this calculator (although I am afraid it is evolving into language)

I made a decesion about making its types like the mathmatical numbering types

1- Scalar

2- Vector

3- Matrix

4- Tensor   (LATER LATER I HOPE)

The Scalar in Qs is  a normal  number with a unit.

(remember the idea of this calculator is that all numbers are quantities)

so Scalar in my programming model for now is  holding a quantity   which is number+unit

and ofcourse Vector is an array of Scalars

😀 the great thing I’ve discovered is that there are two Vector types

Vector Types

a) Euclidean Vector : This is only a three component vector

This Vector is always expressing the point in the space

It has the famous Cross Product Multiplication   (implemented in Qs as ‘x’ letter)

b) Normal Vector : This is an array holding a lot

This Vector is any number of components and can have Dot Product and

I am dealing with this types as a whole entity, I am not taking the approach of element by element calculation

because I am not convinced again about this approach :S

Multiplication Operators

So after great thinking and a lot of fancy shadows in my tiny room I made a three multiplication operators

1- Ordinary multiplication  ‘*’

2- Dot Product                          ‘.’

3- Cross Product                      ‘x’    <== YES it is the X letter 😀  [Who cares??!] my language after all 😀

Power Operators

and to make it worse I made a distinction between the three Power operators which are attached by meaning by their associated Multiplication operators

1- Ordinary Power              ‘^’

2- Dot Power                        ‘^.’               Which is different completely from the matlab ‘.^’ element power operator

3- Cross Power                   ‘^x’

Matrix Exponential

So you Remember about the sequence implementation

with sequence implementation I can make functions like sin, cos, and my famous Exponential sequence

Qs> e[n](x) ..> x^n/n!

then wrapping the sequence into a function call

Qs> e(x) = e[0++50](x)

This functions is working great in scalars

have you tried it with matrix ??

I tried it and succeed 🙂 look into this wikipedia page Matrix Exponential (by the way you should donate to wikipedia)

e^X = \sum_{k=0}^\infty{1 \over k!}X^k.

so if you passed a matrix to the function it will be treated as a whole matrix not element by element like matlab for example.

and this was an advantage from my model.

Power Dot

another funny thing is the ‘^.’ Power Dot when applying it to the vector.

by the way in any Power operation in Qs I get internally the first term to be Identity

for example in scalar it is 1<1>

Vector: {1<1> 1<1> … }   with the number of the components

Matrix Identity : Which is  diagonal ones  in a matrix with the same dimensions

\begin{array}{ccc}3 & 4 & 2\\7 & 4 & 3\\5 & 3 & 4\end{array}=\begin{array}{ccc}1\\& 1\\& & 1\end{array}

so when applying the Power dot to vector

first item  or zero repetion is the identity term, then by the power number I multiply the vector in the identity for repeat one and etc.

the funny thing is that dot product in vector gives a scalar value then scalar is multiplied by vector again to give a vector value then a scalar

so when you make a power dot to  an even exponent the result is vector, and when you make an odd exponent it will be scalar.

pretty strange 🙂

Relation Operators

Relation operators are <, >, <=, >=, ==, !=

ofcourse it is well known for scalars

but what about Vector and Scalar

I solved this issue by comparing the norm of the vector with the norm of the scalar

review Vector Norm so The comparison is based on Norm which is Absolute in Scalar and Magnitude in Vector.


As you can see implementing the Scalar, Vector , and Matrix as a first citizen entities in Qs is overwhelming

and a lot of challenges appeared.

however I hope that next post to be about my new innovative idea of the Comparison statement itself

see you 🙂


ok I mentioned before that I’ve implemented namespaces in my quantity system

Why I’ve made this ??

because simply I wanted to add the possibility of adding multi functions in a form of external libraries.

Namespace Operator or Separator

  1. in C++ the name space is two colons :: like the famous std::vector
  2. in C# the namespace is a dot . like  System.Console.WriteLine
  3. in xml the namespace is single colon :

so I’ve choose the xml namespace operator because I find it shorter than C++ namespace and more understandable than the dot of C#.

because I’ve always considered the dot .  to separate between the object and its members

Built in Functions

like any respectable language you have some built in library for mathmatical functions

you can find the functions and constants to be used 🙂

I’ve defined Math namespace to hold some (but not all) functions

Math:Sin, and Math:Sinh

Math:Cos, and Math:Cosh

Math:Log, and Math:Log10

and Math:PI  as a constant


User Defined Functions

you can define your user defined function in any namespace you desire

just write the namespace:function  and suddenly you have a new namespace if it wasn’t there before 😀

Qs> G:V(x,y) = x(y)   # function that take other function as a parameter

Qs> g:v(Math:Sin, 8 )  # passing built in sin function with 8


and as you can notice the functions and namespaces are all case insensitive.


User Defined Functions (External Modules)

and yes you can define your functions outside the quantity system

but the feature is not completed yet

however please try

Qs> Music:Play(c d e f g a b c>)

if you hear the music from your speaker then you are a windows guy 😀

and you can save this as a midi file too 😀

Qs> Music:SaveMidi(c d e f g a b c>, tt.mid)

please find the result file into the program directory.



About DLR and other funny things.


(Dynamic Runtime Library) is microsoft latest technology that will prove itself as long as .NET struggle to survive.

however this is an old news, you must heard about IronPython, and IronRuby.


My Quantity System Calculator is build over the DLR expressions. This has permitted me to do a numerous things in my calculator.

I added functions, new sequence concept, and lately implemented NameSpaces.

the latest DLR version is 0.92 and you can get it from


Funny Things

if you download the last Quantity system sources from the source panel in code plex

and run this code


Qs> Sin[n](x) ..> ((-1)^n*x^(2*n+1))/(2*n+1)! #Sin sequence

Qs> Sin(x) = Sin[0++50](x) #Sin function


Qs> Math:Sin(8)
DimensionlessQuantity: 0.989358246623382 <1>
Qs> Sin(8)
DimensionlessQuantity: 0.989358246623403 <1>
can you notice the difference between the last 3 digits from right

the first function from the Math:Sin(8) is a direct calling for the .NET Math.Sin  function

and the second Sin(8) is a call for my sequence-series implementation.

well I have double checked by the windows calculator and the result was the same as the .NET library.

Windows Calculator Sin(8) in radian mode: 0.98935824662338177780812359824529

So which one is the right approximation 🙂

let’s try to call the SIN series with less items


Qs> Sin[0++20](8)

DimensionlessQuantity: 0.989358246623414 <1>

ok also have an error

let’s try it for many more items.


Qs> Sin[0++160](8)

DimensionlessQuantity: 0.989358246623403 <1>

we are back to the same result 🙂

damn it 😀 what should i trust more??  my sequence-series implementation or the .NET Sin implementation, and what if this was obtained from the FPU ???



I really don’t know.




Quantities! are they all dimensional uniques??

Small Talk
Is it really important to have a unit associated to value.
I really don’t know the answer

I assumed it is important to know the dimension of the quantity.
* To be able to sum, and subtract different units but same dimension quantities.
* To be able to predict that the outcome of the division and multiplication process of quantities.
* To deduce how can I reach specific quantity from another quantity.

Article Begins
So let us focus on the important objective of the library and its calculator.
The main objective was to replace the Dimensionless Variable Concept into Quantity Concept

Reviewing the SI model there are 7 basic base units that form all of our Quantities experience in Life

🙂 do I really have to list them ?? I think I should 😦

1- kg (kilogram) [Mass]
2- m (metre) [Length]
3- s (second) [Time]
4- A (Ampere) [Electric Current]
5- K (Kelvin) [Temperature]
6- mol (mole) [Amount of Substance]
7- cd (candela) [Luminous Intensity]

these are 7 base quantities with 7 base units
(I feel they made it 7 so we can tie our self to the 7 number like 7 days and more legendary 7s)

if you encounter a fluid course in your study you will encounter the dimensional analysis course that teach you MLT system

the lecture will teach you about the dimensionality of the quantity
so Length is equal to M=0 L=1 T=0 or for simple writing M0L1T0

Speed or Velocity: M0L1T-1
Acceleration : M0L1T-2

Based on the dimensional Analysis course any quantity in universe have a unique dimensions

and we have special quantities that have M0L0T0 which means Dimensionless quantity

Types of Dimensionless quantities are many
Mach number.
Reynolds number.
Affinity Laws.

also based on professors philosophy Dimensionless numbers are a high class numbers because they always give a lot of information.

for example if I say I am traveling to Alexandria from Cairo
and you asked me about the distance I covered from the beginning of the trip!!
If I told you I passed 100 km from the distance you will wonder and may feel that information is not enough.
But if I told you that I passed half of the distance to Alexandria
you can deduce many things.
because you know roughly when I begin traveling.
you know the maximum speed between towns.
you can deduce when I should get there and in what hour.

practically you can sense and understand whats going on and what will happen.
or simply REALIZE

so dimensionless numbers are important for our life 🙂

Different Quantities and The same dimensions

BACK to quantities again

Force quantity are taken from the classical newton equations and it is Mass multiplied by Acceleration

F = kg * m/s^2

this is awesome so Force as a derived quantity = M1L1T-2

(NOTE: in dimensional analysis there is another approach to define dimensions by FLT system due to the fact that we can’t get mass without knowing the gravity of the location we are on now 🙂 however let us stick with MLT)

BUT can we REALLY say in honest words that all quantities have a different unique dimensions ??


and let me list them as I can remember for now:

1- (Work) vs (Torque):

The two concepts are referring to the same units which are Joule, calorie, or BTU

Work = Force * Length

The same as Torque

Torque = Force * Length

yes you can say that they are different quantities but look at them in units they are the same units N.m 😦

2- (Dimensionless) vs (Angle)
Angle is measured by Length of circumference to the length of radius.
it will be dimensionless

3- (Angle) vs (Solid Angle)
as angle units, steradian for solid angle
Solid angle is Area to Area

4-(Frequency) vs (Angular Velocity)
Frequency is equal to M0L0T-1 or 1/s i.e. (1/Time)
Angular Velocity = rad/s

and rad = 1 because it is dimensionless.

so summing frequency with angular velocity should be logically correct (because they resemble the same dimensions) WHICH is WRONG in literature.

do you remember the equation of Omega = 2 * Pi * f
Omega: Angular Velocity
f: Frequency.

5- (Luminous Intensity) vs (Luminous Flux)
The first quantity is lm/sr and the second one is (

Units can differentiate between the two quantities

but the unit is dimensionless and in SI standards you can replace either rad and sterad with which the dimensionless unit.


  1. These quantities will prevent any implementation to differentiate between quantities by dimensions and in return will prevent the intelligence of knowing the outcome quantity of an operation
  2. You can’t take the dimensional analysis approach in differentiating between quantities.

So in return most of the implementation of dimensionality of variables took the shorter approach of supporting only units side.

but where is the quantity ???

can the unit approach differentiate between Torque as N.m and Work as N.m

if you implemented the J (Joule) unit you will have to invent a unit for Torque also, so you can make a distinction between units.

But how about the rest of quantities.

In my next post I’ll introduce to you the hypothetical solution of this dilemma and how I solved this problem in my Quantity System implementation.

Thank you
Ahmed Sadek



This blog is about my last software Quantity System Framework

my Name is Ahmed Sadek
and I am a mechanical engineer who know how to program computers since MSX
my personal web site is which hold also my personal blog.
because I have a special interrest in programming and simulating the mechanical engineering problems into software.
I found that we really didn’t have a programming language that support unit conversion between the same quantity.
my first attempt to make this library was about 5 years ago.
I was making a progam to compute the heat gain through building using ASHRAE 97 method of TFM
back there I created a simple concept and tried to make it succeed.
(I FAILED) and you will know later WHY ?? 🙂
I’ve created this blog especially for writing about this piece of software this library
and my future plans about it.
as my ideas are now burning in my head this blog will serve as a source for ideas related to the scientific applications that will be built around this library.
Being a thermodynamic fan I know what is meant by Effeciency, Second Effeciency, and Availability.
I wanted to create this library (and later the calculator it self) for calculating effeciently not to make another program which let me decide what I should do.
(I have another things to decide about it)
The library and its calculator serve more than one goal (at least in my opinion)
First: young people who are un-aware about units and its conversion tricks
Second: Scientists who want to get their job done without making un-noticed mistakes.
The quantity system is the first to differentiate between work and Toruqe.
this is a really an important sentence.
if you looked into the previous implementations for the same idea.
you will find them lacking the dimensional approach
although they know about the concept and all those pretty things about Pukingham theory and dimensional analyis
but they simply choosed to ignore the dimensional approach because the lake of differentiating between Torque and Work
All other attempts before this one was ignoring this problem by employing the concept of units
without thinking about dimensions.
so their concept is “Unit” as the begining and ending to the problem, and by following the SI standards about units.
however this lead to a serious problem.
The problem about Work which is Force times Length N.m is the same as Torque Which is Force times Length also N.m.
So simple you CAN’t differentiate between Work and Torque by using only units
Another problem about angle
Have you ever looked into the Angle quantity
The Angle is dimensionless quantity which is Length Divided By Length.
And to make things even more worse
Solid Angle Quantity which Area divided by Area is also dimensionless quantity
and Angle unit is Radian
and Solid Angle units is Steradian
How can you differentiate between Angle and Solid Angle ??
telling me they have different units 🙂
let me ask again they are dimensionless
how will your program behave about that.
And these problems especially what made me fail before.
this problem also is the stone that render all other attempts as a weak implementation
But I insisted on one Concept
I have to think in quantities not in units
I solved the problem I’ll tell you about it next post.
And that leaded to another surprise for me which was the last thing to break my barriers in starting this blog.
This is a long post I think
but I think later posts will be more interresting for all of the readers
I have a bulk of ideas that are ready to implement.
I have this faith in making every thing open either information or implementation.
and I really wish to enhance our lives
Thank you
Ahmed Sadek