In this lecture we will learn the following things. We will learn how to define kinetic energy and momentum while incorporating special relativity. We will learn about the nature of mass and the concept of intrinsic mass. And we will learn about the relationship between energy, momentum and mass. Now let's take a look back at Newton's second law from the perspective of classical physics and in particular have a look at momentum or classical momentum in the context of this discussion. So in introductory physics you are introduced to the concept of momentum roughly as follows. Historically it was observed that there appeared to be a conserved directional quantity associated with motion. This quantity which we call momentum is well defined in the classical domain of physics that is low velocities and large scales by the product of the mass of an object m and the velocity of the object u vector. So we arrive at the definition, the so-called classical definition of momentum, by taking the product of these two things m times u and that gives us p, the momentum or linear momentum of that object. Now in a closed and isolated system perhaps with a whole bunch of different objects i equals 1 to n, it is observed that this quantity overall is conserved, that is the sum of all momenta of all objects in a closed and isolated system can be written as a singular number, the total momentum and that total momentum remains constant no matter what happens inside that closed and isolated system. Now when a system is not closed and isolated for instance subject to some net external force f, then the full beauty of Newton's second law is observed to be obeyed by the system. That is that the net force acting on the constituents of the system is just given by the change in momentum of that system divided by the change in time or dp dt. So Newton's second law f equals ma can actually be rewritten in terms of momentum concepts as just f equals dp dt. Now of course we need to bridge from classical physics to modern physics and to do that I want you to start thinking a little bit about the laws of physics and their invariance under transformations from one inertial frame of reference to another. Recall that one of the postulates of special relativity is that the laws of physics should not depend on what frame of reference you are measuring them in. They should be the same for all frames of reference and the consequence of that of course is that you can't tell if you're in an absolute state of motion. But the benefit of that is it preserves the forms of the laws of physics for all observers regardless of whether or not they're moving. So if one subjects the classical momentum concept consideration moving from one frame of reference to another, imagine a second frame of reference observing an object moving at speed u prime and that second frame of reference s prime is moving at relative velocity v to the original frame s. Now imagine that this is all closed and isolated and in the rest frame the velocity of the object is u and in the moving frame it's u prime and the conservation of momentum will hold and so for instance if we take the momentum observed in the rest frame for this object so p equals m times u and we use the Galilean transformation from classical physics to move to what we observe in the moving frame. We find that of course the moving frame will observe p prime equals m times u prime and we can relate the momentum in the moving frame and the momentum in the rest frame using a Galilean velocity transformation changing u prime to u minus v and then distributing that inside the definition here. So when we do that we find out that the momentum observed in the moving frame is related to the difference between the momentum observed in the rest frame and sort of the frame momentum itself m times the velocity of the moving frame. Now if we then consider changes in momentum in the moving frame with respect to universal and absolute time so dt prime or dt it doesn't matter which in the classical view of physics we just wind up taking the time derivative of momentum in the moving frame and if we distribute that time derivative to the two terms on the right hand side above we find out we have du dt and dv dt. Now since the moving frame is moving at a constant velocity relative to the rest frame dv dt is zero that is the moving frame is not accelerating with respect to the rest frame it's moving at a constant velocity with respect to the rest frame so this second term is zero and we see that we recover exactly dp dt in the rest frame. In other words dp dt in the moving frame is the same as dp dt in the rest frame this is Newton's second law and so we find that this transformation in classical physics leaves the form of Newton's second law invariant at least under Galilean transformations assuming that's the correct term for transformation of space and time and velocity. Now this should all work in domains where the speeds are low compared to that of light but we know that the original definition of momentum was predicated on experiments and observations that were all done in that low velocity large-scale regime of investigation that is sort of the human scale of speeds and sizes we also know that that wasn't quite correct the Lorenz transformation not the Galilean transformation gives the correct way to define relationships between frames great well let's just take the classical definition of momentum and apply the Lorenz transformation the correct transformation between frames so when we do this of course we find that the momentum is equal to mass times velocity and we want to view this in the moving frame where the momentum in the moving frame should be mass times the velocity in the moving frame well if we insert into this the relativistic transformation of velocities in special relativity we wind up with this nasty thing over here the mass times u minus v over the quantity one minus u v over c squared that's the thing we have to insert that contains the velocity of the object as observed in the rest frame and of course the relative velocity of the two frames all right well fine so let's then transform this into a statement about differentials so if I try to write the differential of p prime in terms of the differential of p the momentum in the rest frame if I do the calculus on this I wind up with this horrible looking thing here and then of course if I do dp prime dt prime which would be the change in momentum with respect to time in the moving frame that's related to the change in momentum with respect to time in the rest frame by this horribly velocity dependent thing here this is bad why is this bad it's bad because it totally violates the first postulate of special relativity the forms of the laws of physics must be invariant across all inertial reference frames but here we see that one frame has that forces just equal to dp dt but in the other frame that very same law is horribly velocity dependent this is not good and rather than throwing the whole concept of momentum out the window what we should do is stop and ask ourselves did we really define momentum the conserved quantity associated with degree of motion did we do that assignment correctly in the classical regime of physics did we just get the wrong definition is m times u to naive a definition of momentum given now what we know about space and time and invariance in special relativity now in order to come up with a more appropriate and physically correct definition of momentum that is relativistic momentum there are many many alternative approaches to finding the correct definition of momentum textbooks gloss over this because in many cases the framework for coming up with the exact form of this is not really approachable to students at the level of a student taking this course so I had to cherry pick a methodology to motivate where the definition of relativistic momentum might come from and I prefer the method that comes from my colleague Darren Acosta so let's assume that the problem in the original definition of momentum was that of the definition of time used in the time derivative of space momentum was defined as mass times velocity of an object u velocity is the derivative of space with respect to time so perhaps it's that time definition that's the flaw in the original definition of momentum after all that definition of time did not regard changes from frame to frame as having any appreciable effect on time dt was not necessarily invariant from frame to frame and in fact could have been the root cause of the problem we saw on the previous slide however there is in fact a time unit that all observers regardless of their states of relative motion can agree on they can agree it exists and it can be measured the same way in a specific frame every time and that is proper time denoted with the letter tau so if two events occur and those events are observed by all observers in all frames of reference all observers agree that proper time will be observed in a frame where the two events happen at the same spatial location that is the definition of the proper time it is the shortest time duration measured in any frame by any method of measuring time durations using two events now it's always possible to find such a frame if you're not in the frame where proper time is defined you could always accelerate yourself in such a way until you enter the frame where the regularly occurring events that will be used to define passage of time occur at the same place the time in any other frame is going to be given by the relationship between time in that frame and the proper time so in any other frame the time t for a frame moving at velocity v with respect to the proper time frame is simply given by gamma the gamma factor associated with the motion of that frame relative to the proper time frame times the proper time duration tau now we're talking about inertial frames of reference moving in relative constant velocities with respect to one another and so as a result of that the gamma factors involved here will not be time dependent they are defined using constant velocities of objects or constant velocities of frames relative to one another or both so consider an object moving at velocity u with respect to the proper time frame that in and of itself that object would be a frame of reference that's in relative motion to the frame in which proper time can be observed so let's trade the old time derivative in the definition of momentum that is momentum equals mass times the first derivative of space with respect to time for the derivative with respect to proper time that is momentum will now be defined as mass times the first derivative of space with respect to proper time now we want to convert that into any other frame specifically into the frame where the momentum is being measured which may not be the proper time frame and to do that we just substitute for detail with the relationship between it and dT and if you do that you'll find that you now have mass times the first derivative of space with respect to time times a factor of gamma so if this is a better definition of momentum one that preserves the second law from Isaac Newton under transformations from frame to frame then we should be able to show that and the definition that we get from this exercise using proper time derivative instead of just the plain old time derivative is that the momentum of an object viewed from a reference frame is given by the gamma factor of that object relative to that frame times its mass times its velocity as observed in that frame now again i want to be careful here because the gamma factor that appears here is very specific it has to do with the gamma factor associated with the velocity of that object viewed in the frame of reference the object itself could be viewed as a reference frame of course but because we're going to start talking about transforming object velocities into other frames moving at speed v relative to the one where we measured it it's extremely important to realize that there are suddenly going to become multiple gamma factors in your equations some of those gamma factors will relate to the observation of the object and the passage of time relative to its frame of reference and some of the gamma factors will be related to the relative motion of other frames of reference relative to the one in which you're defining momentum and if that all seems confusing it is and the only way to get better at this is to practice practice practice so the gamma factor here i've denoted especially with a subscript u to indicate that it is not the velocity of another reference frame v that appears in here but rather the velocity of the object itself u and so this gamma factor is defined as one over the square root of one minus u squared over c squared that's what gamma with a subscript u is going to refer to now this redefinition of momentum can be demonstrated with a lot of algebraic pain to leave newton's second law invariant and in fact this is accepted to be now the correct definition of momentum i leave it to the viewer to go through the exercise sketched out on a previous slide to transform the momentum of an object observed in one frame into another frame moving at velocity v with respect to that first observing frame and show that the form of newton's second law dp dt remains invariant from frame to frame now any good definition of momentum will hopefully respect the observations of the past that at low velocities the classical definition of momentum seemed to be good enough if special relativity is the more correct general framework for describing space and time then in some appropriate limit in this case low velocity of the object we should be able to recover the classical definition of momentum so let's give this a try and i'm going to begin by writing the gamma factor for the moving object gamma with a subscript u as a binomial expansion and i've used this before in an earlier lecture so hopefully the rhythm of this will begin to look familiar the binomial expansion is very useful for carefully step by step exploring what happens when you send a parameter of the theory in this case the velocity of an object relative to that of light closer and closer to one of its limits so we'll start by writing down gamma subscript u with its traditional definition of one over the square root of one minus u squared over c squared and then we can use the binomial expansion approach to write it instead as a series of terms of increasing powers of the velocity over c so the first term is just one the second term is one half u squared over c squared etc after that you have terms of order u to the fourth over c to the fourth u to the sixth over c to the sixth and so forth those terms matter when u over c is very close to one but when u over c is very close to zero those higher order terms really don't matter so much compared to the lower order or leading terms in the expansion so now let's write relativistic momentum using this series expansion of the gamma factor so i have momentum is equal to gamma subscript u times m u which is now this series expansion times m times u and you'll notice now that i have an extra u to multiply into the series expansion if i take m times u and distribute it to every term in the series expansion i wound up with something that looks like this the leading order term now has a dependence on velocity but the sub leading term has a dependence on velocity cubed over c squared and then the terms after that are velocity to the fifth over c to the fourth or velocity to the seventh over c to the sixth etc and as u approaches zero that is as the velocity of the object gets much much much much much lower than the speed of light essentially as its velocity is sent towards zero any terms that depend on u cubed over c squared or higher in this expansion are going to vanish they're going to approach zero much faster than that leading term of m u the leading term will dominate the series expansion as u over c gets very small so i can start from this expanded version of momentum using the binomial expansion and in the limit that the velocity is much much less than the speed of light only the first term in the series will survive the one that's largest compared to the others as u over c goes to zero and that's just m times u we have recovered the classical definition of momentum in the limit of velocities that are small compared to the velocity of light so we can proceed similarly now having had some measure of success with looking at momentum as the quantity the directional quantity of motion thinking about kinetic energy which is the scalar or directionless quantity associated with motion that can also be conserved so let's begin to think about kinetic energy in special relativity did we really have the right definition in the old days one half mv squared is that the relativistically correct definition of kinetic energy well we can start by looking at the relationship between external forces changes in states of motion work and kinetic energy when an external force acts on an object and displaces it over some for instance straight line distance s vector the action of accelerating this object under the influence of an external force represents itself a unit of energy being imparted to the object and that energy is known as work work done by an external force changes the kinetic energy of the object it was in a state of some kinetic energy maybe zero and then a force acted on it and accelerated it and now it's in a different state of kinetic energy because its velocity has changed that means that the work done by the force has had some action in changing the kinetic energy of the object and according to the work kinetic energy theorem the change in the kinetic energy of an object is directly proportional to the work done by the external force now the work done by the force on the object displacing it over for instance a linear distance s vector can be written as the dot product of that external force and that displacement now i'm taking some shortcuts here with the form of the work equation this is for a constant magnitude force displacing an object over a straight line distance that's not the general form of the work equation and i will use the general form of the work equation in a moment so let's assume a constant force acts on an object from the perspective of an observer in frame s and the of course the the form of that force and its relationship to the momentum of that object and the changes in momentum of that object will be given by newton's second law the force is equal to the change in relativistic momentum with respect to time this is now the correct definition of momentum in that frame and used in any other frame preserves the form of newton's second law which is f equals ma or f equals dp dt now let's say the force acts over a small displacement a differential of a path ds vector and at any moment it's related to the velocity of the object and the time over which the displacement occurs via the fact that the object velocity is the change in the path position divided by the change in time in that frame in other words u vector is ds vector dt we can write the differential of work the little bit of work done by that constant force over that little bit of displacement by thinking about the definition of work itself in a more general form that is the little bit of work done in displacing the particle over a little bit of path ds vector by a constant force f is given by the dot product of f and ds vector now by newton's second law this has to be equal to the first derivative of the relativistic momentum with respect to time that is what the force should be equal to and again that thing is dotted into ds vector the little bit of displacement but we can replace ds vector with its relationship to the instantaneous velocity of a particle under the action of this external force ds is just going to be equal to u dt now to simplify this dot product i'd like to assume that the change in momentum is in the same direction as the force that's applied on the object so the force is entirely directed in the direction of the displacement or the change in momentum or the change in velocity and as a result of that the dot product trivially becomes the product of the magnitudes of the two vectors to find the total work done by the force which is to be related to the total change in kinetic energy if i can find the total work being done by this force i can absolutely relate that to delta k the change in kinetic energy and perhaps arrive at the form for the kinetic energy what we're going to do is we're going to integrate both sides so by the work kinetic energy theorem the change in the kinetic energy of the object whatever equation that is is given by the work done by the force on the object and that is going to be the integral of this equation here the sum of all the little bits of work should add up to the total work and so that equates to taking the sum of all these little bits here and if i pull out all the constants and all of this i'm going to wind up with the mass times the integral of u times the quantity d gamma u u the dts have cancelled out here in this dot product leaving us with just a differential of the gamma u times u well that doesn't look like a very pleasant integral but there is a way that we can get this into a more pleasing form one that's more easily solved i'm going to start by rewriting this relationship delta k equals w equals m times the integral of the speed times the differential of gamma u times speed to get this into an easier to solve form we're going to integrate by parts to get a final form for the integral this is using the trick that the for instance integral of u dv is equal to u v minus the integral of v d u so let's make some identities between this more general form of the equation and the specific stuff that appears in the integral up here i'm going to identify u as being equal to u that's straightforward i'm going to identify v as being equal to gamma times u when i do that i can then write u times v which i need here as gamma u times u squared and then i need v times du well v times du is just going to be equal to gamma sub u times u times du that's pretty straightforward try this on your own this will help you dust off your integration by parts but you'll find that the integral becomes the following the change in kinetic energy is given now by substituting in using the integration by parts trick as m times gamma u times u squared evaluated at the end points of velocity the initial velocity ui and the final velocity uf minus the mass times the integral of gamma u du again evaluated between the initial and final velocities and if you work through all this you'll get an equation that looks something like this you have this first term m gamma u times u squared plus the second term which looks a bit nastier mc squared times the square root of 1 minus u squared over c squared and we are to evaluate this at the end points of the motion so let's do ourselves some favors here and assume that the initial speed of the object is zero that means that the initial kinetic energy must also be zero whatever the equation for kinetic energy is that's got to be true the final speed will just set to be u some final speed u that we achieve and at that point the kinetic energy is k so substituting all this in we find out that the kinetic energy is equal to m times gamma u times u squared plus mc squared times the inverse of gamma u minus mc squared and rewriting this doing some algebraic gymnastics with the gamma factors and mc squared you'll find that this can be simplified to this lovely little equation here the kinetic energy of a particle is simply given by the quantity of its gamma factor minus one times mc squared now i'm going to let you show that last step on your own it's good practice for the gamma factor gymnastics that you'll often have to do in these problems we find that the relativistic kinetic energy is just gamma u minus one all times mc squared m is just the mass of the object c is just the speed of light and gamma u is its gamma factor relative to the frame in which the object is being observed you can use the binomial expansion trick once again and i encourage you to try this on your own in the limit that the velocity is much much less than the speed of light and you'll find that the expression reduces to one half m u squared the classical definition of kinetic energy these quantities for momentum and kinetic energy have all the right behaviors they don't look like what they looked like in their assumed classical forms they reduce to their classical forms in the appropriate limit and they leave laws of physics invariant where they can be applied now we've looked at momentum and we've looked at kinetic energy but what about the total energy of an object in special relativity in classical physics the total energy of an object was just its kinetic energy and if it wasn't moving it was said to have no energy now that's not entirely true if that object was being acted on by an external conservative force it's possible that that object could have some potential energy associated with it for instance if you raise a ball up in a gravitational field it has some now stored potential energy if you let the ball go it will be released and turned into kinetic energy but for a force-free situation an object at rest really had no defined energy in classical physics is that still true well we can start by just simply noting that as before the total energy of a body in any system is composed of at least two parts a kinetic part describing the energy associated with its motion and a potential part describing any energy that is stored internally in the system and that could be released by some means now the total energy then is the sum of these two pieces so I will use capital E to denote total energy k to denote kinetic energy and u to denote potential energy or stored energy we see that kinetic energy in special relativity is the difference of two pieces k is equal to gamma mc squared minus mc squared so if we rearrange the above total energy equation and then plug in this expression for kinetic energy we arrive at an interesting preliminary conclusion so if I take k and solve for that using the above equation I find that k is equal to the total energy minus the stored energy and if I substitute in with this equation I find that k is also equal to gamma u mc squared minus mc squared and by identifying and relating terms in these two equations for k I can draw the conclusion that the total energy of an object is given by gamma u mc squared and the stored energy of an object even one that's at rest is mc squared it's mass times the speed of light squared so by this identity the total energy of an object in special relativity is given by gamma u mc squared and in the limit that the object is at rest we see that the total energy becomes not zero but mc squared mass times the speed of light squared and we note that the same quantity mc squared has been identified in the above exercise as a kind of energy stored somewhere in the object what's particularly remarkable about this exercise is that by our own means we arrive at a conclusion that albert einstein too arrived at in his miracle year in 1905 it's one of the most profound conclusions drawn from special relativity that mass is itself a form of stored energy and even when a body is not moving its total energy is not zero but rather decreases to a minimum given by e equals mc squared and this latter equation is one of the most famous in the history of science it is an equation that would lead to the development of nuclear weapons nuclear power plants the pet scan a non-invasive medical invention the particle collider and many other technologies taken for granted feared or loved in the modern world for an indivisible fundamental particle for instance the electron is a pretty good example of this we've never seen that the electron is made of anything else one has to conclude then when when it's at rest its energy is the result of some kind of intrinsic mass a fundamental property of matter just like electric charge appears to be a fundamental property associated with matter now it's interesting it's interesting to ask yourself well how much energy if i could find a way to convert it into some other form is contained in the mass of an object well consider the fact that a typical ish human being has a mass somewhere in the realm of 60 kilograms and if by some means all of that could be converted to another form of energy like kinetic energy or chemical energy or radiation then the above equation tells us the energy in joules that this represents e equals m times c squared which is 60 kilograms times something that's about nine times 10 to the 16 meters squared per second squared this yields a total energy in joules stored in your body in the form of mass energy is 5.4 times 10 to the 18 joules now for comparison the energy the little sliver of energy that reaches the earth from the sun every second a tiny bit of the total energy that the sun can emit and yet the same energy that keeps our planet warm and hospitable to life as we know it that energy is 10 to the 17 joules the stored energy in the form of mass energy in your body is a factor of 10 more than that and if it even a fraction of it could be converted into some other form of energy it represents a terrifying amount of potential so let's do an example of this sort of hidden energy of matter by considering the mass that's lost by a uranium nucleus during fission the process of breaking that nucleus into pieces nuclear fission was itself first discovered by physicists and chemists Otto Hahn and Fritz Strassmann and this was done in Germany in December 1938 if you know anything about your history this was the period of Nazi rule of Germany now the observation of nuclear fission especially the fact that the uranium nucleus was observed to split into nearly two equally massed parts was a bit of a mystery and it was explained very quickly thereafter by physicist Lisa Meitner and her nephew Otto Frisch the physics community came to understand that what was going on here just in breaking up the nucleus of a uranium atom was the potential of a vast power that lays in the hearts of all unstable atoms to be unleashed on humankind so consider the process shown at the left this little blue ball is supposed to represent a neutron one of the components of a nucleus they can be freed from the nucleus and fired at other nuclei a neutron striking a u235 nucleus will set off a chain of events that results sometimes and it breaking up into roughly equal mass pieces a nucleus of the element krypton krypton 92 and a nucleus of the element barium barium 141 now the mass of the unsplit u235 nucleus is given in atomic mass units using this number and i'm keeping the precision on purpose because small differences when it comes to mass energy matter a lot now the masses of the daughter nuclei krypton 92 and barium 141 are 83.798 atomic units and 137.327 atomic units respectively now i should note that for purposes of conversion one atomic mass unit is given roughly as the mass of a proton 1.6605402 times 10 to the minus 27 kilograms now if you check the daughter masses do not add up to the parent mass mass is not conserved in this process it's lost in the fission process and the amount of mass that is lost is roughly 14 atomic units even accounting for the fact that three neutrons get produced in the fission process that only adds up to roughly three atomic mass units that's still 10 atomic mass units or so of energy left over that could be converted into forms like kinetic energy or heat now since we've checked that the daughter masses don't add up to the parent mass we recognize that there's missing mass energy here and that mass energy that's missing is about 2.1 times 10 to the minus 9 joules about a billionth of a jewel now that doesn't sound like much but consider what's going on in this cartoon at the left three neutrons have also been produced in this process three neutrons that are bullets that can be fired at other u235 nuclei that might be lingering nearby for instance if you highly enrich uranium to greater than 90 pure u235 it's possible to set off a reaction of events that cannot be stopped and has catastrophic consequences this process can initiate what is known as a chain reaction as you multiply the fission process over and over and over again using these neutron bullets that get produced from the first fission process so for instance the first split makes three to the one neutrons the second generation of splits makes three to the two neutrons because each of these neutrons goes on to split a uranium nucleus that produces three neutrons so that gives you nine the third generation gives you three to the three or 27 a typical chain reaction in purified u235 can go something like at least 40 to 50 generations before this device will blow itself to pieces that's a multiplicative factor of about three to the 45 or three times 10 to the 21 so you're taking the energy left over from one split and you're multiplying it by about 10 to the 21 now those neutrons won't all go on to split uranium nuclei some of them will be thermalized and will result in dumping thermal energy into the body of the material or into the surrounding air around it if the energy of those neutrons is converted to heat from collisions you'll find that this level of multiplication is sufficient to explain the explosive yield of the very first uranium atomic weapon codenamed little boy which was equivalent to about 13 to 18 000 tons of trinitrotoluene or tnt being dropped on a single city that's 54 to 75 trillion joules of energy that weapon devastated the japanese city of Hiroshima at the end of world war two so we can see that a little bit of mass energy goes a long way and it can have positive applications in society it can have negative applications in society but all of this stems from the revelation that energy and mass are not distinct from each other now in classical or Newtonian Galilean physics there is a relationship between momentum and kinetic energy we know that k equals p squared over 2m go ahead and try it yourself if you've never seen this before convince yourself that this is true in classical physics p equals mv k equals one half mv squared do the substitution there's a relationship between kinetic energy and momentum now in the more correct description of space and time given by the special theory of relativity we have kinetic energy mass energy and momentum what is the correct relationship between these things let's begin with the momentum equation that is momentum is equal to gamma u times m times u let's then insert a sort of clever multiplicative one multiply this equation by c over c which has the effect of just multiplying the equation by one but allows us to distribute the c in a useful way we can take the denominator one over c and move it to the left and associate it with the velocity of the object u so we wind up with a term of u over c in this equation now we know that the equation for total energy has c squared and gamma u minute and gamma u depends on u squared over c squared they're related to each other so i recommend you try squaring this above equation square p which then squares this thing on the right hand side gamma u times m times u over c times c and when you do that you get this equation here now if you then use the fact that u squared over c squared can be related to gamma by one minus one over gamma squared you can then insert that and you find that p squared is equal to m squared c squared times the quantity gamma u squared minus one now if you stare at this for a moment you'll notice that this equation has a piece in it that's awkwardly close to e squared e squared the total energy would be given by gamma squared m squared c to the fourth so multiply both sides of this equation by c squared we wind up with p squared c squared on the left this is going to be equal to m squared c to the fourth times the quantity gamma squared minus one if we then distribute the m squared c to the fourth into the parentheses we wind up with this equation and we can identify the first piece here as e squared and the second piece here as m squared c to the fourth or the square of mass energy so putting it all together we find that energy and mass and momentum have a relationship to each other and it's an elegant relationship between an object's total energy its momentum and its mass energy and special relativity and that relationship is given by this quadratic equation e squared equals p squared c squared plus m squared c to the fourth now this equation allows us to think about some cases of certain kinds of particles and one very interesting special case is to look at particles that have no intrinsic mass now the electron is a particle with intrinsic mass the muon is another example of a particle with intrinsic mass albeit 207 times that of the mass of the electron but we can ask ourselves what if there is a particle out there in nature that has no intrinsic mass can it exist and if it did exist what would its properties be well let's take a look at that we can use these relationships to study this very special case now it will turn out that photons which are the particles involved in light have never been observed to have an intrinsic mass they behave as if they have no mass at all so let's go ahead and take that exact limiting case of m equals zero and if we plug that into the energy momentum and mass energy relationship we find that we're left with e squared equals p squared c squared that is we can take the square root of this and say that the total energy of a massless particle is given by its momentum times the speed of light the total energy of a massless particle is entirely energy of motion in other words if such a particle could be stopped from moving you would have to interpret it as them ceasing to exist their total energy would suddenly become zero but of course that violates the conservation of energy you can't just make energy go away without consequence so this implies that such particles can actually only be stopped when they're removed from the natural world by being absorbed into another process now you might then feel emboldened by this and say aha well this is great i'm going to go ahead and figure out what e and p are for massless particles but then you very quickly run into a problem and that is that e depends directly on m and p depends directly on m as defined in special relativity and so you get no useful information from these equations from special relativity special relativity can't give you otherwise useful information about what the total energy actually comes from and what the momentum actually comes from for such particles so what is it that defines energy and momentum of a common particle like a photon which so far as we know has no intrinsic mass no mass energy well to answer that question we're going to have to wait a little bit longer and see as we enter the next phase of this course so to conclude this lecture let's look at what we have learned we have learned how to define kinetic energy and momentum while incorporating the principles of special relativity and in doing so we've learned something deep about the nature of mass and we've learned to appreciate that there is intrinsic mass in nature and that mass in general is associated with a kind of internal energy of all objects an object at rest does not have zero energy it has internal energy given by mc squared we've also learned about the relationship between energy momentum and mass we've looked at some applications of the relativistic concept of energy momentum and mass and we've left ourselves with some questions that we can hopefully resolve by delving deeper into nature in the next phase of the course


