Sign in

username:

password:



Not a member?

Search msp430



Search tips

Subscribe to msp430





Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | MSP430 | OT: Binary Mathematics

The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.

OT: Binary Mathematics - solarquark - Sep 6 12:28:54 2009

Hi all.

I have been reading, and no doubt promptly forgetting, the MSP430 documentation. Rivetting stuff!

I have an off-topic query.
Does anyone know of an easy to understand document that would explain binary matematics to an idiot like me? I would really like something that would not only explain multiplication and division but also how to achieve calculations using logs (natural and unnatural) and any other mathematical functions that would prove useful.

Take care.

Mike

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )


RE: OT: Binary Mathematics - "Hayashi, Steve" - Sep 8 8:32:58 2009

Addition and subtraction are fairly simple. School children are taught to learn to add and subtract in different bases.

Multiplication and Division by any multiple of 2 is easy: Shift.

Multiplication the hard way is still fairly easy when done by hand.

1101
x 0101
------------
1101
00000
110100
0000000
-------------
1000001

Couldn't tell you anything about logs. But truly, if you're trying to recreate higher level mathematics on a processor like the MSP430, you should probably reevaluate your task.

-Steve

________________________________
From: m...@yahoogroups.com [mailto:m...@yahoogroups.com] On Behalf Of solarquark
Sent: Sunday, September 06, 2009 12:29 PM
To: m...@yahoogroups.com
Subject: [msp430] OT: Binary Mathematics

Hi all.

I have been reading, and no doubt promptly forgetting, the MSP430 documentation. Rivetting stuff!

I have an off-topic query.
Does anyone know of an easy to understand document that would explain binary matematics to an idiot like me? I would really like something that would not only explain multiplication and division but also how to achieve calculations using logs (natural and unnatural) and any other mathematical functions that would prove useful.

Take care.

Mike

[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: OT: Binary Mathematics - Jon Kirwan - Sep 8 10:18:47 2009

On Sun, 06 Sep 2009 16:28:35 -0000, you wrote:

>Does anyone know of an easy to understand document that would explain
>binary matematics to an idiot like me?

Start here:

http://webster.cs.ucr.edu/AoA/Windows/HTML/DataRepresentation.html#998834

Work forward through that chapter (3.)

That's a start, anyway.

>I would really like something that would not only explain
>multiplication and division but also how to achieve calculations using
>logs (natural and unnatural) and any other mathematical functions
>that would prove useful.

Most programmers don't worry too much about representation and just
use the tools they are given, instead. (Yes, I think that's a sad
loss; but there it is.) But if you read the above and can follow that
well enough and you sit down and use the techniques you've been taught
as a child for doing things like multiplication and division, long
hand for decimal, you will find that the same ideas work with binary.
It will take a moment to exercise those mental muscles and get
going... but it is a tiny bridge to cross, really. And you will get
to the other side just fine.

....

Now I'm going to switch gears for a moment and be a little
discouraging. I think you need to embrace the idea that a fuller
understanding isn't easy and just take one step at a time. Even the
above document on the web will only get you so far and no further.
It's not designed to give you the kind of knowledge you may need for
logarithms, for example -- though if you are a sharp one, you may see
it all the same quite easily.

Generally, there is no "easy to understand" path. There is a price to
pay in life for everything. The price for learning how to properly
and professionally write your own functions to calculuate things such
as log() or tan() is a personal education matched by personal hard
work. Just like learning how to properly build a home takes education
and hard work before you are truly competent at it. Anyone can learn
to pound a nail in short order. But there is so much more to properly
designing and preparing foundations, etc., and while pounding a nail
is important it is by no means all there is to learn.

There is no escaping the pragmatic reality that ignorance isn't swept
away by taking a pill or stuffing your head with sleep tapes or
finding some web site. If you imagine otherwise, even for a second,
you need to have your face slapped to bring you out of that dream.

The way out of ignorance is hard work. Period.

You show some lack of training in describing logs as natural and
_unnatural_. Mathematicians will use the term 'natural' to mean
something specific (base e) but otherwise specify the base with a
number or else are talking _without_ a need to specify a base (which
often doesn't matter to the point being made.) The term 'unnatural'
feels very stilted to me and I can't recall any mathematician ever
using it except maybe to make a joke.

That segues into another point. Setting aside the idea of calculating
them for a moment and just staying on the idea of using them (the
difference between being a gunsmith and a shooter of a gun), if you
aren't trained well with the application of mathematical functions,
you probably shouldn't be applying them except where others, who are
so trained, tell you to use them. So what will "prove useful" to you,
on your own, is probably a very limited set until you become better
educated in this area.

But generally speaking, the idea behind the log() of a binary number
is the same as the idea behind the log() of a number represented in
any other base. So if you know one, you do know the rest. There is
nothing new here.

If by writing "achieve calculations" you are wanting to understand how
to compute transcendental function results using code you write
yourself (and not the libraries others write for you), then you will
need a broad education in various techniques which will clearly
require a minimum of two years of college mathematics starting with
calculus. Three years would be more likely, but I don't want to speak
to what you can handle. Look for infinite and finite calculus,
differential equations (usually a 2nd year class), and some exposure
to Laplace and Fourier, recurrences, generating functions, and
Chebyshev (spelled a half a dozen different ways) polynomials and
economization all help. If after some education, you still imagine
using Taylor's to approximate a sine() function, you are not educated
enough. (Minimax techniques and a dose of numerical methods would
help, too.)

You can even use continued fractions for calculations, if you want,
and then handle irrationals with infinite precision on finite memory
computers. But that's yet another subject.

The point is you need an education in mathematics to reach towards
some calculations involving some functions, if you are going to
maintain other behaviors of them, such as monotonicity while also
keeping precision and speed in mind.

I haven't brought up different binary representations. You seem to
imagine there is one used in computers. Although it is today almost
universal that computers use one of two different, quite similar,
formats for integers (unsigned and a specific form of signed), there
are many others. One's complement and two's complement, to name two.
There are reasons why one or another may be preferred for some
application. There are an almost infinite variety of Gray codes, as
well -- which are essentially mere Hamiltonian walks on hypercubes.
Etc.

And there is group theory (finite and infinite, again), including
ideas of rings, fields, and so on. These apply to floating point
representations. (Something I haven't yet brought up, yet probably
needs to be broached because you brought up log() functions.) There
are fixed-field formats, infinite precision formats, variable
precision formats, continued fraction formats, and pretty much
anything you can come up with. Each is useful for something.

I bring all this up to illustrate a hint towards a majestic tapestry
ahead, which all relates in interesting ways to the question you
started with. At this point, you can only see a single thread here or
there. But there is much beauty and much work ahead if you are to
'see' all that is there to know and apply well.

....

Getting back to Earth. While addition and subtraction, and to be
honest multiplication too, are very basic and you can use your grade
school understanding with binary and get good results for many uses
from that... it does take a little more to fathom efficient methods
for division. Long hand almost gets you there, but you will need to
think closely to details to make it efficient. People who write early
learning books on VHDL or Verilog, used in programming everything from
FPGAs to ASIC chips, will provide some good education on division
methods. Best to look there, when you are ready for it.

.....

So what exactly did you want to know, again? ;)

Jon
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

RE: OT: Binary Mathematics - "Redd, Emmett R" - Sep 8 11:28:43 2009

Jon,

You almost made my head hurt and I have had a good number of those courses. :-)

Emmett Redd Ph.D. mailto:E...@missouristate.edu
Professor (417)836-5221
Department of Physics, Astronomy, and Materials Science
Missouri State University Fax (417)836-6226
901 SOUTH NATIONAL Lab (417)836-3770
SPRINGFIELD, MO 65897 USA Dept (417)836-5131

"In theory there is no difference between theory and practice. In practice there is." -- Yogi Berra or Jan van de Snepscheut

________________________________________
From: m...@yahoogroups.com [m...@yahoogroups.com] On Behalf Of Jon Kirwan [j...@infinitefactors.org]
Sent: Tuesday, September 08, 2009 9:17 AM
To: MSP430 list
Subject: Re: [msp430] OT: Binary Mathematics

On Sun, 06 Sep 2009 16:28:35 -0000, you wrote:

>Does anyone know of an easy to understand document that would explain
>binary matematics to an idiot like me?

Start here:

http://webster.cs.ucr.edu/AoA/Windows/HTML/DataRepresentation.html#998834

Work forward through that chapter (3.)

That's a start, anyway.

>I would really like something that would not only explain
>multiplication and division but also how to achieve calculations using
>logs (natural and unnatural) and any other mathematical functions
>that would prove useful.

Most programmers don't worry too much about representation and just
use the tools they are given, instead. (Yes, I think that's a sad
loss; but there it is.) But if you read the above and can follow that
well enough and you sit down and use the techniques you've been taught
as a child for doing things like multiplication and division, long
hand for decimal, you will find that the same ideas work with binary.
It will take a moment to exercise those mental muscles and get
going... but it is a tiny bridge to cross, really. And you will get
to the other side just fine.

....

