We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

The Ada Numerics Model

00:00

Formal Metadata

Title
The Ada Numerics Model
Title of Series
Number of Parts
287
Author
Contributors
License
CC Attribution 2.0 Belgium:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
The requirements for Ada numerics were to provide portable arithmetics without unacceptable performance cost. This talk shows how this was achieved by interval arithmetics without requiring a particular implementation model, like IEEE arithmetics.
Mathematical analysisRational numberInfinitySubsetComputer hardwareFile formatBinary fileDecimalStandard deviationExtension (kinesiology)Real numberPortable communications deviceArchitectureData modelApproximationLogical constantType theoryNumerical digitAbsolute valueVoltmeterMaxima and minimaCompilerMeasurementReal numberPhysicistCircleEndliche ModelltheorieDecimalPoint (geometry)VoltmeterRange (statistics)Covering spaceFormal languageType theoryNeuroinformatikPrice indexMultiplication signPortable communications deviceNumerical analysisStandard deviationSet (mathematics)Programming languageFile formatJava appletRational numberResultantApproximationPhysicalismLine (geometry)InfinityLink (knot theory)AreaNumeral (linguistics)CASE <Informatik>DigitizingVirtual machineBitSubsetNumberRepresentation (politics)Goodness of fitCompilerComputer hardwareSurfaceLengthComputerMetreExponentiationPlastikkartePresentation of a groupResolvent formalismOvalPrisoner's dilemmaGame theoryNatural numberComputer architectureCodeSemiconductor memoryProcedural programmingCAN busWeb pageRevision controlDifferent (Kate Ryan album)Product (business)Logic gateExtension (kinesiology)Compilation albumCone penetration testNoise (electronics)MedianBeat (acoustics)BuildingPrincipal idealDataflowVotingHand fanDiagramComputer animation
Performance appraisalFluid staticsRegulärer Ausdruck <Textverarbeitung>Extension (kinesiology)CompilerRational numberData modelCompilerAsynchronous Transfer ModeOperations researchAdditionLibrary (computing)Linear mapElectric generatorAlgebraImplementationReal numberProduct (business)CompilerEndliche ModelltheorieResultantNeuroinformatikProcess (computing)Virtual machineOperator (mathematics)Logical constantMaxima and minimaDivisorRun time (program lifecycle phase)CASE <Informatik>ExpressionComputer architectureApproximationNumberRange (statistics)Different (Kate Ryan album)AdditionError messageNumeral (linguistics)Scaling (geometry)Elementare FunktionImplementationAsynchronous Transfer ModeComputer configurationTheory of relativitySound effectReal numberRule of inferenceGoodness of fitLibrary (computing)Formal languageSign (mathematics)WavePoint (geometry)TunisExtension (kinesiology)Bounded variationUsabilityLattice (order)Roundness (object)Network topologyOvalMultiplication signComputerPhysicalismBuffer overflowCovering spaceMathematicsResolvent formalismFunctional (mathematics)MultiplicationAreaComputer animation
ImplementationIndependence (probability theory)Real numberComputer hardwarePoint (geometry)Floating pointScale (map)Coefficient of determinationAttribute grammarNumerical digitCurvatureType theoryPower (physics)Point (geometry)Endliche ModelltheorieSystem callWater vaporOptical disc driveNeuroinformatikMultiplication signResultantPrisoner's dilemmaCASE <Informatik>Maxima and minimaTwitterComputer hardwareMeasurementNumberMachine visionMessage passingGoodness of fitMetreHome pageDifferent (Kate Ryan album)DataflowProtein foldingPeripheralCompilerApproximationScaling (geometry)Metropolitan area networkWeb pageStress (mechanics)InformationAdditionRow (database)Virtual machineProcess (computing)Portable communications deviceComputer programmingType theoryDampingClosed setPhysicalismExploratory data analysisPhysical lawAngleNumerical analysisDigitizingLevel (video gaming)Axiom of choiceBound stateBitImplementationRepresentation (politics)Computer animation
CASE <Informatik>NumberComputer animationMeeting/Interview
NumberReal numberMereologyLibrary (computing)Formal languageIntegerMeeting/InterviewComputer animation
ResultantMeeting/InterviewComputer animation
Graphical user interfaceBitFormal languageReal numberInternet service providerMultiplication signIntegerLibrary (computing)Type theoryWindowMeeting/InterviewComputer animation
Power (physics)CalculationData conversionPoint (geometry)Different (Kate Ryan album)Domain nameMessage passingOntologyData miningBoss CorporationNeuroinformatikPiDimensional analysisTerm (mathematics)OvalNumerical analysisType theoryPosition operatorPhysicalismMathematicsMeeting/InterviewComputer animation
Position operatorImplementationEndliche ModelltheorieIntervallalgebraNeuroinformatikVirtual machineType theoryShift operatorPoint (geometry)Computer hardwareComputer animation
Type theoryPoint (geometry)CASE <Informatik>Mathematical analysisWordLatent heatNP-hardDifferent (Kate Ryan album)Formal languageRange (statistics)Computer hardwareAxiom of choiceDampingMultiplicationGame controllerMultiplication signPhysical lawResultantForcing (mathematics)Network topologyMeeting/InterviewComputer animation
Mathematical analysisLatent heatSet (mathematics)Numeral (linguistics)Vector potentialBuffer overflowCAN busNumberNeuroinformatikDisk read-and-write headMeeting/InterviewComputer animation
VotingDataflowResultantStudent's t-testEndliche ModelltheorieArithmetic meanPhysical systemMeeting/InterviewComputer animation
Meeting/InterviewComputer animation
Transcript: English(auto-generated)
Good morning, I'm Jean-Pierre Rosin from AdaLog and I'm going to present how Ada deals with the issues of numerics.
First of all, what is numerical analysis? The problem is that the mathematical set that we call real numbers cannot be represented on a computer because it has an infinite number of values, even if you consider only a bounded segment of the reals, and a computer can in any case represent exactly only rational values.
But pi is irrational, if you want to compute the area of a circle, then you need absolutely irrational values, but you cannot have them. So, numerical analysis is about making not-too-wrong computations in the real world, with pun
intended, using only an infinite subset of rational numbers that can be represented on a computer. There are various ways to represent those numbers. Actually, computers have very different formats for representing real.
For example, that link leads you to a paper that describes 76 different floating point forms. Even the famous IEEE 754 defines fine standard formats for the real numbers, with some extensions.
Another interesting case is the VAX computer, the regretted VAX computer, where you had four floating point formats, but two of them were on 64 bits.
One with more mantissa, providing more accuracy, and the other one with a bigger exponent, therefore providing more range. So you see that saying long float, for example, could not describe this case
where on the same number of bits you had different representation of floating point numbers. How did programming languages address this issue? Well, for a long time they followed the legacy of Fortran.
Fortran had only two definitions, real and double precision, because that was what was available on the computer where Fortran was designed. Then some programming languages added some more formats, but it's basically saying I want a
big or a small real number without any indication about the kind of accuracy you needed. And, of course, real didn't mean the same thing from a computer to another one. There was no portability.
So, Ada was built with requirements, and one of the requirements was to have portable results for real computation, even on various architectures, without imposing a particular architecture.
Because this would have led to an efficiency penalty for the computers that did not have that architecture. That was a big mistake of Java to impose the IEEE format, because it's not usable with any other kind of computer.
The solution found by Ada was to follow the model of approximate values in physics. You know, when a physicist does an experiment, he doesn't consider just the measured point, the small circles here.
Each measure has a certain uncertainty, and therefore the measurement is represented as a little segment. And if the physicist is lucky, he will find a straight line that goes through all segments, and then we can say that the phenomenon is linear.
You will never find a straight line that goes exactly through all the measured points, of course. So we have that idea that the point of measure does not represent on itself, but a small segment of the real axis.
There are two ways of defining those segments. What is called a relative approximation, where delta x over x is constant. It translates like something saying, okay, my voltage is five volts plus or minus five percent.
So as the value grows, you have more uncertainty, or you have absolute approximation, where delta x is constant. And something like five volts plus or minus 0.1 volts on the whole range. The uncertainty is the same over the whole range.
Therefore, in Ada, we have two kinds of real types. What we call real covers both the usual floating point type, the one that you know in most of the languages.
So this is a syntax and you see that you give a type with the number of significant digits in decimal representation that you want. So, for example, here, if I want to present a length on the Earth, on the surface of the Earth, I need five significant digits.
So it's an approximation of 10 to the minus five over the range from zero to 40 exponent six meters. And you have fixed point type, they come into flavor, binary and decimal, but the principle is
the same, where you specify the absolute step that you want, the delta and the range of value. So a typical example, my volts here, if I want one hundredth of a volt over the range of zero to
100, or typically for decimal numbers, euros, as with a step, if you want, of 0.01 cent over 11 digits.
The decimal numbers correspond on machines that have them to binary coded decimals. And so the principle is that you specify the minimal accuracy that comes from your requirements, and
then the compiler will choose among all available hardware types the one that fits best your requirements. So all available hardware types can be used, and if the compiler does not find an appropriate type, then it will be rejected at compile time.
If you need, say, 20 digits of accuracy, and your computer doesn't have 20 digits, then you'd better know that as soon as possible, because either you change your requirements or you have to change your computer.
When you have a computation, you have several cases. First is arithmetic that can be done at compile time. Sometimes you have various constants that you multiply by other constants to give you a factor of scaling and various things like that.
If an expression can be evaluated at compile time, then the standard guarantees that it will be exact. It means that one divided by three multiplied by three will give you one exactly, and not 0.999999 or 1.00001.
That's not easy. It means that the compiler must implement a multi-precision rational arithmetic,
but the compiler did that, and so everything that you can write will be evaluated exactly. Then you have dynamic evaluation, expressions that are evaluated at run time. So here we are blocked, of course, by the accuracy of the computer.
You have two modes. In the so-called relaxed mode, you have a guarantee that the data will be represented with the required accuracy, but you have no guarantee about the way a arithmetic operation performs.
For a compiler that conforms to the optional annex G, the numerics annex, then in addition you have a strict mode that will put requirements on the accuracy of all operations, including the operation from the standard mathematical library.
And that's important, because in other languages you try to have a good sign function, but nobody knows what is the accuracy of the sign function. Here you have guaranteed accuracy for all elementary functions.
So, how does it work for usual operations? The model, it uses a model called the Brown's model, which dates back to the 80s by Mr. Brown, who invented that.
The principle is that when you define a type, you have a certain number that are represented exactly on the machine according to the definition of your type. These are called model numbers.
When you do an operation between two model numbers, and the mathematical result holds exactly on a model number, then the computation must provide you with exactly that model number.
That means that 1.0 plus 1.0 is exactly 2.0. It's important, because people often see real numbers with a kind of fuzz, something that's of unknown accuracy.
If you know what you are doing and process correctly model numbers, then you can predict the exact outcome of a mathematical operation.
Now, if you have two model numbers and an operation whose mathematical result holds between two model numbers, then the computer can provide any value in what is called a model interval. That's the interval that is limited by the
two adjacent model numbers. So, you are not required to round up or to round down. You can even keep a more accurate value if you have extra values that can be represented in the computer. So,
you can keep a more accurate result, but at most, the result is rounded up or down to the next model number.
Now, if you have several computations, you may have two operands where the inaccuracy accumulates. So, if you have two numbers that belong to some model interval, you consider all the possible values of each of the operands,
and you perform the operation on all the possible values. That gives you a range which is not necessarily bounded by model numbers. And then, that range is extended to the two adjacent model numbers that surround it.
So, this, in practice, applies the usual rules of approximation that we know in physics, like for relative approximations,
uncertainty adds up when you do a multiplication, and they add up for fixed uncertainty when you do an addition. That's almost the same rule, plus that little digitalizing effect that you always extend the result to the adjacent model numbers.
A consequence of that model is that you have no notion of underflow, because it may happen that the model interval of the result covers zero. In
that case, well, zero is an acceptable value for the result, but there is no special case where the result of an operation gives you a plain zero.
It's just accepted by the model. So, when you are doing real computation, what will happen if you are doing the same computation on two different computers?
Nothing forces the two computers to give you exactly the same result. It is likely that on two different computers, implementation A will find a result and implementation B a different result. But what you know is that those two different results will belong to a result interval
that is guaranteed by the language and that can be computed independently of any machine architecture. So, you are not granted a value, you are granted a maximum error value, and all implementation will guarantee that maximum inaccuracy.
So, that's a model that has the benefit to be compatible with
any hardware while still putting reasonable bounds on the difference between two implementations. I stress a little bit those fixed points, because that's something that most of you presumably have not encountered in other languages.
A floating point has that kind of representation where numbers are very close to each other when you are
close to zero, and as you go farther from zero, the gap between two numbers gets wider and wider. For a fixed point, you have the same gap between numbers over the whole
range, so depending on what you need, one or the other might be more appropriate. Typically, fixed points are used to represent time. In general, in computers, you have a time zero, but it's arbitrary.
Unless you are modeling the Big Bang, you don't need more accuracy close to zero than away from zero. And if you use a floating point type to represent time, then as time passes, your uncertainty increases, and that can be very annoying.
Also, for physical measures, that can be quite useful, because most of physical devices have a linear scale. I've never seen a logarithmic voltmeter, for example.
They are all linear, so a linear scale is a better representation, a better modeling of a voltmeter. And, of course, money must be represented by floating points. By the way, it is forbidden by law to represent money with floating points, because you cannot have approximations the way it works with floating points.
So, when you are doing computation in floats, with this model you have two possibilities.
First, what I call a posteriori accuracy. It means you want to use just the regular floating points of your computer, so you can use types like float and long float. The floating point types that are natural to the hardware are predefined like in any language, with names like float and long float.
Of course, you will use derived types, so you can still have strong typing of the values, but you derive them from the hardware types.
With those kinds of types, a good analyst can compute the maximum uncertainty, thanks to the model that we have seen. It's a kind of portability, if you want, where you run the same program on two machines,
and machine A tells you pi equals 3.14 plus or minus 10 to the minus 3. And on another machine it will tell you pi equals 3.14 plus or minus 10 to the minus 5.
These are different results, but both results are correct. So you do your computation, and after the fact you are able to compute what is the maximum uncertainty of your computation.
Another case is what I call a priori accuracy. You absolutely need some accuracy. For example, you are computing the angle of entrance of a shuttle in the atmosphere, and if you are too steep the shuttle will burn.
If you are too flat, then the shuttle will not be able to enter the higher level of the atmosphere. So you took a numeric analysis to analyze your computation, and he determined, for example, that to
get enough accuracy for the angle of entrance, you need to have your values with 7 digits. You may have more accuracy than that with your floating point type, but that's not useful
because in any case your physical devices won't give you enough precision to make use of that. However, if you have less than that, then you take a risk of burning the astronauts.
So you require digit 7, and in any case the compiler will provide you what you asked for. And of course you have the ability to have fixed point number with fixed scales also, where you tell the accuracy you need and the compiler will provide it.
So this, in that case, the accuracy is guaranteed independently of the implementation. So in conclusion, first of all, don't think a number with a decimal point is always a float.
As soon as it's not an integer, people think it's a float. In EDA we have a much richer set of numbers, and we have various ways of defining our non-integer numbers.
The EDA model offers the ability to use all the various facilities provided by the hardware, not just one or two or three predefined floating point types.
Everything that's available on the computer can be used by the compiler. And of course, depending on what you want to model, it might be more appropriate to use floating point types or fixed point types.
So the choice is yours. We have a very rich modeling of real value. That's something that should be of interest to your numerical friends. Thank you for your attention and we'll move to questions.
What about big numbers? Is it accepted in 2020x, which I believe it's going to become 2022? Yes, there are big numbers in 2022. We hear you a little bit, but I don't know, maybe it's that you're far from the microphone or...
Not further. Do you hear me now? Not great, but we can understand you.
I'm saying that there are big number packages, both big integers and big reals. These are just packages, so it's not part of the definition of the language itself. I don't know if it's just libraries like foreign language, but they are provided with a way that is difficult to do.
Okay, if you can speak louder, maybe the sound quality will be better, but I think we more or less understood what you just said. Don't worry. Let's just say, sorry, the microphone is in the room.
Yeah, I'm trying. Do you hear me now? We hear you more or less the same, but if you speak louder, I think maybe that solves the problem. And yes, there is a bit of echo.
This one, do you hear me? Oh, perfect. Much better. Luckily, we have a bit of time for questions and answers. If you would like maybe to repeat the answer to the first question to the big number. So, Ada 2022 will provide big integers and big reals with two different packages.
These are just packages. You don't need anything special in the language itself. It's just libraries like in any other language. Okay, thank you. Another question from Stefan. This one is a bit longer, so I think you should look at it.
But basically, he asks, what is the recommended way to make fixed point calculation when you have to convert domain types? Example, and he gives an example of different definitions for volts, amperes, ohms and power.
What would you recommend? I've seen the message. Now I can see it. Well, in general, this is heterogeneous computation. So you have to return first the type to some common type that you
compute beforehand to be wide enough with enough accuracy or whatever for your computation. So you convert to that intermediate type, which is somehow the mathematical type without physical dimension. And then you return, you do your intermediate computation with that type.
And then you return to the physical type, if I can say so, type in the end. But you certainly need, you need some numerical analysis to determine exactly what that intermediate type of computations should be.
Okay, then Derek asks a question of any experience with Ada and POSIT format. So POSIT is another item, like I tried probably, it's certainly compatible.
I mean, POSIT has fixed values and also interval values. So it should be compatible. I don't know if there is concrete experience or I don't know what computers use POSIT actually. But the idea is that the Ada model has been made to be implemented independent of any hardware model.
So there is no reason that it shouldn't be compatible. Actually, looking at it, POSIT is based on interval arithmetic. So it should be quite easy to map Ada to POSIT.
But that's a matter of implementation. I don't know if there are currently implementations of Ada or other POSIT machines. Okay, thank you. And one question from me. In the case where you're using floats, normal floating point types and fixed point
types, what would you recommend when an analysis of precision has to be done? If you mix them, that's what you are saying? Well, if you mix them or more specifically, if I can choose any of them, if the hardware doesn't have any restriction,
if my requirements don't have any specific clause regarding the types that have to be used, if I could choose between fixed point or floating point, what would you recommend if I need to control the uncertainty and the result?
Well, if you need to control the uncertainty and the result, then you have requirements somewhere. So I would say look at your requirements and see what's available. The main difference between Ada and other languages, in other languages you more or less have a choice between short and long floats.
Here you have a whole range of possibilities and it's certain that having a choice is more difficult than having no choice at all. But in general, fixed point types have a more tricky arithmetic, especially
with multiplication of fixed point types where there are issues regarding accuracy. People are generally more used to using floating point types. So if you have no special requirements, you may use the provided floating point types like in other languages.
If you have some more requirements, then it will depend on your requirements, of course. Ok, thank you.
You're welcome. Regarding the accuracy analysis in Ada especially, what approach would you recommend people take? I suppose starting from a set of specifications or requirements, how would you recommend that people do a precision analysis?
Ok, refer to a numerical analyst. I mean, numerics are very tricky, you know. I don't consider myself as a numeric expert, but I know just enough to tell
you that if you don't know the numerics, you are likely to make big mistakes. So if you have needs with accuracy, with your computations, and you're not familiar with that, refer to someone who knows.
That's the best advice I can give because it's really tricky what can happen. Ok, and if you can answer this shortly, what is the best way to handle potential overflows and underflows to find them in Ada?
Ok, first in Ada, there is no underflow. As I mentioned in my talk, it may happen that the model interval of the results covers the value zero. But the value zero has no special meaning. It's just one possible real value like any other one.
If the model interval of the results covers zero, then the system is going to close. So if you have more questions, please join this room.