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)
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
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.
Finally
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
Namespaces
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
- in C++ the name space is two colons :: like the famous std::vector
- in C# the namespace is a dot . like System.Console.WriteLine
- 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.
DLR
(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 http://dlr.codeplex.com
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
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 ??
{NO}
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
The same as Torque
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
where
Omega: Angular Velocity
f: Frequency.
5- (Luminous Intensity) vs (Luminous Flux)
——————————————–
The first quantity is lm/sr and the second one is (cd.sr)=lm
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.
Conclusion:
- 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
- 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
Introduction
This blog is about my last software Quantity System Framework