Now I'm going to switch gears for a moment and be a little
discouraging. I think you need to embrace the idea that a fuller
understanding isn't easy and just take one step at a time. Even the
above document on the web will only get you so far and no further.
It's not designed to give you the kind of knowledge you may need for
logarithms, for example -- though if you are a sharp one, you may see
it all the same quite easily.

Generally, there is no "easy to understand" path. There is a price to
pay in life for everything. The price for learning how to properly
and professionally write your own functions to calculuate things such
as log() or tan() is a personal education matched by personal hard
work. Just like learning how to properly build a home takes education
and hard work before you are truly competent at it. Anyone can learn
to pound a nail in short order. But there is so much more to properly
designing and preparing foundations, etc., and while pounding a nail
is important it is by no means all there is to learn.

There is no escaping the pragmatic reality that ignorance isn't swept
away by taking a pill or stuffing your head with sleep tapes or
finding some web site. If you imagine otherwise, even for a second,
you need to have your face slapped to bring you out of that dream.

The way out of ignorance is hard work. Period.

You show some lack of training in describing logs as natural and
_unnatural_. Mathematicians will use the term 'natural' to mean
something specific (base e) but otherwise specify the base with a
number or else are talking _without_ a need to specify a base (which
often doesn't matter to the point being made.) The term 'unnatural'
feels very stilted to me and I can't recall any mathematician ever
using it except maybe to make a joke.

That segues into another point. Setting aside the idea of calculating
them for a moment and just staying on the idea of using them (the
difference between being a gunsmith and a shooter of a gun), if you
aren't trained well with the application of mathematical functions,
you probably shouldn't be applying them except where others, who are
so trained, tell you to use them. So what will "prove useful" to you,
on your own, is probably a very limited set until you become better
educated in this area.

But generally speaking, the idea behind the log() of a binary number
is the same as the idea behind the log() of a number represented in
any other base. So if you know one, you do know the rest. There is
nothing new here.

If by writing "achieve calculations" you are wanting to understand how
to compute transcendental function results using code you write
yourself (and not the libraries others write for you), then you will
need a broad education in various techniques which will clearly
require a minimum of two years of college mathematics starting with
calculus. Three years would be more likely, but I don't want to speak
to what you can handle. Look for infinite and finite calculus,
differential equations (usually a 2nd year class), and some exposure
to Laplace and Fourier, recurrences, generating functions, and
Chebyshev (spelled a half a dozen different ways) polynomials and
economization all help. If after some education, you still imagine
using Taylor's to approximate a sine() function, you are not educated
enough. (Minimax techniques and a dose of numerical methods would
help, too.)

You can even use continued fractions for calculations, if you want,
and then handle irrationals with infinite precision on finite memory
computers. But that's yet another subject.

The point is you need an education in mathematics to reach towards
some calculations involving some functions, if you are going to
maintain other behaviors of them, such as monotonicity while also
keeping precision and speed in mind.

I haven't brought up different binary representations. You seem to
imagine there is one used in computers. Although it is today almost
universal that computers use one of two different, quite similar,
formats for integers (unsigned and a specific form of signed), there
are many others. One's complement and two's complement, to name two.
There are reasons why one or another may be preferred for some
application. There are an almost infinite variety of Gray codes, as
well -- which are essentially mere Hamiltonian walks on hypercubes.
Etc.

And there is group theory (finite and infinite, again), including
ideas of rings, fields, and so on. These apply to floating point
representations. (Something I haven't yet brought up, yet probably
needs to be broached because you brought up log() functions.) There
are fixed-field formats, infinite precision formats, variable
precision formats, continued fraction formats, and pretty much
anything you can come up with. Each is useful for something.

I bring all this up to illustrate a hint towards a majestic tapestry
ahead, which all relates in interesting ways to the question you
started with. At this point, you can only see a single thread here or
there. But there is much beauty and much work ahead if you are to
'see' all that is there to know and apply well.

....

Getting back to Earth. While addition and subtraction, and to be
honest multiplication too, are very basic and you can use your grade
school understanding with binary and get good results for many uses
from that... it does take a little more to fathom efficient methods
for division. Long hand almost gets you there, but you will need to
think closely to details to make it efficient. People who write early
learning books on VHDL or Verilog, used in programming everything from
FPGAs to ASIC chips, will provide some good education on division
methods. Best to look there, when you are ready for it.

.....

So what exactly did you want to know, again? ;)

Jon
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: OT: Binary Mathematics - Michael Malone - Sep 8 11:39:33 2009

Thanks for the response, Steve.

It has been a long, long time since I was in school - so long I can't even remember if we had covered matematics in different number bases.
I'm fairly certain I 'get' (in my head that is) binary addition and subtraction.
I think I 'get' multiplication.
I don't, yet, understand division.

wrt logs, and other functions (sin, cos, tan, etc) - I haven't a clue (yet).

I know I don't _need_ to know. If I use c then I can just use an appropriate library.
There may even be ready made assembly libraries that I can just import - I don't know (yet).
But I like to have a good understanding of any subject I approach.
This understanding is just for me. I'm silly that way.

Mike

________________________________
From: "Hayashi, Steve"
To: "m...@yahoogroups.com"
Sent: Tuesday, September 8, 2009 1:32:12 PM
Subject: RE: [msp430] OT: Binary Mathematics

Addition and subtraction are fairly simple. School children are taught to learn to add and subtract in different bases.

Multiplication and Division by any multiple of 2 is easy: Shift.

Multiplication the hard way is still fairly easy when done by hand.

1101
x 0101
------------
1101
00000
110100
0000000
------------ -
1000001

Couldn't tell you anything about logs. But truly, if you're trying to recreate higher level mathematics on a processor like the MSP430, you should probably reevaluate your task.

-Steve

____________ _________ _________ __
From: msp430@yahoogroups. com [mailto:msp430@yahoogroups. com] On Behalf Of solarquark
Sent: Sunday, September 06, 2009 12:29 PM
To: msp430@yahoogroups. com
Subject: [msp430] OT: Binary Mathematics

Hi all.

I have been reading, and no doubt promptly forgetting, the MSP430 documentation. Rivetting stuff!

I have an off-topic query.
Does anyone know of an easy to understand document that would explain binary matematics to an idiot like me? I would really like something that would not only explain multiplication and division but also how to achieve calculations using logs (natural and unnatural) and any other mathematical functions that would prove useful.

Take care.

Mike