Catch a mĶa, mĶa ā8a āVimāscis Ākāā …. So letís say a set of programs have been developed, ṣaĀsa your project develop. ἔνα learned the project word  socied string alone application ln which case any program that is ever required to do anything continent of that package itself in that case that programming package never needs to interact with any other package or any other program but that is not the case invariably any programming system will either require to invoke some additional functionality from some other programming system or will have to provide a link to itself to an external programming system so that somebody outside can invoke a desired functionality from my programming system. Such is the case that all pieces of software all over the world might need to talk to each other and talking to each other does not mean talking in a conversational sense but being able to invoke functionality from within a programming system. So suppose we have a set of programs how do I invoke one or more of these programs from my program. Every piece of software is built with interfaces so at the interface level you expose the package to the rest of the world saying look I might have 30,000 lines of code maybe 200 functions all kinds of data structures 50 files whatever whatever but there are three or four things which you might want to use which I have already coded so how would you invoke a function from my package. Observe that so far all the programs that you have been writing including n number of functions that you might write are all monolithic programs everything is contained within so you write the functions also within your program if you don't like to write the functions ahead of the main program we have seen how prototype can be declared at the beginning of the program and then the actual function code can be written later because without the prototype definition at least if I call a function from within my program the compiler won't understand what I am calling so it must know what is the prototype of that function. Of course later on when I compile my program my functions also need to be compiled but suppose somebody has compiled these functions separately he says I won't give you the source code but I have the compiled version this is the prototype of the function go ahead and call this function now if I want to do that I must make that compiled version of the function available to the compiler linker system saying that look this is my program these are my functions additionally I might be using functions such as this this this which come from somewhere else I don't have the source code so I can't give those functions for compilation to you but I have the compiled version of those program these are typically in the form of libraries they are compiled library so I say compiled libraries are available so please first compile my program after you translate it when you link pieces together also link the translated version which are pre-prepared already available of those functions and put all of them together and create an executable file that is usually what is done in real life in order to use libraries of functions but whether you are using libraries of functions which are to be linked explicitly while you compile and link your program or whether there is a completely independent system to which you want to make a function call by perhaps sending a message to that system or something like that in either case you need to know how you will interface your program with some other program or how others will interface their program to your program all such interfaces in the hands of the application program application program is people like us who write programs to implement certain applications for us such interfaces are available they are known as application programmer interfaces or simply APIs and these are APIs are essentially as we will see essentially the definition of functions which are available what kind of parameters are to be passed to the function and what kind of return value we will get let's just have a re-look at the use of functions so recall we define structure student info, care role 10 etc etc this is the definition of a student's information then we have a function prototype here it says wide print student data struct student info we are not writing the function here the function would be written somewhere else the reason I am putting a prototype here is later on I will say that even this prototype may not be written explicitly by me it might have been put somewhere else but the point is once I include this structure definition observe that this structure definition is before the int man just as the function prototype is also before the int man so these are called global declarations that means my entire program can exist any one of these in fact the top lines which will soon understand in a better fashion include IO stream, include CST delay are also considered global declarations because they are outside the main program they are available to everybody so this is the standard way in which we use that in the main program of course I might declare a variable called as with structure student info and then I can do whatever I want to do and I can invoke that function that I have written the alternate way is that the student info structure which I had defined I need not actually include it physically in that program I could put that in a separate file and let's say I call it student info dot H dot H is a standard convention in CC++ system to describe a separately created header why is it called header because it is usually it appears at the head of any program function or whatever so if I create a separate file I can tell the compiler to include it in my program that's the whole point that physically that file is separate which contains that header currently we are talking about a header which just describes the structure student info in which case I can do that by using an include macro so this is the include statement that I will write here hash include student info dot H when I say this the way the compiler is all set it first locates this file and physically put the contents of that file here then it gives everything to the compiler needless to add it must be doing exactly the same thing for the other two include statements that I have and that is exactly what is done if I have components of my program which are required for proper compilation and linking but they are not physically put in the same file then even if I put them elsewhere I could give an include command this is called a pre-processor command a pre-processor meaning even before compilation when you say C++ something before compilation the C++ system reads your entire program and resolves such references as include and whatever whatever so it collects information from other files put it all together and then sends the whole thing for compilation so these could be macros, these could be includes these could be whatever else essentially the final source code which is compiled is not just the one that you have written but an expanded version by inclusion of such files why is it written like this whereas these are written separately or differently any idea ok this means that the student info.h is to be found in the current directory what is the current directory in whichever directory you are issuing a C++ command where your program file itself is program.cpp in the same directory you have this file so when you have that you simply put that is double quote as a filename and the filename is expected to be found there of course the file could be somewhere else in which case it is possible to prescribe the whole path why don't we prescribe the path such as iostream, cstdlib etc 2 reasons one these are standard C++ libraries so when the C++ system of compiler linker etc is installed on your machine the paths are automatically set and unknown to C++ C++ knows where it will find standard Cstdlib where it will find iostream etc but there could be other libraries which as i said some package somebody else has written we are going to discuss the eased windows package but there could be any other pack so if there are other libraries i must indicate where these libraries are to be found these paths are indicated through the commands that we give for compilation and linking by saying that when you convert my program into a .o file or translated version called object file and later on when you link it please link it with this library, this library, this library because in this or this or this or this library you will find the references such as iostream, cstdlib or any other library names that we mentioned so is this understood this mechanism pretty simple and straightforward you may want to experiment with path and such things incidentally there is a variable i think i had mentioned it once there is a variable called path variable which is part of your computing environment when you log in you have a file called .bashrc which stores the initialization of all these operating system environment variables this path you can get to see the path by giving a command echo dollar path any operating system variable when you want to refer to its value you said dollar something something so when you say this you will get to see the path the path is separated out by colon so you will have for example slash usr slash bin colon slash usr slash include colon etcetera etcetera this path is nothing but identification of separate some directories and directories in the file system in which the command that you give here is to be located so when you say c++ for example where is c++ so c++ will be found either here or here or here or here or somewhere since the current directories usually not included by default in this when you say a not out nothing happens because the machine cannot figure out where the a dot out is and that is why what you are required to say dot slash a dot out when you give this command you are telling the machine that don't search through the various sub directories of path the command that I am giving you is to be found in the present sub directories itself and that is why you said dot if you don't want to do that you should include dot in the path and the easiest way is to extend the available path let me just give you that command because it's a very easy command to use at the dollar prompt you can simply say path equal to dollar path colon dot that means whatever is the value of path put a colon after that and put a dot after that and then you have to say export path after you do that you can simply give the command a dot out you don't have to say dot slash a dot out I hope you have figured out why because that dot is now explicitly included in the path if you wish you can put these commands by editing the dot bash rc file which is the file which is executed automatically and it creates all these paths and other environment variables so that is one possibility anyway incidentally many of you will find that this dollar symbol is preceded by things like machine name and directory name and such things so quite often when you go to sub directories and sub directories your prompt itself comes out here and the command that you write invariably turns out so in order to simplify the prompt you can use a simple command called ps1 equal to say dollar if you say that from this point onwards you will find the prompt to be exactly in the leftmost corner it will never be preceded by any other trash of course you won't automatically get to know which sub directory you are in etc etc but this makes for a simpler reading of the commands that you try ps1 incidentally stands for the prompt the prompt string that should appear instead of it showing you variety of things you are telling the operating system that look I am comfortable with just one character prompt and that's all you show me these are anyway some side issues let's get back to our discussion essentially then the preprocessor will take care of these things so as I was saying what if the functions themselves are written somewhere else what we saw in the previous screen was if the header file is written somewhere else the header file which was defining the struct info which was essentially a data structure now just as there is a data structure there could be also a function header such as the prototype now that is a character string exactly is to be included as it is that could be included with this idea of .h however if the functions have been compiled and kept in a library I cannot just say .h and include because they will not be header files they will be compiled version they will be object files we need to do two things essentially one is the function prototype as we said apart from the data structures that we define and we need the translated version of those functions which we wish to use but which we have not written they need to be linked with the translated version of our program and that is where we need to include library files in precisely for this reason and this method is essentially an API so the .ez windows package which we are going to discuss or an .erp package which is used in real life any number of package any package that you can think of a high precision arithmetic package somebody has written what it means is that person would have written some .50 odd functions compiled all of them and kept them in a library and then say that if you want to multiply two high precision numbers invoke this high precision multiply function so I need to know the prototype of high precision multiply function alright but I also need the translated code high precision numbers do the algorithm and calculate the result so I need to invoke it and link that function these library files in unix environment typically take the form of .a files called the archive files or .so files which are called the shared objects the shared object is effectively equivalent to what some of you might be familiar with the .dll files which are the dynamically linked libraries in the Microsoft environment they are all similar so they all permit you to create packages and use them in any programming environment what we are discussing is how to use these in cc++ environment but they could be used in any programming environment exactly the same fact all standard libraries of c++ provides such interface and that's the reason we say this hash include whatever library so now how many libraries do we include depending upon what kind of functions we are using in our program so if we are using let us say we are handling string functions string length now we know where that is that is in the c string library so we have to say include c string we are using c in c out now we know that is in the io stream library so we have to include io stream it is not uncommon to see a program of a reasonably complex software would have something like 20 include statements perfectly fine now there is one more package which we take for granted the operating system itself we never look at operating system as a package operating system is in fact the environment in which we are working but we should not forget that that is also a package of software there is also a set of functions and so on now that package is interacting with us remember when we say we execute our program what do we do we execute our program means the operating system we are trying to tell operating system please run my program so the operating system must have an api for me both for it to invoke my program and for me to use some functionality of the operating system within my program if I so desire such interface is called the system level interface and all the functions which are intrinsic functions of the operating system not of an external package intrinsic functions of the operating system these intrinsic functions are invoked using what is known as systems cause so all the OS functions they are called system cause rather than function cause so system cause means system functions which are part of the operating system they have to be used next we discuss the topic of random number generation how many of you are familiar with pseudo random numbers random numbers everybody is familiar with no not much ok everybody has played some kind of a board game where you throw a dice and you get any one of the faces 6 faces so 1 2 3 4 5 6 this next 10 ladders whatever whatever n number of place practically everybody has played that when you throw a dice dice is assumed to be a normal dice meaning that any one of the 6 numbers can come with equal probability when such is the situation the number so generator is called a random number the fact that they are equiprobable cannot be ascertaining by throwing the dice only for 1 or 2 or even 6 or 12 types for example if you assume that if I throw it 6 times one should come exactly 1 2 should come exactly 1 etc that will not happen but if you throw it 6000 times then roughly 1000 times 1 will come 1000 times 2 will come 1000 times 3 will come and that is why these numbers are known as uniformly distributed or equiprobable random numbers if you want to implement any board game or a game of chance or if you want to simulate where the events occur at random times then within your program you need to generate random numbers consider this in our simulation of large data we had arbitrarily taken serial number as roll number from 1 to 5 million but imagine if I were to actually stuff in the information some domain let's say language spoken now there are 20 languages and there are let's say 5 million participants in my portal I want to test my software so I want to create realistic data so I have to generate random numbers to allocate different languages to be spoken by the artificial students whom I have generated and that means I will have to take these 20 languages and allocate one language to this person another to this again that to this and this must be done randomly but in a uniform fashion I need therefore the mechanism to generate random numbers now any random number that we generate with an algorithm cannot strictly be a random because randomness depends upon the fact that there is no algorithm so therefore such numbers which are generated by computer algorithms are called pseudo random numbers there are articles and research papers on how such random numbers are to be generated we are not interested in that but we want to concentrate on using such numbers if they are generated fortunately there are other classes and this standard libraries of almost all programming languages will provide a function which will generate random numbers for you a function called rand which is available rand function generates random numbers between two values 0 and rand underscore max this rand underscore max is also defined in one of the header files it is typically the largest unsigned into the namb ޚප ම්ඳඇයකප දේඵත්ලරීමන්න්ත්, කසලත්න්ය එය මභෙලයක්ත්ලි,වකක්ත්යක්යක්,වකරය මභෙලේතය්නත්නන්න්රමක්මරීමදතික්ත්ර මභෙලේ්රමක්ම්න්නන� Ḙ トギ Ḝflies Thrillion times , 5 000 times 20, 000 times you will be able to demonstrate the uniformity we shall see how it can be done The point is that Okay your program is executed for your purpose you have generated some 527 random numbers they have come, you have run your job let's say simulation Tomorrow you run your program again because the algorithm is same Exactly the same sequence Sa. There is nothing random about the second execution also to be different. For this purpose most random function generated libraries will provide for you to give a what is known as a seed or a seed value or a number which is the starting point of a sequence of random . genuinely if you change the starting point the specific sequence that will be generated and there is a separate function పటకపెనే నావార్లిందిసిసి పతిన్ట్టాదియాల్లూతౌనాస్ పనినిమావమిండి సరిమాస్మ వెలలిద్కతినండల౪౏స్ఫ్రన ground も fill నిభాయచాయానథ౦ిస్ environmental ధైపా� సొత్రalla(?)ft ఠూండానacam ! వ్యచినండపగ్యడ దిమ్ర్నన౏ ప్ట sost�్త్స్ side nails నిత్లివం. Here is one possible simple way of doing that. I declare a dice value as an integer variable. I declare unsigned int as a seed value for the seed. I declare ik and count 6 because I want to determine how many times different digits appear when I throw a dice using this simulator. I collect an integer seed value from the user and invoke this SRAM. When I do that, I am resetting the start point for the generation of the random number sequences. I can generate any one of the 6 digits 1, 2, 3, 4, 5, 6. I want to generate thousands of them and count how many times 1 happened, how many times 2 happened, how many times 3 happened. For that purpose, I have put an array called count array. I initialize the count array to 0 and then set up an iteration say I run it 60,000 times. That means I will run 60,000 and I will generate 60,000 random numbers. How do I generate 60,000 random numbers? Very simple. Every call ran, opening bracket, closing bracket will get me a random number. Of course, this is between 0 and very large number. So what I do? I take a module of 6 value of this. Whatever be the random number, this value will be either 0, 1, 2, 3, 4 or 5. I add 1 to it and what I get is a dice value, a proper dice value. So I can simulate a dice throw because as a result of this calculation, I will get a dice value which will be between 1 and 6. I can use this value so generated for either simulating a board game like snacks and ladders or doing whatever. Here the objective of this segment of the code is to find out how many times different values occur. As I told you, if you just throw it 10 or 20 times and conclude that it is uniformly not distributed, that will be wrong but if you do this and every time a number happens, use the associative array principle, subtract 1 from it, this will be between 0 and 5 and you increment that particular element of that array. So if you get 5, you increment 5th element, you get 4, you increment 4th element, you get 0 meaning 1 minus 1 so you increment 0th element etc. At the end of this iteration, the various counts that you will print should roughly be how much? Well, I am conducting this iteration 60,000 times. So every digit should happen about 10,000. Now it will not happen exactly 10,000. You can try running this code. Some digit will happen say 9,854 times. Something will happen 10,400 and something like that. And that is real so there is no problem there but these are truly uniformly distributed random. The problem with this approach is that every time you run a program, suppose you are simulating a game of snakes and ladders, now you don't want both the players to go through exactly the same process randomly and still arrive at the same result. You would like randomness to be different. On the other hand, you have written a simulator. Why should user be asked to give a number? Can't I do that automatically? So what I want? I want a number which will be different every time I run a program. What could be such a number? The suggestion is I can use the random number generator to generate a seed. Good point but sadly it will not work. I generate a random number S-rand. Remember every time I run the program it will generate the same random number. So that I put it as seed again it will generate the same signal. I need a number which is guaranteed different every time I physically run the program. So one of the things which is used universally is time because time is a one-way street. No instance comes back after it goes away. So today at whatever 10-15 is different than yesterday night 7 o'clock. It will be different tomorrow morning. In fact it will be different 5 seconds later. It will be different even 1 millisecond later. The trouble is the time is available with our watch. And that will again mean I will have to feed something. Fortunately the operating system of almost all computers maintain a time internal. And there is an operating system called which permits us to get time. There is a function called time. It has variety of types of parameters but a particular parameter 0 if you give time 0. Then time 0 will go to the operating system. It will ask operating system to look up its own watch internally at that instance of time. And so return me what value is returned. It returns the number of seconds that have elapsed since an artificial date 111970. Starting from the greenwich mean time. Midnight of greenwich mean time. Large number of seconds. But every second that value will be different. So if instead of collecting some seed from you if I simply say srand time 0 as the first instruction in my program. I would be necessarily setting a seed which is different for every execution. And then when I generate my random numbers I will get explicitly different things. Incidentally I would like you to look at the time function. For example the time function returns a value which is an integral type but not a normal unsigned int. It is actually type which has been defined there called time underscore t. You will find in the C++ libraries variety of types get defined for specific usage. So this time underscore t is actually a type which is of the integral type. It is alright because by the normal common sense whenever an integer value is required and the type is an integral type but not exactly unsigned integer the compiler will issue instructions to convert it automatically. So this type will be converted into unsigned int which is required as a parameter for time. However if you wanted you could explicitly invoke that casting. So if I say in bracket unsigned int in front of time 0 this means that whatever is the value of type returned by time it should be converted to unsigned int before calling the next function. This explicit declaration explicit casting is often very useful. Let me just digress a bit for a minute and show you how explicit change explicit casting is almost mandated. Consider this let's say I have n number of students and let's say I have bought a large number of apples so I have mapples and I want to distribute these apples to students. What I want to calculate at the gross level is what is the average number of apples per student? Average will be naturally float but these will be int. So if I say in my program average is equal to n upon m. What will I get? Integer divided by integer and obviously there should be more apples than students the average number of apples will be 0 which is not the correct result. I could do one of the two things. I could say that look I want to avoid this. So let me declare instead of this int let me declare this as float. Even declaring one of the values as float will solve the problem because when I have an operation between float and int then int is converted to float. However this will solve my problem but programming coding standard wise this is wrong. I use float strictly when I am likely to have fractional values. I am very unlikely to have 27.5 students. In exactly the same fashion I am unlikely to have 4 and 3 fourth apples. These are natural integers and therefore they must be represented as integers which is the correct way. So the right way of writing this expression will be I return this integer but I say average is equal to this putting float in brackets actually forces a casting forces a conversion temporary conversion the value of n remains integer but it is converted to float before it is divided by m. If I wanted I could do this as well although the second part is not required that will be implicitly done if one of the things is float. So is that clear? This is called the casting and the casting operation is used very often in programs. Lastly I want to discuss the assert micro. There is a library called assert library and it is extremely useful to simplify error checking and what should I say any sad termination of my program if there is an error. Recall that in our discussion on the file processing we have come across such a code. We had said in file is equal to f open whatever whatever file name but if the file could not be opened for some reason we were checking whether the pointer returned by that open statement was null and if it was null we are saying error in opening file and return one. Terminate the program. This is often required to be done. The more external functions that you call the more will be such code in your program. Why? Because you are expected to test every time whether that external function work properly or not. So C++ provides a simpler mechanism called assertion checking. So basically what you say is I assert that the file opened properly but if the assertion has backfired then please do something What is to be done? Well what is to be done is give an appropriate error message. I don't waste my time writing error messages for every now and then in my program and I call this function. I will just tell you what condition is to be checked. That is called assert checking and the way it is done is by writing this. So for example this particular code is more simply written as assert in file not equal to null. So my assertion is I have opened a file. File has properly opened. That is my assertion. I am assuming that is so. So I say assert this. If however file has not been opened for any reason this condition will be false. If this condition is false the assert library system does the following. It gives you an error message. This error message is given on stderr which incidentally is a file connected automatically to your terminal only so there is no problem. And it will tell you assert failure and it will say why. Maybe it will say in file or whatever something. And it will also give you the source file name in which this program code was there. So it is sufficient for you to decipher what exactly happened. Additionally after giving that message on stderr it will terminate the program abnormal. So you don't have to worry about it. Again it is exactly the same thing as you are doing here. But remember in a large program such as the one which you will be writing for your project it will not be uncommon where you will need maybe 30 such statements there. And once you are writing your own statement you will naturally think of writing different error messages. So instead this assertion is an extremely simple way of ensuring exactly the same thing. With this we begin our discussion on the object oriented program. I am not suggesting that we have discussed all possible features of CC++ which are procedural in nature. There will be some more which we will come to as and when we proceed. However the features that we have discussed so far in this course are actually adequate for you to write programs for practically solving any problem. But if we look at programming in an object oriented way the programming task becomes further easier. And that is what we are going to see now. So far what we have seen in the CC++ programming language features is the set of procedural aspects of that programming language. But there are strong object oriented aspects which we shall be examining over the next 2 or 3 weeks. And you may be able to use some of them very quickly in your projects further simplifying the course that you write. Objects occur very naturally and object classes are almost a natural division or classification that we are able to do. We discussed when we modeled information system we said students, student is an object and all students form a class. We call that an entity class. An entity is nothing but an object because an object has certain properties. A student has certain properties as we saw. What we forgot to mention because we are modeling only the property or the data part about that object called student. But that student also has certain behavioral aspect in the context of the problem that we have seen. For example, a student's hostel number and room number may change. A student's marks may get updated. The hostel number, room number and marks are the property or the description of that student. The fact that these can be changed is the behavioral aspect of that object. The way I am trying to illustrate it is the closest equivalent and much stronger equivalent to the object oriented notion in programming that we find in real world. Namely a cell, a biological cell in any living species. That cell is an object. Those of you have studied some basic biology somewhere would remember that every cell has a nucleus. By the way, all the information about that cell is contained in the nucleus because your DNA, RNA, etc. are all part of that nucleus. This nucleus is surrounded by some fluid and then there is a membrane. The cell interacts with the rest of the world through this membrane and therefore membrane forms an interface. Do you know how these interfaces work? They actually work through messaging system. For example, if by mistake you put your hand to a flame, that portion of the skin will get very hot very quickly.  You would have felt this sometime or the other. Have you tried to analyze how this happens?  So the information has to reach from that tip of your hand all the way to the brain. Because the motor functions of the muscles which cause your hand to be withdrawn are controlled by the brain. Only when brain takes those muscles to contract and move, then they will move. So messages have to pass across from that tip travelling fairly large distance if you look at the sizes of the cells which are taking this message across. And how will they take the message across? Because each cell is a completely independent self-contained unit. So the cells actually interact with each other and this interaction happens through some kind of a message passing. It is known for example that in the nervous system the neurons which pass messages across actually generate some sort of a chemical which creates some voltage difference between two points and that voltage difference corresponds to information. The plethora of research on that will not go into those details. The point is that the actual properties of a cell are contained within the cell itself. Now when a particular message has to pass that look something has happened in that corner, please inform the brain. At that point in time the 250 odd properties which are part of this cell are not relevant. We want to know whether this cell can transmit this message or not. Or whether it can generate something else. The behavior therefore is restricted to what the external world can cause that behavior to happen or what the cell can cause the behavior to happen in other cells. This encapsulation, the private property of the cell need not be known to the rest of the world. I only need to know how to invoke it. Take students as objects. There is a project to be done. Now there are individual properties in each lab batch. If I take lab batch as an object, batch as an object and the class of all batches as the class. Now each batch has certain properties. Those properties are known to those batch members. External person who is interacting with that batch will only say alright this is the problem that you have chosen. Okay work on this project. And at the end of 20 days, 15 days whatever you will come up with those program. So your behavior includes ability to write programs, ability to compile programs, ability to discuss etc. I am not invoking any one of these. I am saying do this project and submit weekly reports. Interaction between different objects can be extremely simplified. If the interaction is limited to one object invoking some behavior or some action on part of the other object. Further the internal information about the object need not be exposed to the rest of the world. It is not required. The internal information will be used by the object itself while displaying that behavior. Now this beauty of encapsulation and this beauty of interaction between different objects through messages is what has given rise to a rethinking on programming. And therefore programming systems evolved which said that why can't I instead of calling my values as variables and my operations as multiply, divide etc. Why can't I classify all this plethora of features into an object oriented philosophy. And therefore if I could define a class of objects. Where a class would be equivalent to the complexity associated with the structure and its behavior. So if I say student as a class for example. It will have every student will have same properties and every student will have the same behavior. In the context of what we discussed the other day in terms of modeling. We say that if we have a student class then the properties of all students will be same. What were the properties that we said student as role number, student as mark, student as hostel number, student as room number. Amongst thousand properties we said these properties are relevant to us. And in terms of the behavior or action what is possible with this information. As I said a student may change room number from ground floor to fourth floor. Students marks may get updated. Now if there is a class of students for which I define functions which will change the marks. I define another function which will change or update the hostel room. Then I don't care how exactly this information about hostel room etc. is maintained inside the student class. Somebody may be writing it on a piece of paper. Some student may be putting it on a computer. I don't care as long as I can tell student to change the marks or tell student to change the hostel room. Or the student can tell another class called modern class to do something. Now that behavior is what we are trying to incorporate in our program. Very crudely whatever we have discussed as variables, arrays, different types, data structures. They all form the basis for describing properties of class. And whatever we have discussed in terms of coding, actual computations, reading, writing, input, output, assignment, calculations etc. That will be modeling our behavior. And the way we model the behavior is instead of writing these instructions in an aphazard fashion we identify what are the behavioral patterns which are most important from a programming perspective and write functions specifically for that. These functions in the context of a class are called member functions of the class. And the properties are called data members for the class. So the behavior of an object essentially is invoked by sending a message and message is nothing but the set of parameters that you will send along with a function. So when you call a function and set of parameters you are basically asking that class that please invoke this behavior of yours, that means execute this function and these are the parameters using which you have to execute that function. So in a nutshell this programming paradigm which is different from a conventional procedural programming paradigm by the way I have tried to significantly simplify the notion. The object oriented programming in depth when you read there is a lot more to it. Just trying to give you a very very crude overview. So we are saying that we have the ability to define a class of objects. For a class I can define properties through what we call data elements. For a class I can define the behavior through member functions which are also called methods sometimes. And once I define methods and the data elements for a class then those methods and data elements are available for every member of the class. And I can invoke these functions for any member at any point in time. So whenever we wish to invoke specific behavior we pass a message that we are essentially parameters to a function. We shall see some examples of a class called graphic objects class. So let us very quickly look at some aspects of graphics. We frequently use graphics for displaying information such as windows, rectangles, circles, lines, text strings, bitmap images. We in fact spend some time in analyzing what would be an histogram of an image and normalization of histogram and so on. We did not see how exactly we would plot an image on that paper. In my screen when I press some key you saw an image coming there, an image of the original photograph, an image of the modified photograph. How exactly is that photograph being shown there? So there are pixels we know that pixels but who draws those pixels? How are those pixels drawn? Suppose I want to draw those pixels myself. I want to draw one point here, one point here, one point here to draw a line. I want to draw a rectangle. I want to draw a circle. How do I do that? I can either do that by getting a function to draw one point with given color at a position and then do the rest of the hardware of writing an algorithm to draw a line, writing an algorithm to draw a circle, etc., etc. But instead of each one doing it, if someone has developed a library and I can use that library and that is why we say that in real life programming the less programming that you do, the better will be your program. Never reinvent the wheel. Use somebody else's work. The graphic library that we are going to discuss called EZ windows. This is an object-oriented library. It has several classes and we shall see how exactly the objects can be declared in those classes and how exactly we can do graphics. Now as I said, every such library has an API. This particular graphics library also has an API but to invoke that API, the library demands that you don't write your program as main. You write your program as API main. That is because the EZ windows actually sits between the operating system and you. So for curious reason, this particular functionality is to be invoke by saying API main and therefore the way I will write my program will change slightly in syntax. These are the classes available in EZ windows. There is a class called simple window. It permits us to define windows. Windows which will appear on the screen. These windows have simple properties. They have a text panel at the top, title. So I can give a text and that text will be written in that title. Then these windows are height and width. That's it. It also has. So these are the properties. That means if I describe that I need a window with title some cs101 let's say and I need it by 5 cm by 8 cm then this class has behavioral member functions which can permit me to open such a window then do some work on it display other objects etc and at the end close that window. So if I have declared W to be an object of this type look at the similarity between the declaration of ordinary variable types that you do int x float y similarly simple window W that will define an object W of the class simple window. The point is just as when you say int and float the moment you say int and float all the arithmetic operations etc etc are available to you in exactly the same way once I define W to be an object then all the operations which are available as member functions of the class are available to me also. Additionally I can give the initial values of the property parameter of this object the property first property parameter is the title or the title that will appear on top of that window it is given as a string. The next one is width and the next one is height so I say 8 cm wide 5 cm should be the height Incidentally all these values for these graphic objects are given in cm and the coordinate system is slightly okay the coordinate 0 0 is at the top left corner as I move to the right x is moving forward so larger x from 0 onwards but when y increases it comes down because that is exactly you will recall how our images are stored the first row of pixels second row of pixels third row of pixels so third row of pixels is conventionally y equal to minus 3 so that is why you have y increasing this way x increasing this way that is the coordinate system that you use once I say this I can say W dot open W dot open is a member function it will open that window it will display that window there then I can display other objects inside it and later on I can close that window we will look at one typical object a rectangle class the rectangle class is another object which can be drawn inside a window and this rectangle class has what attributes first of all the window in which it is to be drawn so it has to be connected to a window then the position in the window a color for the rectangle and the width and height but once I have defined this rectangle I have member functions which will automatically say say if I say rectangle class r if I say r dot draw it will draw that rectangle with this problem if I say r dot get color it will return the color value similarly get height get width you will notice that if somebody has written the code to implement this functionality your job is essentially to invoke these member functions and ensure that the appropriate values are set for the attributes which define individual objects I will just look at two examples very quickly in the handout that you will see on this Sunday and the link that you will see on the model in your lab on Monday you will find six sample programs like this sample 1, sample 2, sample 3, sample 4, etc install that eZ windows package it takes about 5 minutes to install it all ubuntu machines run this package and we have ensured that all old software lab machines run ubuntu now so it won't take much time if you have any problem your TS will help this is a complete program to draw a window I include IO stream, I using namespace STD include rect dot h, rect dot h so this is actually a header file for recta int api main one thing you have to be very careful about ordinarily in my examples I have been writing all names of functions in small case sometimes first later is big case that is capital but in all apis and the standard practice across different packages the first later and the first later of another word if it is part of that full name they are capital so api main is capital api, capital ai if you write small m it will say function not found over same thing here simple window so s capital w capital so like we saw I am defining a simple window the title I want to appear there is my first window I am defining a object called w like a variable of this type and the w has these attributes and I said w dot open when I say w dot open mind you o is capital it will actually draw that window in fact this window will look like this so actually a window will be drawn like this if you don't give any height and width it will assume some default height and width but if you give some height and width you can experiment with that remember if you had only the very basic functionality available namely drawing a particular point in a color at defined position it would have taken hello a lot of work to just do this it is not easy to write text my first window all of this is now made part of the life observe that in this program there is a statement here which says type control c to remove the display and exit then I say care any care and I say see in any care only when you give me that character I am saying w close why I have to do all this what will happen if I said w close here what will happen is even before I see the window it will disappear I want to see it and as long as I want to see it I want to keep it there but then if I keep it there it will not automatically vanish so I have to create this artificial interrupt or an event later on we shall see when we discuss more on the e-z windows how variety of events can be actually taken care of by event tracking mechanism so when I move my mouse and mouse comes to a particular the cursor comes to a particular point that's an event I can actually track that position and I can say if I have drawn this diagram here if the mouse comes here do the following so event-based action is possible in object oriented programming in an extremely simple fashion because events can be reacted to so this is one program and this the second one notice here I am using c-azert so azert library is included by saying c-azert I have simple window whose name is not w this time it is hello window hello window is the title that will appear in the diagram that I showed now that hello window will have this title and its size will be 10 by 10 and its position is 1,1 that means starting from the left corner of the screen 1 centimeter here 1 centimeter here will be the position of the top left corner of this window so now I am being very specific where I want that window of what size okay then I say hello window dot open I might have goofed up in giving these values so I want to sure that the window actually open note the azert the azert says hello window dot gate status now gate status is another property of the simple window class this gate status is able to tell you whether the window is open or not so I am azerting it is open if it is not if it is not window open this fellow will send a message and terminate automatically so I got my window now exactly instead of my first window it will say hello is there windows now I am doing something different I am finding the center of that window again there is a member function hello window dot gate center it will tell me the center point coordinates and that I am assigning to position center so position is another type position is another class I am defining just like int x I am saying position center so I am saying center equal to all of this I get that value and then I define an upper left and lower right corner in which I want to write some text that definition is center plus position this center plus position this notice what I am doing when I get that position earlier the center position I say minus 1 minus 1 and 1 1 that means I am defining left of the center and right of the center and I am defining some kind of a bounding box this bounding box is required to be defined whenever you want to write any text in that shape that you have any window if you want to write a text you have to define a bounding box of course this is artificial because even if your text extends beyond that bounding box the system does not create it will write the text however what is important is how easily the text is written you just say hello window dot render text so render text is another member function render text means whatever string I give you write it in that window where do you write it how do you write it well write it from the upper left and lower right which is the bounding box and what is the text I want it to write well namaste CS101 students and I want to write it in red color just this single call to member function called render text will write all this in that window and later on you can do the same thing if you want wait for a character input and close if you don't if you just say return 0 your program will terminate but the window will still remain on the screen you may of course delete that window from by other means and so on this is a rudimentary graphics library but this is very good to illustrate the power of looking at things from the point of view of classes and objects fundamentally there is no difference I would have done the same thing if I had written my functions and assume that these functions were part of this library so I was having these function libraries here this is the upper left and this is the lower right so upper left and lower right are something like x and y I am giving values to x and y which are not simple integer values but these are attributes these are coordinates so the upper left and lower right define an artificial rectangle within which the text is supposed to appear there is no physical rectangle that is drawn there is just position of the upper left corner of that artificial rectangle and lower right corner of that artificial rectangle so it is in fact if we were to see this here suppose this is my thing I want my text say let's say I just want to write namaste now I can write namaste here I can write namaste here I can write anywhere where I should write so I want I am imagining as if I have a rectangle like this physically such a rectangle does not exist but I estimate where that text will appear and I have to tell the system please write my text inside this estimated rectangle so I have to give the upper left corner of the rectangle and lower right corner of the rectangle what the graphic package does is it tries to put this text centered at the center of this box of course if the text is larger it may go on this side and this side but effectively I can imagine where I want to write and I can give this so that's the requirement of that function that is how the function has been written this whole text is inside that my first window yeah of course this whole text is inside that so all operations that you do is on the window so the hierarchy is like this first you open a window then inside the window you can either write text or you can draw rectangle you can draw circles whatever what in fact the remaining sample program which as I said I will try to describe them briefly on Tuesday lecture if I can connect my ubuntu machine otherwise you can test them on your machines alright thank you


