Click to See Complete Forum and Search --> : Analog data type
kedaman
May 15th, 2000, 08:31 PM
Ok, you know all that there are datatypes like integer, single and currency.
While integer (16bit) is spec: -32768...-2,-1,0,1,2...32,767 you can't specify any decimal values like 2.6689 or -6.32
With the Single-precision floating point (32bit) you can specify more exact values, but not too exact, but you will get pretty near a value
With Currency (64bit) you will get an exact value but only give a precision of 10^-4
With Decimal (96bit) you will get the optimal value with 28 digits to both sides of the "," so this one is most exact but still an integer
Ok, we have no true rational-value datatypes, only integers and floating points. My idea was to have a analog data type to specify both rational values like 3/7 and real values like sqr(2) and they will be stored at the same way as varlen strings so that we can calculate exact values for everything.
I got the idea from my TI-83 where I can store and calculate with complex values (not really rational but the i part is there)
Anyone have something to reply? I'm not sure if i'm talking to my self here, i would appreciate comments about my idea.
Juan Carlos Rey
May 15th, 2000, 10:31 PM
Sorry to tell you that computers as they are conceived today, are digital - it means discrete.
There is a minimum step between two numbers, (thus discrete) and that minimum is the BIT (BInary digiT). All you can do to improve resolution is increase the number of bits in a variable, but you'll never get analog performance.
But, man, when you'll need more than 64 / 96 digits of precision?
kedaman
May 15th, 2000, 10:57 PM
Well if you're an mathematician or scientist, you know why.
If not then i tell you that you wan't to store your Real or complex values and make calculations with proper answers
Digital' is just what all datatypes are until someone consider to do it my way: Store the particular parts of anlog constants combinated with rational values
Let's take an example here:
Dim a as Real
a=Sqr(2)
a=a*4
msgbox a 'Shows 4Sqr(2)
msgbox val(a) ' shows 5,656854...
msgbox int(a) ' shows 5
a=sqr(2)*sqr(2)
msgbox a 'Shows 2
a=pi*sqr(2)*sqr(3)
msgbox a 'Shows PiSqr(6)
Sam Finch
May 16th, 2000, 12:43 AM
Nice Idea, there's a language called maple that simplifies calculations like you're describing, you can even do something like this
Dim a as MapleDataType
Dim x as Long
Dim y as Long
Dim z as Long
(x*a^2) + (y*a) + z = 0
MsgBox a 'Returns (-y (+/-)Sqr( (y^2) - (4*x*z) ) ) / (2*x)
x = 2
y = -2
z = 1
MsgBox Val(a) 'Returns 0.5 (+/-) 0.5i
x = 1
y = 2
z = 1
MsgBox Val(a) ' Returns -1
a = Sqr(2)
MsgBox a ' Returns Sqr(2)
MsgBox Val(a) ' Returns 1.414213562
The Trouble is that it still only does calculations in double precision integers, so it does loose some accuracy, it's also slow as F***.
If we're trying to store a number as accuratley as we like there's only really one way of doing it, store the number like a string, but instead of characters store bytes, so
1F is 31
1F,01 is 64 + 31 (The lowest order byte is always stored first in memory)
and these can be as long as we like, there is some way of finding out their length, like we do with strings, (assume we've found a way of doing it so there is no limit to the length)
then to store any rational Number we like by storing 2 of these and dividing one by the other, we can also use a bit for remembering the sign, or, have 2 poitive ones, one stores the Modulus, the other stores the angle then we can have complex numbers as well.
there's 2 problems with this.
1. Calculations get really slow
2 Try to store an irrational number, you can't do it, if you tried to calculate Sqr(2) you would fill up your whole hard drive trying to store it, no matter how big it is.
kedaman
May 16th, 2000, 01:18 AM
I expected someone had already come up with this, as it's on my tiny ti-83 with complex values. Sam, where do i get that mapledatatype? I want to try it out.
Also i wanted to add that you should be able calculate with physical constants like c,h,e,...
Sam Finch
May 16th, 2000, 07:45 AM
well yeah, you'd need to learn Maple to do it, and Maple Sucks monkeys. you can't do calculations with irrational numbers, pi and e are irrational, and c and h are probably irrational but we havn't measured them accuratly enough.
an Irrational Data type needs an infinite abount of memory to store it and to do calculations on a number you need to store it, sorry ked, can't be done.
kedaman
May 16th, 2000, 10:24 AM
okok, but someone shoud make this var type in visual basic
vash2000
May 31st, 2000, 02:52 AM
Hang on a sec there.....there has to be a way of storing irrational numbers, or otherwise the calculators couldn't do it......Why don't you try to store your numbers in terms of logs, or re-write exponents so Sqrt(2) becomes 2^(1/2) or something like that.....I'm pretty sure that Base e logs are pre-programmed (If they're not, there are libraries out there). Give that a whirl :)
kedaman
May 31st, 2000, 03:11 AM
yeah, rational numbers can be stored in two vars in a class, irrational can be a classcollection with parts of rational numbers and irrational functions like sqr,^,log... And both custom and preset constants like e,pi,h...
Sam Finch
May 31st, 2000, 03:16 AM
No, they're stored to a few d.p. there's no point storing them to more than that because the results they give only need to be accurate enough for the 8 or so dp they display.
you can't store irrational numbers you can only store approximate values of them
kedaman
May 31st, 2000, 03:31 AM
No sam, i can store rational numbers in combination with irrational functions, the only problems is the constants, they need to be approximate
Sam Finch
May 31st, 2000, 04:59 AM
the only problems is the constants, they need to be approximate
irrational numbers are constants ked, there's nothing you can do with irrational numbers on computers, pi * 2 would take an infinite period of time to calculate. you just can't do it.
kedaman
May 31st, 2000, 06:52 AM
I know that doctor Sam, but what about having approximate values calculated and returned while the class handles the rational data and irrational functions?
When you do calculations in physics, you do them with a calculator of course, but you don't calculate the values all the time, you take formulas and reformulate an equation so that you can calculate the approximate value without rounding it all the time. That's what can be done in vb also, i suppose
As I was reading this thread, I was also thinking of Maple. As you've learned from Sam, Maple does "Symbolic" calculations. As far as "getting" the datatype, you might try MathCAD. MathCAD is inexpensive, based on Maple's engine, does symbolic calculations, AND can interface to C/C++ last I checked. (Probably other languages as well).
Gen-X
Jun 4th, 2000, 12:07 PM
but what about having approximate values calculated and returned
I thought a double floating point "approximated" the value and returned it ;-)
You can get it to 48 Decimal Places and if you want to go further than that then you are STILL approximating it.
Like someone has already said... You have 2 choices :
1. Do Symbolic Calculations (ie no values are stored)
2. Accept the fact there is a precision because your using a computer
Oh and about the calculator.... They usually have in-built code that automatically "rounds" it to the nearest value at the end of its precision.
So when you do sqrt(2) * sqrt(2) it gets the answer 1.9999999999 or 2.0000000001 but because the "next" digit is 9 it "rounds it to 10 which filters right up the line to give you the answer "2" or it chops the 0.0000000001 off the end.
It isn't anything "amazing"... Do PI to 6 decimal places and it will give you 3.141593 (The 3 being a rounding of the last digit which is 6).
kedaman
Jun 4th, 2000, 05:25 PM
Gen-x YOu seem not to get my point at all. The calculations are symbolic like maple, while the results alway are approximate, either floating or integer, that's a part you could choise. That's also how you work with formulas and equations in math and physics.
Gen-X
Jun 5th, 2000, 11:47 AM
No I got your point alright... *sigh* its just you keep forgetting the nature of a computer.
Ok, you store them as varlen strings... You do whatever you want but at SOME POINT you are going to actually turn that formula into a REAL number, something you can see on the screen...
At that point you are back to integers and floating points.
When you write something like "3/7" you can store it like "3/7" and thats fantastic...
But at the point where you say "Give me the answer" you get
"3/7" = 0.42857142857142857142857142857143
Now notice how the last digit went from a "2" to a "3" because the following "8" is > 5?
It has been "approximated".
So what point am I making?
The point is when you actually "START" to calculate a formula you have to process "PARTS" of that formula.
How do you think a computer adds 3 numbers together?
1 + 2 + 3 = 6
WRONG
A computer goes :
1. Register < 1
2. Register Add 2 -> (Register = 3)
3. Register Add 3 -> (Register = 6)
It has to TEMPORARILY store the value 3 (1+2) before it can add the last number 3 to it.
So for all your fancy storage of formula it will STILL have to at some point store these into a REGISTER which means its precision has been approximated.
The whole point of the exercise is lost.
Just so you don't all think I am a naysayer ;)
Here is a suggestion. Why not write a program that uses "STRINGS" as formula and instead of actually calculating anything it uses the rules of mathematics to combine formula etc... including the ability to rationalize them, analyse them and reduce them to their lowest form before actually doing the calculation?
kedaman
Jun 5th, 2000, 04:17 PM
Ok, Gen-x This time you got my point, but you wasn't cleaver enough to figure out why! My Ti-83 and I does the same thing, now except this time the computer does all the work for me.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.