[Non-text portions of this message have been removed]
[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: OT: Binary Mathematics - Jon Kirwan - Sep 8 11:55:43 2009

On Tue, 8 Sep 2009 08:39:13 -0700 (PDT), you wrote:

>
>I know I don't _need_ to know. If I use c then I can just use an
>appropriate library. There may even be ready made assembly libraries
>that I can just import - I don't know (yet). But I like to have a
>good understanding of any subject I approach.

>This understanding is just for me. I'm silly that way.

I LIKE that attitude and find it all too rare. Look up some of the
terms I handed out, then. If you have a specific function you'd like
to use as a segue into a cornucopia of new ideas, I can try and supply
some reading suggestions.

By the way, one of the better ones I know about and which is a lot of
fun (if fun can be had at all here) is a book titled "Concrete
Mathematics: A Foundation for Computer Science," by Graham, Knuth, and
Patashnik, 2nd edition. (If there is a 3rd edition, let me know so I
can buy it.) There you will get exposed to some very important
foundation subjects, including recurrences, generating functions,
finite calculus, and important special subjects like Stirling,
Bernoulli, and harmonic numbers, etc. It's not dry, either. The
authors include margin notes by students and the writing is lively.

Jon
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: OT: Binary Mathematics - Michael Malone - Sep 8 12:06:12 2009

Thank you, Jon.

As one of our species is reputed to have said 'A journey of a thousand miles begins with a single step'.
And another 'The purpose of education is not to fill minds but to open them' or variants of the same '... to take an empty mind and open it', etc.

There is great beauty in mathematics. But I have had little opportunity to pursue such esoteric and often elusive pleasures so far. And although I must exercise my mind to try to regain some lost functionaltity I also am starting (again) from a low base and must not overreach.

I apologise for my use of 'unnatural' in describing logs that would not have the adjective 'natural' attached - this is just an example of my weird sense of humour.

Many thanks for the link.

'A good start is half the work'.

Take care.

Mike
________________________________
From: Jon Kirwan
To: MSP430 list
Sent: Tuesday, September 8, 2009 3:17:58 PM
Subject: Re: [msp430] OT: Binary Mathematics

On Sun, 06 Sep 2009 16:28:35 -0000, you wrote:

>Does anyone know of an easy to understand document that would explain
>binary matematics to an idiot like me?

Start here:

http://webster. cs.ucr.edu/ AoA/Windows/ HTML/DataReprese ntation.html# 998834

Work forward through that chapter (3.)

That's a start, anyway.

>I would really like something that would not only explain
>multiplication and division but also how to achieve calculations using
>logs (natural and unnatural) and any other mathematical functions
>that would prove useful.

Most programmers don't worry too much about representation and just
use the tools they are given, instead. (Yes, I think that's a sad
loss; but there it is.) But if you read the above and can follow that
well enough and you sit down and use the techniques you've been taught
as a child for doing things like multiplication and division, long
hand for decimal, you will find that the same ideas work with binary.
It will take a moment to exercise those mental muscles and get
going... but it is a tiny bridge to cross, really. And you will get
to the other side just fine.

....

Now I'm going to switch gears for a moment and be a little
discouraging. I think you need to embrace the idea that a fuller
understanding isn't easy and just take one step at a time. Even the
above document on the web will only get you so far and no further.
It's not designed to give you the kind of knowledge you may need for
logarithms, for example -- though if you are a sharp one, you may see
it all the same quite easily.

Generally, there is no "easy to understand" path. There is a price to
pay in life for everything. The price for learning how to properly
and professionally write your own functions to calculuate things such
as log() or tan() is a personal education matched by personal hard
work. Just like learning how to properly build a home takes education
and hard work before you are truly competent at it. Anyone can learn
to pound a nail in short order. But there is so much more to properly
designing and preparing foundations, etc., and while pounding a nail
is important it is by no means all there is to learn.

There is no escaping the pragmatic reality that ignorance isn't swept
away by taking a pill or stuffing your head with sleep tapes or
finding some web site. If you imagine otherwise, even for a second,
you need to have your face slapped to bring you out of that dream.

The way out of ignorance is hard work. Period.

You show some lack of training in describing logs as natural and
_unnatural_. Mathematicians will use the term 'natural' to mean
something specific (base e) but otherwise specify the base with a
number or else are talking _without_ a need to specify a base (which
often doesn't matter to the point being made.) The term 'unnatural'
feels very stilted to me and I can't recall any mathematician ever
using it except maybe to make a joke.

That segues into another point. Setting aside the idea of calculating
them for a moment and just staying on the idea of using them (the
difference between being a gunsmith and a shooter of a gun), if you
aren't trained well with the application of mathematical functions,
you probably shouldn't be applying them except where others, who are
so trained, tell you to use them. So what will "prove useful" to you,
on your own, is probably a very limited set until you become better
educated in this area.

But generally speaking, the idea behind the log() of a binary number
is the same as the idea behind the log() of a number represented in
any other base. So if you know one, you do know the rest. There is
nothing new here.

If by writing "achieve calculations" you are wanting to understand how
to compute transcendental function results using code you write
yourself (and not the libraries others write for you), then you will
need a broad education in various techniques which will clearly
require a minimum of two years of college mathematics starting with
calculus. Three years would be more likely, but I don't want to speak
to what you can handle. Look for infinite and finite calculus,
differential equations (usually a 2nd year class), and some exposure
to Laplace and Fourier, recurrences, generating functions, and
Chebyshev (spelled a half a dozen different ways) polynomials and
economization all help. If after some education, you still imagine
using Taylor's to approximate a sine() function, you are not educated
enough. (Minimax techniques and a dose of numerical methods would
help, too.)

You can even use continued fractions for calculations, if you want,
and then handle irrationals with infinite precision on finite memory
computers. But that's yet another subject.

The point is you need an education in mathematics to reach towards
some calculations involving some functions, if you are going to
maintain other behaviors of them, such as monotonicity while also
keeping precision and speed in mind.

I haven't brought up different binary representations. You seem to
imagine there is one used in computers. Although it is today almost
universal that computers use one of two different, quite similar,
formats for integers (unsigned and a specific form of signed), there
are many others. One's complement and two's complement, to name two.
There are reasons why one or another may be preferred for some
application. There are an almost infinite variety of Gray codes, as
well -- which are essentially mere Hamiltonian walks on hypercubes.
Etc.

And there is group theory (finite and infinite, again), including
ideas of rings, fields, and so on. These apply to floating point
representations. (Something I haven't yet brought up, yet probably
needs to be broached because you brought up log() functions.) There
are fixed-field formats, infinite precision formats, variable
precision formats, continued fraction formats, and pretty much
anything you can come up with. Each is useful for something.

I bring all this up to illustrate a hint towards a majestic tapestry
ahead, which all relates in interesting ways to the question you
started with. At this point, you can only see a single thread here or
there. But there is much beauty and much work ahead if you are to
'see' all that is there to know and apply well.

....

Getting back to Earth. While addition and subtraction, and to be
honest multiplication too, are very basic and you can use your grade
school understanding with binary and get good results for many uses
from that... it does take a little more to fathom efficient methods
for division. Long hand almost gets you there, but you will need to
think closely to details to make it efficient. People who write early
learning books on VHDL or Verilog, used in programming everything from
FPGAs to ASIC chips, will provide some good education on division
methods. Best to look there, when you are ready for it.

.....

So what exactly did you want to know, again? ;)

Jon

[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: OT: Binary Mathematics - Jon Kirwan - Sep 8 12:20:22 2009

On Tue, 8 Sep 2009 10:27:22 -0500, you wrote:

>You almost made my head hurt and I have had a good number of those
>courses. :-)
>

:) I guess I've got some baggage I'm unloading.

One seems 'political' though it shouldn't have to be. It's that
ignorance is the natural condition of humans and that succumbing to
the ignorant rut of acceptance-of/promulgation-by authority figures is
the downhill slope and the easy path. And it leads us all to mutual
ruin, politically, socially, and personally. Each of us has a duty to
fight the hard uphill battle out of ignorance with the courage and
hard work it actually takes.