Standards before ship building and centuries before Cole, culture and learning was at the heart of the country's identity. However, solar is not just a city with a great history. It's united with the great future too, with an array of exciting new developments just like this one, the renovation of the OR fire station this is a city with culture at its heart. The Heritage Lottery Fund, all the fire station received £2.5 million per annum tr fel Lottery to tell today massive building into a cultural hub. Give people the opportunity to take part in and experience workshops and classes in music, drama, art and creative writing. A number of projects here, one we'll see is a project called Live Tales, which is about literacy for key stage two children. And we're getting kids from all over Sunderland coming in here to improve their literacy through story writing. So Pickles is a good guy in your story. Is Pickles going to be good in your story? And on a wider scale, do you think it's really good for Sunderland as a city to get people creatively writing? We see children come into the room and arriving going, I don't really like writing. And then after a couple of hours worth of a session, creating a story, creating characters, leaving with a book of their work, they leave going, I love it. This is creativity. And this must be very dramatic because we've got three exclamation marks there, haven't you? So what is it about creative writing that you enjoy so much? It helps us think of different ideas. I think that we perhaps underestimated the demand for this sort of stuff in Sunderland. We've got hours and hours of dance classes here. The whole thing about art and culture is it builds confidence. It gives opportunity. I mean, for kids, often kids in Sunderland are a little bit shy and reserved. Suddenly being able to be more outward facing. It just really changes their whole outlook on life. I think it's a really important part of growing up and giving them the opportunity to do it in a place like this is just fantastic.