We come into this world with nothing but evolved reactions and a
capacity to survive. We leave it, taking out with us everything we've
gained in a lifetime of civilized education and hard work (those of us
who aren't born with a silver spoon in our mouths, anyway.) The
process of passing along that science knowledge, to be carried in
newer heads as older ones leave us, is a fast pacing treadmill we
cannot afford to get off of. We either pay the price to pass along
knowledge or else our very civilization itself declines for the
failure to keep up. To stay at the same place, we have to run the
treadmill at the same rate. To advance, we have to run still harder.

To stop running on the treadmill is to fly off into a return to
ignorant oblivion. None of us can afford that luxury.

Another is that too many in _this_ business, in my experience, only
want to learn what is staring them in the face and even then only just
enough to get by for the immediate project at hand. Mike appears NOT
to be one of these. Which is a good thing, in my book. I wish I saw
more of that than I have. (Yes, I've taught computer science at the
university level and I've seen the kids go by over the years.)

Jon
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: OT: Binary Mathematics - Michael Malone - Sep 8 12:23:55 2009

"Concrete Mathematics: A Foundation for Computer Science," by Graham, Knuth, and
Patashnik, 2nd edition.

Ordered.

Thanks Jon.

Mike
________________________________
From: Jon Kirwan
To: MSP430 list
Sent: Tuesday, September 8, 2009 4:55:21 PM
Subject: Re: [msp430] OT: Binary Mathematics

On Tue, 8 Sep 2009 08:39:13 -0700 (PDT), you wrote:

>
>I know I don't _need_ to know. If I use c then I can just use an
>appropriate library. There may even be ready made assembly libraries
>that I can just import - I don't know (yet). But I like to have a
>good understanding of any subject I approach.

>This understanding is just for me. I'm silly that way.

I LIKE that attitude and find it all too rare. Look up some of the
terms I handed out, then. If you have a specific function you'd like
to use as a segue into a cornucopia of new ideas, I can try and supply
some reading suggestions.

By the way, one of the better ones I know about and which is a lot of
fun (if fun can be had at all here) is a book titled "Concrete
Mathematics: A Foundation for Computer Science," by Graham, Knuth, and
Patashnik, 2nd edition. (If there is a 3rd edition, let me know so I
can buy it.) There you will get exposed to some very important
foundation subjects, including recurrences, generating functions,
finite calculus, and important special subjects like Stirling,
Bernoulli, and harmonic numbers, etc. It's not dry, either. The
authors include margin notes by students and the writing is lively.

Jon

[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: OT: Binary Mathematics - p_murayama - Sep 8 21:23:56 2009

Hello!

Now I feel I have to start my journey by hunting the log among
other numbers.

In this delirium, I will use the following conventions:
a^b means power. Example 10^2 =3D 100.
Since there are sometimes several levels of brackets, then I will use ()
for the lowest, then [] and {}.

Here we go!

1 In the beginning, the mathematician said: let there be numbers.
2 And there were numbers, and he saw that this was f**ing good.
3 There was an evening with many beers to celebrate, there was wine,
there was sake, a few rails of coke.
4. And there was a morning with incredible headaches. It was the second day=
.
5. And the mathematician took a few painkillers.
6. And he got fuzzy until noon.
7. And he was looking at its creation and got amazed.

I'll skip a few steps, and report what the mathematician noticed:

If you make a sum of the n first integer powers of a number a, you get:

1 + a^1 + a^2 + a^3 =85. +a^n =3D [1-a^(n+1)] / (1-a) (A)
Lets's call Sn =3D 1 + a^1 + a^2 + a^3 =85. +a^n=20
and Rn =3D [1-a^(n+1)] / (1-a)

Let's prove it: let's assume that until n, the formula (A) works.

Now let's calculate at rank n+1:

S(n+1) =3D Sn + a^(n+1) =3D Rn + a^(n+1)=20
=3D {[1-a^(n+1)] / (1-a)} + a^(n+1)

Multiplying a^(n+1) by 1-a in order to get the same denominator:

=3D {[1-a^(n+1)] / (1-a)} + [(1-a)*a^(n+1)] / (1-a)

=3D [1 - a^(n+1) + a^(n+1) - a^(n+2)] / (1-a)

The n-1 terms disappear, and we have:

S(n+1) =3D [1 - a^(n+2)] / (1-a)

What we have shown here is that if it works at rank n, then it works at ran=
k n+1.
An important point is also to show that it works at rank 1.
1 + a =3D (1 - a^2) / (1-a). This is a known result, usually written (1-a)(=
1+a) =3D (1-a^2)
Consequence of this:
- It works at rank 1
- If it works at a given rank n, then it works at n+1
Therefree this relation works for any (a, n) combination.

Now if we assume that the absolute value of a is less than 1, then the nume=
rator
will go to 1 with high powers, and therefore the polynomial 1 + x + x^2 =85=
+x^n
will converge to 1 / (1-x). Let's stress again that while the general formu=
la (A) works
everywhere, this latter formula works only for small values of x.

To summarize this result:
Around 0:

1 / (1-x) =3D 1 + x + x^2 +x^3 + =85.. (infinite sum) (B)

There was a second night of celebration, many beers, naked womans, kilogram=
s
of coke, sake, etc...
There was a morning, that was the 3rd day, and the mathematician was starti=
ng
thinking that nobody would give a rat's ass about what he found the previou=
s day.

So he had a cool idea: integrate (B) at both sides. And he got:

-ln(1-x) =3D x + (x^2)/2 +(x^3)/3 + =85.. + (x^n)/n=85.

Therefore

ln(1-x) =3D - x - (x^2)/2 -(x^3)/3 + =85.. - (x^n)/n

Now the problem is that x must be close to 0=85

At this point, the mathematician made a mistake (consequence of successive
celebrations), and wrote 1+x instead of 1-x.
The sequence does not change for even powers, but does for odd ones. The
sign will alternate.

ln(1+x) =3D x - (x^2)/2 + (x^3)/3 + =85..

And he said, why not subtracting the logs. All the even powers will vanish,=
which will
reduce the amount of computation. Here we go:

ln(1+x) - ln(1-x) =3D 2x + 2*(x^3)/3 + 2*(x^5)/5 =85.=20

And since ln(a) - ln(b) =3D ln(a/b), we obtain:

ln[(1+x)/(1-x)] =3D 2 [x + (x^3)/3 +(x^5)/5 =85. ]

Now the good thing is that around 0 (in the interval ]-1, +1[, borders excl=
uded), the
ratio (1+x)/(1-x) will take any value between 0 and infinity.

So if we let a =3D (1-x)/(1+x), we can calculate x backwards like this:

a =3D (1+x) / (1-x)
a - ax =3D 1+x
a - 1 =3D x + ax
a-1 =3D x (1+a)

then finally: x =3D (a-1) / (a+1)

The result of this is that we can calculate ln(a) for any value like this:

We will use an intermediary variable to help the calculation:
x =3D (a-1) / (a+1)

and then we can calculate ln(a)

ln(a) =3D 2[x + (x^3)/3 + (x^5)/5 =85.]

Now the inconvenience of this algorithm: for large numbers, you get a x rat=
io
very close to 1, and the convergence is slow.
Example: if you want to calculate ln(100), then (100 - 1) / (100 + 1) =3D 0=
.98.
The successive powers of 0.9801 decrease slowly. At the 15th power, you're =
still
at 0.74, so if you leave from rank 15, then you will get an error of about
0.75 / 15 =3D 0.05.

So here is a trick.
You want to calculate ln(100). In this case, x =3D 0.98.
But you can say that ln(100) =3D 1 + ln(100/e)
100/e =3D 36.78, in which case the ratio becomes 0.95.
Doing the same trick until the remainder is less than e, and we get:

ln(100) =3D 4 + ln[100/{e^4)] =3D 4 + ln(1.83)
in this case, the intermediate variable x becomes 0.29.
The 15th power of 0.29 is 0.000000002996, so that if you stop at rank 15,
the error on your result will be in the order of 10^-9. Now the worst case
is when the successive divisions by e come close to e itself. In this
case, the x ratio will be 0.462, and at the 15th power, you will get
0.000004, therefore the error when leaving at the 15 th power is less
than 0.000001, which might be acceptable in most of the cases.

As a conclusion: don't do this in an embedded environment.
If you need logs, then use a table. If a table is not accurate enough,
you may also interpolate the table. If you _really_ cannot avoid having a
great precision (I would be curious about the application), then use
a library.

Pascal

--- In m...@yahoogroups.com, Michael Malone wrote:
>
> Thank you, Jon.
>=20
> As one of our species is reputed to have said 'A journey of a thousand mi=
les begins with a single step'.
> And another 'The purpose of education is not to fill minds but to open th=
em' or variants of the same '... to take an empty mind and open it', etc.
>=20
> There is great beauty in mathematics. But I have had little opportunity t=
o pursue such esoteric and often elusive pleasures so far. And although I m=
ust exercise my mind to try to regain some lost functionaltity I also am st=
arting (again) from a low base and must not overreach.
>=20
> I apologise for my use of 'unnatural' in describing logs that would not h=
ave the adjective 'natural' attached - this is just an example of my weird =
sense of humour.
>=20
> Many thanks for the link.=20
>=20
> 'A good start is half the work'.
>=20
> Take care.
>=20
> Mike
>=20
>=20
>=20
>=20
> ________________________________
> From: Jon Kirwan
> To: MSP430 list
> Sent: Tuesday, September 8, 2009 3:17:58 PM
> Subject: Re: [msp430] OT: Binary Mathematics
>=20
>=20=20=20
> On Sun, 06 Sep 2009 16:28:35 -0000, you wrote:
>=20
> >Does anyone know of an easy to understand document that would explain
> >binary matematics to an idiot like me?
>=20
> Start here:
>=20
> http://webster. cs.ucr.edu/ AoA/Windows/ HTML/DataReprese ntation.html# 9=
98834
>=20
> Work forward through that chapter (3.)
>=20
> That's a start, anyway.
>=20
> >I would really like something that would not only explain
> >multiplication and division but also how to achieve calculations using
> >logs (natural and unnatural) and any other mathematical functions
> >that would prove useful.
>=20
> Most programmers don't worry too much about representation and just
> use the tools they are given, instead. (Yes, I think that's a sad
> loss; but there it is.) But if you read the above and can follow that
> well enough and you sit down and use the techniques you've been taught
> as a child for doing things like multiplication and division, long
> hand for decimal, you will find that the same ideas work with binary.
> It will take a moment to exercise those mental muscles and get
> going... but it is a tiny bridge to cross, really. And you will get
> to the other side just fine.
>=20
> ....
>=20
> Now I'm going to switch gears for a moment and be a little
> discouraging. I think you need to embrace the idea that a fuller
> understanding isn't easy and just take one step at a time. Even the
> above document on the web will only get you so far and no further.
> It's not designed to give you the kind of knowledge you may need for
> logarithms, for example -- though if you are a sharp one, you may see
> it all the same quite easily.
>=20
> Generally, there is no "easy to understand" path. There is a price to
> pay in life for everything. The price for learning how to properly
> and professionally write your own functions to calculuate things such
> as log() or tan() is a personal education matched by personal hard
> work. Just like learning how to properly build a home takes education
> and hard work before you are truly competent at it. Anyone can learn
> to pound a nail in short order. But there is so much more to properly
> designing and preparing foundations, etc., and while pounding a nail
> is important it is by no means all there is to learn.
>=20
> There is no escaping the pragmatic reality that ignorance isn't swept
> away by taking a pill or stuffing your head with sleep tapes or
> finding some web site. If you imagine otherwise, even for a second,
> you need to have your face slapped to bring you out of that dream.
>=20
> The way out of ignorance is hard work. Period.
>=20
> You show some lack of training in describing logs as natural and
> _unnatural_. Mathematicians will use the term 'natural' to mean
> something specific (base e) but otherwise specify the base with a
> number or else are talking _without_ a need to specify a base (which
> often doesn't matter to the point being made.) The term 'unnatural'
> feels very stilted to me and I can't recall any mathematician ever
> using it except maybe to make a joke.
>=20
> That segues into another point. Setting aside the idea of calculating
> them for a moment and just staying on the idea of using them (the
> difference between being a gunsmith and a shooter of a gun), if you
> aren't trained well with the application of mathematical functions,
> you probably shouldn't be applying them except where others, who are
> so trained, tell you to use them. So what will "prove useful" to you,
> on your own, is probably a very limited set until you become better
> educated in this area.
>=20
> But generally speaking, the idea behind the log() of a binary number
> is the same as the idea behind the log() of a number represented in
> any other base. So if you know one, you do know the rest. There is
> nothing new here.
>=20
> If by writing "achieve calculations" you are wanting to understand how
> to compute transcendental function results using code you write
> yourself (and not the libraries others write for you), then you will
> need a broad education in various techniques which will clearly
> require a minimum of two years of college mathematics starting with
> calculus. Three years would be more likely, but I don't want to speak
> to what you can handle. Look for infinite and finite calculus,
> differential equations (usually a 2nd year class), and some exposure
> to Laplace and Fourier, recurrences, generating functions, and
> Chebyshev (spelled a half a dozen different ways) polynomials and
> economization all help. If after some education, you still imagine
> using Taylor's to approximate a sine() function, you are not educated
> enough. (Minimax techniques and a dose of numerical methods would
> help, too.)
>=20
> You can even use continued fractions for calculations, if you want,
> and then handle irrationals with infinite precision on finite memory
> computers. But that's yet another subject.
>=20
> The point is you need an education in mathematics to reach towards
> some calculations involving some functions, if you are going to
> maintain other behaviors of them, such as monotonicity while also
> keeping precision and speed in mind.
>=20
> I haven't brought up different binary representations. You seem to
> imagine there is one used in computers. Although it is today almost
> universal that computers use one of two different, quite similar,
> formats for integers (unsigned and a specific form of signed), there
> are many others. One's complement and two's complement, to name two.
> There are reasons why one or another may be preferred for some
> application. There are an almost infinite variety of Gray codes, as
> well -- which are essentially mere Hamiltonian walks on hypercubes.
> Etc.
>=20
> And there is group theory (finite and infinite, again), including
> ideas of rings, fields, and so on. These apply to floating point
> representations. (Something I haven't yet brought up, yet probably
> needs to be broached because you brought up log() functions.) There
> are fixed-field formats, infinite precision formats, variable
> precision formats, continued fraction formats, and pretty much
> anything you can come up with. Each is useful for something.
>=20
> I bring all this up to illustrate a hint towards a majestic tapestry
> ahead, which all relates in interesting ways to the question you
> started with. At this point, you can only see a single thread here or
> there. But there is much beauty and much work ahead if you are to
> 'see' all that is there to know and apply well.
>=20
> ....
>=20
> Getting back to Earth. While addition and subtraction, and to be
> honest multiplication too, are very basic and you can use your grade
> school understanding with binary and get good results for many uses
> from that... it does take a little more to fathom efficient methods
> for division. Long hand almost gets you there, but you will need to
> think closely to details to make it efficient. People who write early
> learning books on VHDL or Verilog, used in programming everything from
> FPGAs to ASIC chips, will provide some good education on division
> methods. Best to look there, when you are ready for it.
>=20
> .....
>=20
> So what exactly did you want to know, again? ;)
>=20
> Jon
>=20
>=20=20=20=20
>=20
>=20
>=20=20=20=20=20=20=20
>=20
> [Non-text portions of this message have been removed]
>
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

RAM,ROM and FLAsh - =?iso-8859-1?Q?FabWar=AE?= - Sep 9 3:09:13 2009

Hello all,

How do I know, how much RAM, ROM and flash being used for my program? What are kind of thing store in ROM, RAM and flash

[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: RAM,ROM and FLAsh - "John C. Westmoreland, P.E." - Sep 9 3:43:48 2009

FW,

You can find what you are looking for in your linker MAP file - check your =
linker command file and/or IDE for details.

HTH,
John W.

----- Original Message -----=20
From: FabWar=AE=20
To: m...@yahoogroups.com=20
Sent: Wednesday, September 09, 2009 12:09 AM
Subject: [msp430] RAM,ROM and FLAsh
Hello all,

How do I know, how much RAM, ROM and flash being used for my program? Wha=
t are kind of thing store in ROM, RAM and flash

[Non-text portions of this message have been removed]

=20=20

[Non-text portions of this message have been removed]

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: OT: Binary Mathematics - diegomongo - Oct 19 19:07:36 2009


Hey That was great! I don't think I would ever use it tho... great journey =
none the lesss...=20

--- In m...@yahoogroups.com, "p_murayama" wrote:
>
> Hello!
>=20
> Now I feel I have to start my journey by hunting the log among
> other numbers.
>=20
> In this delirium, I will use the following conventions:
> a^b means power. Example 10^2 =3D 100.
> Since there are sometimes several levels of brackets, then I will use ()
> for the lowest, then [] and {}.
>=20
> Here we go!
>=20
> 1 In the beginning, the mathematician said: let there be numbers.
> 2 And there were numbers, and he saw that this was f**ing good.
> 3 There was an evening with many beers to celebrate, there was wine,
> there was sake, a few rails of coke.
> 4. And there was a morning with incredible headaches. It was the second d=
ay.
> 5. And the mathematician took a few painkillers.
> 6. And he got fuzzy until noon.
> 7. And he was looking at its creation and got amazed.
>=20
> I'll skip a few steps, and report what the mathematician noticed:
>=20
> If you make a sum of the n first integer powers of a number a, you get:
>=20
> 1 + a^1 + a^2 + a^3 =85. +a^n =3D [1-a^(n+1)] / (1-a) (A)
> Lets's call Sn =3D 1 + a^1 + a^2 + a^3 =85. +a^n=20
> and Rn =3D [1-a^(n+1)] / (1-a)
>=20
> Let's prove it: let's assume that until n, the formula (A) works.
>=20
> Now let's calculate at rank n+1:
>=20
> S(n+1) =3D Sn + a^(n+1) =3D Rn + a^(n+1)=20
> =3D {[1-a^(n+1)] / (1-a)} + a^(n+1)
>=20
> Multiplying a^(n+1) by 1-a in order to get the same denominator:
>=20
> =3D {[1-a^(n+1)] / (1-a)} + [(1-a)*a^(n+1)] / (1-=
a)
>=20
> =3D [1 - a^(n+1) + a^(n+1) - a^(n+2)] / (1-a)
>=20
> The n-1 terms disappear, and we have:
>=20
> S(n+1) =3D [1 - a^(n+2)] / (1-a)
>=20
> What we have shown here is that if it works at rank n, then it works at r=
ank n+1.
> An important point is also to show that it works at rank 1.
> 1 + a =3D (1 - a^2) / (1-a). This is a known result, usually written (1-a=
)(1+a) =3D (1-a^2)
> Consequence of this:
> - It works at rank 1
> - If it works at a given rank n, then it works at n+1
> Therefree this relation works for any (a, n) combination.
>=20
> Now if we assume that the absolute value of a is less than 1, then the nu=
merator
> will go to 1 with high powers, and therefore the polynomial 1 + x + x^2 =
=85 +x^n
> will converge to 1 / (1-x). Let's stress again that while the general for=
mula (A) works
> everywhere, this latter formula works only for small values of x.
>=20
> To summarize this result:
> Around 0:
>=20
> 1 / (1-x) =3D 1 + x + x^2 +x^3 + =85.. (infinite sum) (B)
>=20
> There was a second night of celebration, many beers, naked womans, kilogr=
ams
> of coke, sake, etc...
> There was a morning, that was the 3rd day, and the mathematician was star=
ting
> thinking that nobody would give a rat's ass about what he found the previ=
ous day.
>=20
> So he had a cool idea: integrate (B) at both sides. And he got:
>=20
> -ln(1-x) =3D x + (x^2)/2 +(x^3)/3 + =85.. + (x^n)/n=85.
>=20
> Therefore
>=20
> ln(1-x) =3D - x - (x^2)/2 -(x^3)/3 + =85.. - (x^n)/n
>=20
> Now the problem is that x must be close to 0=85
>=20
> At this point, the mathematician made a mistake (consequence of successiv=
e
> celebrations), and wrote 1+x instead of 1-x.
> The sequence does not change for even powers, but does for odd ones. The
> sign will alternate.
>=20
> ln(1+x) =3D x - (x^2)/2 + (x^3)/3 + =85..
>=20
> And he said, why not subtracting the logs. All the even powers will vanis=
h, which will
> reduce the amount of computation. Here we go:
>=20
> ln(1+x) - ln(1-x) =3D 2x + 2*(x^3)/3 + 2*(x^5)/5 =85.=20
>=20
> And since ln(a) - ln(b) =3D ln(a/b), we obtain:
>=20
> ln[(1+x)/(1-x)] =3D 2 [x + (x^3)/3 +(x^5)/5 =85. ]
>=20
> Now the good thing is that around 0 (in the interval ]-1, +1[, borders ex=
cluded), the
> ratio (1+x)/(1-x) will take any value between 0 and infinity.
>=20
> So if we let a =3D (1-x)/(1+x), we can calculate x backwards like this:
>=20
> a =3D (1+x) / (1-x)
> a - ax =3D 1+x
> a - 1 =3D x + ax
> a-1 =3D x (1+a)
>=20
> then finally: x =3D (a-1) / (a+1)
>=20
> The result of this is that we can calculate ln(a) for any value like this=
:
>=20
> We will use an intermediary variable to help the calculation:
> x =3D (a-1) / (a+1)
>=20
> and then we can calculate ln(a)
>=20
> ln(a) =3D 2[x + (x^3)/3 + (x^5)/5 =85.]
>=20
> Now the inconvenience of this algorithm: for large numbers, you get a x r=
atio
> very close to 1, and the convergence is slow.
> Example: if you want to calculate ln(100), then (100 - 1) / (100 + 1) =3D=
0.98.
> The successive powers of 0.9801 decrease slowly. At the 15th power, you'r=
e still
> at 0.74, so if you leave from rank 15, then you will get an error of abou=
t
> 0.75 / 15 =3D 0.05.
>=20
> So here is a trick.
> You want to calculate ln(100). In this case, x =3D 0.98.
> But you can say that ln(100) =3D 1 + ln(100/e)
> 100/e =3D 36.78, in which case the ratio becomes 0.95.
> Doing the same trick until the remainder is less than e, and we get:
>=20
> ln(100) =3D 4 + ln[100/{e^4)] =3D 4 + ln(1.83)
> in this case, the intermediate variable x becomes 0.29.
> The 15th power of 0.29 is 0.000000002996, so that if you stop at rank 15,
> the error on your result will be in the order of 10^-9. Now the worst cas=
e
> is when the successive divisions by e come close to e itself. In this
> case, the x ratio will be 0.462, and at the 15th power, you will get
> 0.000004, therefore the error when leaving at the 15 th power is less
> than 0.000001, which might be acceptable in most of the cases.
>=20
> As a conclusion: don't do this in an embedded environment.
> If you need logs, then use a table. If a table is not accurate enough,
> you may also interpolate the table. If you _really_ cannot avoid having a
> great precision (I would be curious about the application), then use
> a library.
>=20
> Pascal
>=20
> --- In m...@yahoogroups.com, Michael Malone wrote:
> >
> > Thank you, Jon.
> >=20
> > As one of our species is reputed to have said 'A journey of a thousand =
miles begins with a single step'.
> > And another 'The purpose of education is not to fill minds but to open =
them' or variants of the same '... to take an empty mind and open it', etc.
> >=20
> > There is great beauty in mathematics. But I have had little opportunity=
to pursue such esoteric and often elusive pleasures so far. And although I=
must exercise my mind to try to regain some lost functionaltity I also am =
starting (again) from a low base and must not overreach.
> >=20
> > I apologise for my use of 'unnatural' in describing logs that would not=
have the adjective 'natural' attached - this is just an example of my weir=
d sense of humour.
> >=20
> > Many thanks for the link.=20
> >=20
> > 'A good start is half the work'.
> >=20
> > Take care.
> >=20
> > Mike
> >=20
> >=20
> >=20
> >=20
> > ________________________________
> > From: Jon Kirwan
> > To: MSP430 list
> > Sent: Tuesday, September 8, 2009 3:17:58 PM
> > Subject: Re: [msp430] OT: Binary Mathematics
> >=20
> >=20=20=20
> > On Sun, 06 Sep 2009 16:28:35 -0000, you wrote:
> >=20
> > >Does anyone know of an easy to understand document that would explain
> > >binary matematics to an idiot like me?
> >=20
> > Start here:
> >=20
> > http://webster. cs.ucr.edu/ AoA/Windows/ HTML/DataReprese ntation.html#=
998834
> >=20
> > Work forward through that chapter (3.)
> >=20
> > That's a start, anyway.
> >=20
> > >I would really like something that would not only explain
> > >multiplication and division but also how to achieve calculations using
> > >logs (natural and unnatural) and any other mathematical functions
> > >that would prove useful.
> >=20
> > Most programmers don't worry too much about representation and just
> > use the tools they are given, instead. (Yes, I think that's a sad
> > loss; but there it is.) But if you read the above and can follow that
> > well enough and you sit down and use the techniques you've been taught
> > as a child for doing things like multiplication and division, long
> > hand for decimal, you will find that the same ideas work with binary.
> > It will take a moment to exercise those mental muscles and get
> > going... but it is a tiny bridge to cross, really. And you will get
> > to the other side just fine.
> >=20
> > ....
> >=20
> > Now I'm going to switch gears for a moment and be a little
> > discouraging. I think you need to embrace the idea that a fuller
> > understanding isn't easy and just take one step at a time. Even the
> > above document on the web will only get you so far and no further.
> > It's not designed to give you the kind of knowledge you may need for
> > logarithms, for example -- though if you are a sharp one, you may see
> > it all the same quite easily.
> >=20
> > Generally, there is no "easy to understand" path. There is a price to
> > pay in life for everything. The price for learning how to properly
> > and professionally write your own functions to calculuate things such
> > as log() or tan() is a personal education matched by personal hard
> > work. Just like learning how to properly build a home takes education
> > and hard work before you are truly competent at it. Anyone can learn
> > to pound a nail in short order. But there is so much more to properly
> > designing and preparing foundations, etc., and while pounding a nail
> > is important it is by no means all there is to learn.
> >=20
> > There is no escaping the pragmatic reality that ignorance isn't swept
> > away by taking a pill or stuffing your head with sleep tapes or
> > finding some web site. If you imagine otherwise, even for a second,
> > you need to have your face slapped to bring you out of that dream.
> >=20
> > The way out of ignorance is hard work. Period.
> >=20
> > You show some lack of training in describing logs as natural and
> > _unnatural_. Mathematicians will use the term 'natural' to mean
> > something specific (base e) but otherwise specify the base with a
> > number or else are talking _without_ a need to specify a base (which
> > often doesn't matter to the point being made.) The term 'unnatural'
> > feels very stilted to me and I can't recall any mathematician ever
> > using it except maybe to make a joke.
> >=20
> > That segues into another point. Setting aside the idea of calculating
> > them for a moment and just staying on the idea of using them (the
> > difference between being a gunsmith and a shooter of a gun), if you
> > aren't trained well with the application of mathematical functions,
> > you probably shouldn't be applying them except where others, who are
> > so trained, tell you to use them. So what will "prove useful" to you,
> > on your own, is probably a very limited set until you become better
> > educated in this area.
> >=20
> > But generally speaking, the idea behind the log() of a binary number
> > is the same as the idea behind the log() of a number represented in
> > any other base. So if you know one, you do know the rest. There is
> > nothing new here.
> >=20
> > If by writing "achieve calculations" you are wanting to understand how
> > to compute transcendental function results using code you write
> > yourself (and not the libraries others write for you), then you will
> > need a broad education in various techniques which will clearly
> > require a minimum of two years of college mathematics starting with
> > calculus. Three years would be more likely, but I don't want to speak
> > to what you can handle. Look for infinite and finite calculus,
> > differential equations (usually a 2nd year class), and some exposure
> > to Laplace and Fourier, recurrences, generating functions, and
> > Chebyshev (spelled a half a dozen different ways) polynomials and
> > economization all help. If after some education, you still imagine
> > using Taylor's to approximate a sine() function, you are not educated
> > enough. (Minimax techniques and a dose of numerical methods would
> > help, too.)
> >=20
> > You can even use continued fractions for calculations, if you want,
> > and then handle irrationals with infinite precision on finite memory
> > computers. But that's yet another subject.
> >=20
> > The point is you need an education in mathematics to reach towards
> > some calculations involving some functions, if you are going to
> > maintain other behaviors of them, such as monotonicity while also
> > keeping precision and speed in mind.
> >=20
> > I haven't brought up different binary representations. You seem to
> > imagine there is one used in computers. Although it is today almost
> > universal that computers use one of two different, quite similar,
> > formats for integers (unsigned and a specific form of signed), there
> > are many others. One's complement and two's complement, to name two.
> > There are reasons why one or another may be preferred for some
> > application. There are an almost infinite variety of Gray codes, as
> > well -- which are essentially mere Hamiltonian walks on hypercubes.
> > Etc.
> >=20
> > And there is group theory (finite and infinite, again), including
> > ideas of rings, fields, and so on. These apply to floating point
> > representations. (Something I haven't yet brought up, yet probably
> > needs to be broached because you brought up log() functions.) There
> > are fixed-field formats, infinite precision formats, variable
> > precision formats, continued fraction formats, and pretty much
> > anything you can come up with. Each is useful for something.
> >=20
> > I bring all this up to illustrate a hint towards a majestic tapestry
> > ahead, which all relates in interesting ways to the question you
> > started with. At this point, you can only see a single thread here or
> > there. But there is much beauty and much work ahead if you are to
> > 'see' all that is there to know and apply well.
> >=20
> > ....
> >=20
> > Getting back to Earth. While addition and subtraction, and to be
> > honest multiplication too, are very basic and you can use your grade
> > school understanding with binary and get good results for many uses
> > from that... it does take a little more to fathom efficient methods
> > for division. Long hand almost gets you there, but you will need to
> > think closely to details to make it efficient. People who write early
> > learning books on VHDL or Verilog, used in programming everything from
> > FPGAs to ASIC chips, will provide some good education on division
> > methods. Best to look there, when you are ready for it.
> >=20
> > .....
> >=20
> > So what exactly did you want to know, again? ;)
> >=20
> > Jon
> >=20
> >=20=20=20=20
> >=20
> >=20
> >=20=20=20=20=20=20=20
> >=20
> > [Non-text portions of this message have been removed]
>

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Re: OT: Binary Mathematics - Jon Kirwan - Oct 20 6:15:18 2009

Odd you should suddenly pop out this post. I was just working on
floating point ln(x) routines for the 8051, as the existing stuff was
WAY TOO SLOW for my needs. I needed over a 1000 per second, yielding
16 bit results feeding into an LSQ fit routine. Anyway... it was
fun. Started about 48 hours ago, just finished up documentation on
the final result.

The stuff talked about by another poster below isn't (and I didn't
even bother reading through it because it was obvious) very helpful.
The implementation I chose was to first normalize the input values
(the polynomial is designed around the range where (1 <=3D x < 2). So
the input must first be normalized. In my case, I'm using 16-bit ADC
values, so they are usually already present with the high bit set. but
there is no necessary requirement, so I used a short rotate and check
for carry kind of loop, counting shifts.

If you assume:

x input value
b multiplier of x, as required such that 1 <=3D b*x < 2
z b*x-1
n power of 2, such that b=3D2^n (b is always a power of 2)

The polynomial I used does NOT operate on x, but only on b*x (or z,
really.) Given the above, these are true:

ln(x) =3D ln(b*x) - ln(b) =3D ln(b*x) - n*ln(2) =3D ln(z+1) - n*ln(2)

Using real numbers, the formula looks like:

ln(z+1) =3D z*(k1+z*(k2+z*(k3+z*(k4+z*k5)))), where,
k1=3D0.9991150
k2=3D-0.4899597
k3=3D0.2856751
k4=3D-0.1330566
k5=3D0.03137207

I didn't like the negative signs (and the fact that they were
generally larger than the inner product, leaving lots of negative
values to cope with -- and with the 8051 multiplication where the
precision of the result exceeds the operands, that's a pain.) So I
flipped them around, yielding:

ln(z+1) =3D z*(k1-z*(k2-z*(k3-z*(k4-z*k5)))), where,
k1=3D0.9991150
k2=3D0.4899597
k3=3D0.2856751
k4=3D0.1330566
k5=3D0.03137207

Much easier to handle with the fact that the MUL instruction is only
unsigned on the 8051.

Those constants are golden. However, none of that is helpful until
they get recast into integers for an 8-bit cpu like the 8051. So I
converted the constants to integers, propagated the divisors out,
converted the multiplications to integer 16x16 ones and used sometimes
24-bit, sometimes 32-bit summations. Reducing down in size as I
propagated across. (k5 was perfect -- I completely avoided the MUL
instruction there. The special constant it works out to is trivial to
apply.)

The ln(2) is just a fixed 16-bit integer constant when I'm done, so
that is easy to multiply by n (single byte value) and adjust the rest.

Handy.

If anyone wants their ln() library function worked on, on some
arbitrarily ornery micro... I may be in the mood.

Jon

On Mon, 19 Oct 2009 23:06:43 -0000, you wrote:

>Hey That was great! I don't think I would ever use it tho... great journey=
none the lesss...=20
>
>--- In m...@yahoogroups.com, "p_murayama" wrote:
>>
>> Hello!
>>=20
>> Now I feel I have to start my journey by hunting the log among
>> other numbers.
>>=20
>> In this delirium, I will use the following conventions:
>> a^b means power. Example 10^2 =3D 100.
>> Since there are sometimes several levels of brackets, then I will use ()
>> for the lowest, then [] and {}.
>>=20
>> Here we go!
>>=20
>> 1 In the beginning, the mathematician said: let there be numbers.
>> 2 And there were numbers, and he saw that this was f**ing good.
>> 3 There was an evening with many beers to celebrate, there was wine,
>> there was sake, a few rails of coke.
>> 4. And there was a morning with incredible headaches. It was the second =
day.
>> 5. And the mathematician took a few painkillers.
>> 6. And he got fuzzy until noon.
>> 7. And he was looking at its creation and got amazed.
>>=20
>> I'll skip a few steps, and report what the mathematician noticed:
>>=20
>> If you make a sum of the n first integer powers of a number a, you get:
>>=20
>> 1 + a^1 + a^2 + a^3 =85. +a^n =3D [1-a^(n+1)] / (1-a) (A)
>> Lets's call Sn =3D 1 + a^1 + a^2 + a^3 =85. +a^n=20
>> and Rn =3D [1-a^(n+1)] / (1-a)
>>=20
>> Let's prove it: let's assume that until n, the formula (A) works.
>>=20
>> Now let's calculate at rank n+1:
>>=20
>> S(n+1) =3D Sn + a^(n+1) =3D Rn + a^(n+1)=20
>> =3D {[1-a^(n+1)] / (1-a)} + a^(n+1)
>>=20
>> Multiplying a^(n+1) by 1-a in order to get the same denominator:
>>=20
>> =3D {[1-a^(n+1)] / (1-a)} + [(1-a)*a^(n+1)] / (1=
-a)
>>=20
>> =3D [1 - a^(n+1) + a^(n+1) - a^(n+2)] / (1-a)
>>=20
>> The n-1 terms disappear, and we have:
>>=20
>> S(n+1) =3D [1 - a^(n+2)] / (1-a)
>>=20
>> What we have shown here is that if it works at rank n, then it works at =
rank n+1.
>> An important point is also to show that it works at rank 1.
>> 1 + a =3D (1 - a^2) / (1-a). This is a known result, usually written (1-=
a)(1+a) =3D (1-a^2)
>> Consequence of this:
>> - It works at rank 1
>> - If it works at a given rank n, then it works at n+1
>> Therefree this relation works for any (a, n) combination.
>>=20
>> Now if we assume that the absolute value of a is less than 1, then the n=
umerator
>> will go to 1 with high powers, and therefore the polynomial 1 + x + x^2 =
=85 +x^n
>> will converge to 1 / (1-x). Let's stress again that while the general fo=
rmula (A) works
>> everywhere, this latter formula works only for small values of x.
>>=20
>> To summarize this result:
>> Around 0:
>>=20
>> 1 / (1-x) =3D 1 + x + x^2 +x^3 + =85.. (infinite sum) (B)
>>=20
>> There was a second night of celebration, many beers, naked womans, kilog=
rams
>> of coke, sake, etc...
>> There was a morning, that was the 3rd day, and the mathematician was sta=
rting
>> thinking that nobody would give a rat's ass about what he found the prev=
ious day.
>>=20
>> So he had a cool idea: integrate (B) at both sides. And he got:
>>=20
>> -ln(1-x) =3D x + (x^2)/2 +(x^3)/3 + =85.. + (x^n)/n=85.
>>=20
>> Therefore
>>=20
>> ln(1-x) =3D - x - (x^2)/2 -(x^3)/3 + =85.. - (x^n)/n
>>=20
>> Now the problem is that x must be close to 0=85
>>=20
>> At this point, the mathematician made a mistake (consequence of successi=
ve
>> celebrations), and wrote 1+x instead of 1-x.
>> The sequence does not change for even powers, but does for odd ones. The
>> sign will alternate.
>>=20
>> ln(1+x) =3D x - (x^2)/2 + (x^3)/3 + =85..
>>=20
>> And he said, why not subtracting the logs. All the even powers will vani=
sh, which will
>> reduce the amount of computation. Here we go:
>>=20
>> ln(1+x) - ln(1-x) =3D 2x + 2*(x^3)/3 + 2*(x^5)/5 =85.=20
>>=20
>> And since ln(a) - ln(b) =3D ln(a/b), we obtain:
>>=20
>> ln[(1+x)/(1-x)] =3D 2 [x + (x^3)/3 +(x^5)/5 =85. ]
>>=20
>> Now the good thing is that around 0 (in the interval ]-1, +1[, borders e=
xcluded), the
>> ratio (1+x)/(1-x) will take any value between 0 and infinity.
>>=20
>> So if we let a =3D (1-x)/(1+x), we can calculate x backwards like this:
>>=20
>> a =3D (1+x) / (1-x)
>> a - ax =3D 1+x
>> a - 1 =3D x + ax
>> a-1 =3D x (1+a)
>>=20
>> then finally: x =3D (a-1) / (a+1)
>>=20
>> The result of this is that we can calculate ln(a) for any value like thi=
s:
>>=20
>> We will use an intermediary variable to help the calculation:
>> x =3D (a-1) / (a+1)
>>=20
>> and then we can calculate ln(a)
>>=20
>> ln(a) =3D 2[x + (x^3)/3 + (x^5)/5 =85.]
>>=20
>> Now the inconvenience of this algorithm: for large numbers, you get a x =
ratio
>> very close to 1, and the convergence is slow.
>> Example: if you want to calculate ln(100), then (100 - 1) / (100 + 1) =
=3D 0.98.
>> The successive powers of 0.9801 decrease slowly. At the 15th power, you'=
re still
>> at 0.74, so if you leave from rank 15, then you will get an error of abo=
ut
>> 0.75 / 15 =3D 0.05.
>>=20
>> So here is a trick.
>> You want to calculate ln(100). In this case, x =3D 0.98.
>> But you can say that ln(100) =3D 1 + ln(100/e)
>> 100/e =3D 36.78, in which case the ratio becomes 0.95.
>> Doing the same trick until the remainder is less than e, and we get:
>>=20
>> ln(100) =3D 4 + ln[100/{e^4)] =3D 4 + ln(1.83)
>> in this case, the intermediate variable x becomes 0.29.
>> The 15th power of 0.29 is 0.000000002996, so that if you stop at rank 15=
,
>> the error on your result will be in the order of 10^-9. Now the worst ca=
se
>> is when the successive divisions by e come close to e itself. In this
>> case, the x ratio will be 0.462, and at the 15th power, you will get
>> 0.000004, therefore the error when leaving at the 15 th power is less
>> than 0.000001, which might be acceptable in most of the cases.
>>=20
>> As a conclusion: don't do this in an embedded environment.
>> If you need logs, then use a table. If a table is not accurate enough,
>> you may also interpolate the table. If you _really_ cannot avoid having =
a
>> great precision (I would be curious about the application), then use
>> a library.
>>=20
>> Pascal
>>=20
>> --- In m...@yahoogroups.com, Michael Malone wrote:
>> >
>> > Thank you, Jon.
>> >=20
>> > As one of our species is reputed to have said 'A journey of a thousand=
miles begins with a single step'.
>> > And another 'The purpose of education is not to fill minds but to open=
them' or variants of the same '... to take an empty mind and open it', etc=
.
>> >=20
>> > There is great beauty in mathematics. But I have had little opportunit=
y to pursue such esoteric and often elusive pleasures so far. And although =
I must exercise my mind to try to regain some lost functionaltity I also am=
starting (again) from a low base and must not overreach.
>> >=20
>> > I apologise for my use of 'unnatural' in describing logs that would no=
t have the adjective 'natural' attached - this is just an example of my wei=
rd sense of humour.
>> >=20
>> > Many thanks for the link.=20
>> >=20
>> > 'A good start is half the work'.
>> >=20
>> > Take care.
>> >=20
>> > Mike
>> >=20
>> >=20
>> >=20
>> >=20
>> > ________________________________
>> > From: Jon Kirwan
>> > To: MSP430 list
>> > Sent: Tuesday, September 8, 2009 3:17:58 PM
>> > Subject: Re: [msp430] OT: Binary Mathematics
>> >=20
>> >=20=20=20
>> > On Sun, 06 Sep 2009 16:28:35 -0000, you wrote:
>> >=20
>> > >Does anyone know of an easy to understand document that would explain
>> > >binary matematics to an idiot like me?
>> >=20
>> > Start here:
>> >=20
>> > http://webster. cs.ucr.edu/ AoA/Windows/ HTML/DataReprese ntation.html=
# 998834
>> >=20
>> > Work forward through that chapter (3.)
>> >=20
>> > That's a start, anyway.
>> >=20
>> > >I would really like something that would not only explain
>> > >multiplication and division but also how to achieve calculations usin=
g
>> > >logs (natural and unnatural) and any other mathematical functions
>> > >that would prove useful.
>> >=20
>> > Most programmers don't worry too much about representation and just
>> > use the tools they are given, instead. (Yes, I think that's a sad
>> > loss; but there it is.) But if you read the above and can follow that
>> > well enough and you sit down and use the techniques you've been taught
>> > as a child for doing things like multiplication and division, long
>> > hand for decimal, you will find that the same ideas work with binary.
>> > It will take a moment to exercise those mental muscles and get
>> > going... but it is a tiny bridge to cross, really. And you will get
>> > to the other side just fine.
>> >=20
>> > ....
>> >=20
>> > Now I'm going to switch gears for a moment and be a little
>> > discouraging. I think you need to embrace the idea that a fuller
>> > understanding isn't easy and just take one step at a time. Even the
>> > above document on the web will only get you so far and no further.
>> > It's not designed to give you the kind of knowledge you may need for
>> > logarithms, for example -- though if you are a sharp one, you may see
>> > it all the same quite easily.
>> >=20
>> > Generally, there is no "easy to understand" path. There is a price to
>> > pay in life for everything. The price for learning how to properly
>> > and professionally write your own functions to calculuate things such
>> > as log() or tan() is a personal education matched by personal hard
>> > work. Just like learning how to properly build a home takes education
>> > and hard work before you are truly competent at it. Anyone can learn
>> > to pound a nail in short order. But there is so much more to properly
>> > designing and preparing foundations, etc., and while pounding a nail
>> > is important it is by no means all there is to learn.
>> >=20
>> > There is no escaping the pragmatic reality that ignorance isn't swept
>> > away by taking a pill or stuffing your head with sleep tapes or
>> > finding some web site. If you imagine otherwise, even for a second,
>> > you need to have your face slapped to bring you out of that dream.
>> >=20
>> > The way out of ignorance is hard work. Period.
>> >=20
>> > You show some lack of training in describing logs as natural and
>> > _unnatural_. Mathematicians will use the term 'natural' to mean
>> > something specific (base e) but otherwise specify the base with a
>> > number or else are talking _without_ a need to specify a base (which
>> > often doesn't matter to the point being made.) The term 'unnatural'
>> > feels very stilted to me and I can't recall any mathematician ever
>> > using it except maybe to make a joke.
>> >=20
>> > That segues into another point. Setting aside the idea of calculating
>> > them for a moment and just staying on the idea of using them (the
>> > difference between being a gunsmith and a shooter of a gun), if you
>> > aren't trained well with the application of mathematical functions,
>> > you probably shouldn't be applying them except where others, who are
>> > so trained, tell you to use them. So what will "prove useful" to you,
>> > on your own, is probably a very limited set until you become better
>> > educated in this area.
>> >=20
>> > But generally speaking, the idea behind the log() of a binary number
>> > is the same as the idea behind the log() of a number represented in
>> > any other base. So if you know one, you do know the rest. There is
>> > nothing new here.
>> >=20
>> > If by writing "achieve calculations" you are wanting to understand how
>> > to compute transcendental function results using code you write
>> > yourself (and not the libraries others write for you), then you will
>> > need a broad education in various techniques which will clearly
>> > require a minimum of two years of college mathematics starting with
>> > calculus. Three years would be more likely, but I don't want to speak
>> > to what you can handle. Look for infinite and finite calculus,
>> > differential equations (usually a 2nd year class), and some exposure
>> > to Laplace and Fourier, recurrences, generating functions, and
>> > Chebyshev (spelled a half a dozen different ways) polynomials and
>> > economization all help. If after some education, you still imagine
>> > using Taylor's to approximate a sine() function, you are not educated
>> > enough. (Minimax techniques and a dose of numerical methods would
>> > help, too.)
>> >=20
>> > You can even use continued fractions for calculations, if you want,
>> > and then handle irrationals with infinite precision on finite memory
>> > computers. But that's yet another subject.
>> >=20
>> > The point is you need an education in mathematics to reach towards
>> > some calculations involving some functions, if you are going to
>> > maintain other behaviors of them, such as monotonicity while also
>> > keeping precision and speed in mind.
>> >=20
>> > I haven't brought up different binary representations. You seem to
>> > imagine there is one used in computers. Although it is today almost
>> > universal that computers use one of two different, quite similar,
>> > formats for integers (unsigned and a specific form of signed), there
>> > are many others. One's complement and two's complement, to name two.
>> > There are reasons why one or another may be preferred for some
>> > application. There are an almost infinite variety of Gray codes, as
>> > well -- which are essentially mere Hamiltonian walks on hypercubes.
>> > Etc.
>> >=20
>> > And there is group theory (finite and infinite, again), including
>> > ideas of rings, fields, and so on. These apply to floating point
>> > representations. (Something I haven't yet brought up, yet probably
>> > needs to be broached because you brought up log() functions.) There
>> > are fixed-field formats, infinite precision formats, variable
>> > precision formats, continued fraction formats, and pretty much
>> > anything you can come up with. Each is useful for something.
>> >=20
>> > I bring all this up to illustrate a hint towards a majestic tapestry
>> > ahead, which all relates in interesting ways to the question you
>> > started with. At this point, you can only see a single thread here or
>> > there. But there is much beauty and much work ahead if you are to
>> > 'see' all that is there to know and apply well.
>> >=20
>> > ....
>> >=20
>> > Getting back to Earth. While addition and subtraction, and to be
>> > honest multiplication too, are very basic and you can use your grade
>> > school understanding with binary and get good results for many uses
>> > from that... it does take a little more to fathom efficient methods
>> > for division. Long hand almost gets you there, but you will need to
>> > think closely to details to make it efficient. People who write early
>> > learning books on VHDL or Verilog, used in programming everything from
>> > FPGAs to ASIC chips, will provide some good education on division
>> > methods. Best to look there, when you are ready for it.
>> >=20
>> > .....
>> >=20
>> > So what exactly did you want to know, again? ;)
>> >=20
>> > Jon
>> >=20
>> >=20=20=20=20
>> >=20
>> >=20
>> >=20=20=20=20=20=20=20
>> >=20
>> > [Non-text portions of this message have been removed]
>> >
>

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Re: OT: Binary Mathematics - Jon Kirwan - Oct 20 18:33:42 2009

On Tue, 20 Oct 2009 03:14:55 -0700, I wrote:

>Odd you should suddenly pop out this post. I was just working on
>floating point ln(x) routines for the 8051, as the existing stuff was
>WAY TOO SLOW for my needs. I needed over a 1000 per second, yielding
>16 bit results feeding into an LSQ fit routine. Anyway... it was
>fun. Started about 48 hours ago, just finished up documentation on
>the final result.

I just finished timing these 32-bit calculations on a SiLabs x061. A
mean of 18.35 microseconds for ln(x). Fast enough to meet needs.

Jon
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )