Tuesday, August 25, 2020

Foreign Affairs Essay Contest Example For Students

Remote Affairs Essay Contest With the start of an apparently interminable war on psychological warfare, and a flimsy United States economy, presently scarcely appears an opportunity to look at our general arrangement towards every single other country, and creating countries specifically. The destruction of the World Trade Center is as yet seething, and our soldiers are walking on Kabul as I compose. Patriotism is at a stature just recently experienced during the World Wars. Each and every other vehicle you see on the roadway has Old Glory gladly flying in their window or on their recieving wire, some privilege close to their Rebel Flag. On a superficial level it shows up the United States has arranged for one progressively noble purpose, and malicious, or those that contradict the US as they are generally called, will clearly fall. We wont represent guiltless assaults on regular citizens, and those doomed Afghanis and Osama container Laden would be wise to stow away. On the off chance that you dont accept this, not exclusively are you un-American, however you should be a damn fear based oppressor yourself. Discreetly, in any case, the contention is being made among researchers and free scholars in the United States that maybe we are not simply the honest casualties we depict to be in the September 11, 2001 pulverization of the World Trade Center. Some ground breaking minds even anticipated a disaster fairly like this, yet not on such an enormous scope. Unenlightened individuals inquire as to why something like this could or would happen. What might make such a poor and flimsy nation like Afghanistan chooses to confront the all-powerful United States? The appropriate response isn't a simple one, and requires a huge change in what we expect in outside relations, and how we see and treat the remainder of the world in general. The United States is one of the final super powers of the world, and we have the commitment to keep up and bolster great relations with the littler and more fragile cou ntries all through the world. We should exploit this relationship in a few unique manners, all without abusing the first people groups or our own capacity. First the U.S. must concentrate on contributing and exchanging with those countries who still can't seem to become financial forces. Second, we should actualize a reliable international strategy towards the Middle Eastern countries, and all underdeveloped countries by and large. Third, the United States needs to regard the endeavors and consequences of the democratization and strict restorations in the Middle East and Latin America, while playing a latent job in letting the a Western kind of majority rule government follow through to its logical end. Fourth, the U.S. must simplicity and make light of its contention with those civic establishments that despise the Western individuals and their lifestyle. Clearly, remote venture is essential for the eventual fate of creating different countries just as our own. There must be an acc entuation on remote venture and exchange, in any case the underdeveloped countries will keep on falling behind financially, innovatively, and locally, which could prompt a monetary destruction for the U.S. also. The inquiry at that point emerges regarding what the United States must do so as to have enormous exchange concurrences with different nations other than Japan and Mexico. All together for the U.S. to assume an increasingly dynamic job in the monetary and political advancement of a large number of these creating countries, it should initially acknowledge an unexpected way of thinking in comparison to its present one. To start with, it is basic for the United States to assume a comparable job in Latin America to the one Japan has played with a considerable lot of the creating countries in East Asia. The U.S. neighbors Latin America, and on the off chance that it needs to assume the job of elder sibling, it must acknowledge the obligation. Japan has contributed, exchanged, and been a guide for a significant number of its neighboring nations in East Asia, causing them to develop strategically and monetarily while likewise benefitting financially itself (Japan Remains 1996). The U.S. must understand that the economies of Latin American Nations will have a significant impact later on for our own economy, and that it must start to lead, contribute, and help Mexico, however nations, for example, Peru, Argentina, Bolivia, and Columbia into the twenty first century. The backbone in American international strategy has consistently been to advance and impart majority rule government. Be that as it may, so as to do this in a remote country, the U.S. must have the option to initially build up a reasonable monetary relationship and framework inside the ideal countries. We ought not expect or need a country to change from a complete tyrant government to a market economy; doing so would be a calamity. The United States lays a lot on its ideological convictions, when t here is no compelling reason to do as such. Outside nations look for our capital and exchange courses, not our ethics and culture. We, shockingly, don't feel this is the situation. The US has customarily required win big or bust, with respect to requests on forthcoming exchange accomplices, and political partners. The United States position towards Cuba is a prominent case of this way of thinking. Rather, the U.S. must be happy to permit creating to countries put resources into U.S. showcases before we put resources into theirs, paying little heed to philosophy. Consequently, a practical fare/import framework will be built up. Yet, it is basic that the economy of the creating country be observed and run by its own administration, and the United States should just be there for prompting purposes. At the point when a sensible framework has at last been accomplished, thennot right awaya increasingly American, free enterprise sort of financial system will be permitted to develop. On the off chance that the best test the United States faces is executing an international strategy that is predictable all through the Middle East, weve never really shoot ourselves in he foot up until this point. Islamic countries arent prone to be receptive to thoughts, for example, human rights, and majority rule government. These countries will never be receptive to western thoughts when the United States keeps on exacting authorizations against them. The U.S. is fortunate that it has a partner in Saudi Arabia and Israel, permitting them to actualize a considerable lot of these international strategy plans against the other Middle Eastern nations, without confronting genuine financial outcomes in the oil and gas industry. Strangely however, Saudi Arabia is most likely as much against western philosophies as any country in the Middle East. Ladies don't have equivalent rights, torment is visit, there is no division among chapel and state, and Saudi Arabia is amazingly a long way from b uilding up any kind of popular government (Miller 58). Presently, when the U.S. advances majority rules system and human rights, for what reason does it bolster one nation and censure the following? All through the Cold War, American international strategy would offer guide to any country who contradicts socialism. So during that time the U.S. built up a youre either with us or against us kind of strategy, non-arrangement. With this strategy, a significant number of the Middle Eastern nations turned out to be alleged foes with the U.S., which has prompted agitation and contempt of western majority rules systems. In this season of worldwide financial matters, the United States can't single out which nations to put resources into. All together for the U.S. to vanquish the difficulties it faces in the Middle East, it must beginning by supporting the whole Middle East. Israel and Saudi Arabia might be the most appealing offers, however Syria and even Iran have tremendous assets that wil l be truly significant to our economy in the future.Of course we can't disregard our dear companions off the shore of Miami, Cuba. What edge does a nation like China hold over Cuba other than size? Nothing other than a bigger wellspring of modest work. Our present position on Cuba was right in 1962. Castro was to be sure a socialist, however simply after the US, who he went to first, wouldn't support him. In 2001, in any case, it appears to be evident that Castro has metamorphisized into something different. Castro has done a practically complete 180 in his political way of thinking, and some would contend that Cuba is just about a popular government as of now. In the event that we lifted our inadequate embargoes and opened the exchange lines Cuba, I see no motivation behind why Castro would not open his general public significantly more. Americans are passing up an opportunity to change Cuba, both monetarily and strategically. We get the opportunity to reconstruct a whole economy f rom the beginning, and we should simply put resources into it. These open doors are not theoretical either, however genuine as evident to different nations like Canada and the Europeans. Every other person on the planet knows this as of now since they have made the essential mentality alterations and are in there focusing in and getting their hands filthy. Castro realizes that he cannot carry out this responsibility of changing his whole structure himself, and it won't be long until he discovers somebody to assist that with willing in all likelihood not be good for the US. It occurred before when the US denied him and he went to the USSR, there is no motivation behind why we should let it happen once more. As the alleged pioneer of the free world we should know better. All the US does is lecture about the significance of dependability and free market frameworks, and the requirement for vote based system. With a model like we are setting, for what reason would it be a good idea for a nyone to follow? For what reason would it be a good idea for us to make every effort to guarantee neither gets by in Cuba? Its time and has been for quite a while to bite the bullet and concede we weren't right. The remainder of the free world definitely knows it. They sit in their Cuban financed workplaces, smoking huge Cuban stogies snickering at our pomposity and us. (Smith)Next, the United States must react to the issues of democratization and strict restoration in the Middle East and Latin America. In the Middle East, there is by all accounts the idea that endeavors at democratization would prompt the destruction of minority rights. As Judith Miller called attention to, The advancement of free races promptly is probably going to prompt the triumph of Islamic gatherings that have no responsibility to popular government in any conspicuous or important structure (Miller 59). What the United States must do is set up an illustrative or parliamentary procedure that perceives all type s of political activity. Just advancing free decisions would prompt a reaction in democratization endeavors. Th

Saturday, August 22, 2020

Savior In Gnosticism And Orthodoxy Essay Example For Students

Deliverer In Gnosticism And Orthodoxy Essay I am endeavoring to keep in touch with one sound article talking about inquiries three and two. I propose to initially portray the restricting perspectives on the deliverer in Gnosticismand in Orthodoxy. Besides, I will think about the Valentinian and exemplary Gnosticsin how they contrast and how the Gospel of Truth represents the highlights ofValentinian Gnosticism. The Orthodox view the congregation as an essential mediumbetween the common people and god; they contended that without the congregation and the hierarchyof pastorate, the gathering would not have the option to achieve god all alone. Theysaw the happening to divine beings realm as a strict occasion. They additionally observed itpreposterous thought to isolate the body from human life. That is, they sawJesus as both fragile living creature and soul that were indistinguishable. The Orthodox consideredthe torturous killing of Jesus as a verifiable record. They saw Jesus as a martyrthat yielded his life so we may live. It was accepted that the martyrdomof Jesus takes into consideration the pardoning of sins and guaran tees revival and ourlife everlasting; this penance permitted us to discharge our blame and receiveforgiveness for our wrongdoings. On the matter of what Jesus was, the Gnosticsvehemently couldn't help contradicting the Orthodox Church. Gnostics accepted that Jesus wasmore than a human saint; Gnostics accepted that the Holy Spirit (Christ) andJesus of Nazareth were two separate elements. They felt that Jesus was a man offlesh who, at immersion, got the Holy Spirit and became Christ. They lookedat it just as the soul of Christ was involving the group of Jesus until thecrucifixion, where the soul was transfigured and discharged so we mayattain salvation. Gnostics and the Orthodox Church additionally contended over the point ofthe enduring, or the enthusiasm of Jesus. Gnostics felt that Christ just appearedto endure and pass on, it was the body that endured and when Jesus passed, thespirit was transfigured and discharged. Gnostics and the Orthodox likewise disagreedon the purpose of the presence of God. The Gnostics justified that the god ofthe old confirmation a divine force of creation and discipline was unmistakably a different entityfrom the lord of Jesus, who was an adoring and pardoning god. How could such aloving god connect with us with salvation and pardoning be a similar god whocreated agony, discipline and languishing. The Orthodox trusted in one god,the father all-powerful maker of paradise and earth. Actually this was themajor guarantee of the belief that the conventional Christians broadcasted as part oftheir confidence. Another purpose of contention was the way to achieve salvation. OrthodoxChristians felt it was important to announce, so anyone can hear, their confidence in one god. This was the observing element that permitted them to isolate themselves from theGnostics-who were currently viewed as apostates and a danger to the congregation. Gnosticsbelieved that up to one lived in confidence and held great lead throughouttheir whole life they would accomplish salvation. Gnostics felt their methodology wassuperior to that of the Orthodox Christians on the grounds that even scoundrels couldproclaim the belief, not have confidence in it and still arrive at life unceasing andsalvation. After Jesus kicked the bucket, both Orthodox Christians and Gnostics guaranteed towitness the restoration of Christ. The customary guaranteed that they saw thephysical return of Jesus Christ and communicated the significance of this typeof locating as reality. Gnostics had the conviction that the relationship betweensalvation and themselves was on an increasingly close to home level. Gnostics demanded that itwas just an experience between the observer and the soul of Christ that had been changed. This follows the Gnostics conviction that strict enlightenmentcame from introspect and self-information. When one had accomplished this gnosis theywere viewed as of develop information and an individual from a world class bunch readyto get the mystery information on the soul. Gnostics accepted that theybelonged to the genuine church of a choose rare sorts of people who were commendable; theorthodox Christians would not be spared on the grounds that they were oblivious in regards to reality. Ignatus took the possibility of the dad, child and the Holy Spirit to anextreme. He felt that this equivalent progression was spoken to on earth by theprocession of minister, cleric and elder. Furthermore, just by loving the religious administrator as astand-in for god would they be spared. The Orthodox Church was resolute about theimportance of the pastorate as the medium to god. The Valentinians were a branch ofGnosticism that frequently were not perceived as blasphemers. They rode a fine linebetween the standard and the Gnostics. The Valentinians were unique in relation to therest of the Gnostics since they, similar to the Orthodox Church, broadcasted beliefin one god. The standard accepted that once the Valentinians were in seclusionthat they considered a contention between the well known picture of godas the wellspring of all being. The Orthodox Church was soon increasingly undermined by theValentinians on the grounds that they were apostates whos lessons were practically identi cal to thatof the Orthodox in what they said-yet what they implied was irreverent. TheValentinians resembled the great Gnostics since they couldn't help contradicting theOrthodox Church on the matter of the significance of pastorate in the issue ofattaining a relationship with god. The two of them saw the conversation of god as anoverlying issue to the subject of otherworldly position. They expressed that theOrthodox Church was increasingly worried about the issues of who had more force thanfocusing on the genuine issues. The Orthodox focused on the significance of therelationship between the progression of ministry and the association with the father,son and the Holy Spirit. Forebearing, of the Orthodox Church announced that any personwho defied the intensity of the religious administrator was ungodly and ought to be censured todeath. The Gnostics communicated the significance of fairness in the love. Theyargued that by considering each other as equivalents, there would be lessconc entration on the battle for force and more spotlight on accomplishing information andsalvation. The Gnostics took an extreme situation for the time and it stillemanates today-the situation of ladies in the congregation. The Gnostics permitted womento take an interest in all parts of the love; actually, any one whenever wasallowed to take on the situation of religious administrator. Along these lines, there was no contentions overwho held more force. The Orthodox Church thought this was all out and completeblasphemy. They felt that ladies had no spot in the authority of the congregation. Hazard Taking EssayIgnatus took the possibility of the dad, child and the Holy Spirit to anextreme. He felt that this equivalent chain of command was spoken to on earth by theprocession of minister, cleric and elder. Furthermore, just by revering the diocesan as astand-in for god would they be spared. The Orthodox Church was resolved about theimportance of the pastorate as the medium to god. The Valentinians were a branch ofGnosticism that frequently were not perceived as blasphemers. They rode a fine linebetween the conventional and the Gnostics. The Valentinians were not the same as therest of the Gnostics since they, similar to the Orthodox Church, declared beliefin one god. The customary accepted that once the Valentinians were in seclusionthat they considered a contention between the famous picture of godas the wellspring of all being. The Orthodox Church was soon progressively undermined by theValentinians in light of the fact that they were apostates whos lessons were practica lly identical to thatof the Orthodox in what they said-however what they implied was profane. TheValentinians resembled the great Gnostics since they couldn't help contradicting theOrthodox Church on the matter of the significance of ministry in the issue ofattaining a relationship with god. The two of them saw the conversation of god as anoverlying issue to the topic of profound power. They expressed that theOrthodox Church was progressively worried about the issues of who had more force thanfocusing on the genuine issues. The Orthodox focused on the significance of therelationship between the progression of ministry and the association with the father,son and the Holy Spirit. Forgiving, of the Orthodox Church announced that any personwho defied the intensity of the cleric was ungodly and ought to be denounced todeath. The Gnostics communicated the significance of equity in the love. Theyargued that by considering each other as equivalents, there would be lessconcentration on the b attle for force and more spotlight on accomplishing information andsalvation. The Gnostics took an extreme situation for the time and it stillemanates today-the situation of ladies in the congregation. The Gnostics permitted womento take an interest in all parts of the love; truth be told, any one whenever wasallowed to take on the situation of cleric. Along these lines, there was no contentions overwho held more force. The Orthodox Church thought this was all out and completeblasphemy. They felt that ladies had no spot in the initiative of the congregation. Some portion of the explanation that Gnostics communicated their faith in uniformity was becauseof the way that they saw the connection among Jesus and his devotees. They didn't consider Jesus to be a better than the witnesses. Or maybe, they saw Jesus notas a prophet with the entirety of the appropriate responses, however as a detachment of the data thatshould be sed as an asset and a bouncing off point on their quest for gnosis. The Gospel of Truth is a Christian Gnostic book connected to the Valentinin School. It is an impression of the life and work of Jesus. It mirrors the significanceof Jesus and his works. This work is model of the premise of the ValentinianGnostic development. This content communicated the Valentinian rule that theknowledge of god wrecks numbness. It illuminates the legendary record of thefall of Sophia and considers it the depiction of mistake. This content talks ofJesus fill in as a revealer and an educator. It communicates the point about thesignificance of his demise and restoration of his soul and its association toour salvation. It deciphers the occasion of Jesus demise as a disclosure of theessence of the Father and the Origins of mankind inside him. Through thisinsight, the forces are overc

Sunday, August 2, 2020

Designing a Calculator with FSM Logic

Designing a Calculator with FSM Logic My friend Robert V. 20 is a Course 6-3 (Computer Science) sophomore, the MIT African Students Associations webmaster, and has TAd an interesting IAP class called 6.148, a web development class and competition. Hes a really smart guy, and I found out about this cool post he put up on Medium and asked if I could reformat it and post it to the blogs. Robert is passionate about web design and development, and is also really great at teaching. Hes always the first person that many of our Course 6 freshman friends reach out to for help in their introductory courses. Robert lives in Maseeh Hall, was born in Goma and grew up in Kinshasa in the Democratic Republic of the Congo. I hope you enjoy his post as much as I did!   As far as I can tell, making a calculator is a classic first time programmer’s challenge. So, as I was helping some of my fellow underclassmen learn web dev, I suggested making a calculator! For best practice purposes, I also suggested starting off with brainstorming: First, we design how this calculator is going to work, Then, we can implement code for this, And finally, we can make it pretty As we were brainstorming, we naturally through that a coherent design logic for our calculator would be a finite state machine (FSM)! WAIT. What’s a Finite State Machine (FSM)? NOTE: If you’re familiar with FSMs, you can skip this section entirely. An FSM is a mathematical objects made of states, state transitions, and inputs. FSMs are widely used in computer science and engineering to model the behaviors of machines. At any given time, an FSM has one state and can receive inputs. Based on those inputs, the FSM can change both state (through state transitions) and interval variables of the FSM. HERE’S AN EXAMPLE: The state machine of the human body. A very simplified human body has 2 states: hungry and full. When humans are hungry, they need food in order to get back to being in the full state, and at the same time, they may become happy  when they get food. Becoming happy in this case would be an internal variable of the state machine, and eating would be an input. Then, humans use all their energy (the other input) which makes them hungry again. They could become SAD too. So, inputs essentially lead to state change in a state machine. Here’s what this simple human body state machine would look like when graphically represented: Ok, let me show you another example! You’re about to see an FSM that you’re very familiar with but that was just never called an FSM: the state of matter. Right, isn’t that cool? We learn this in high school, but they never call it that way. Anyway, this state machine has 4 states: PLASMA, GAS, SOLID, LIQUID. There are transitions from states to states, which are inputs that are either caused by nature or by humans. Internal states of this state machines could be, for example, the boiling temperature of the given matter, the name of the given matter, etc. Why Are (Finite) State Machines Important? They provide us with a very systematic way of modelling anything that can happen in real life (such as state of matter). Based on state machines, we can easily use mathematics to derive both properties of those machines. State machines are widely used in probabilistic applications, such as modelling the motion of a robot looking for a reward located somewhere the robot does not know using Markov Random Process (which is also a subset of state machines). State machines also allow to naturally and easily expand our model (both through the design and through code). For example, in the human body, we could add another state, not full / not hungry, where the human person could be feeling meh. To add that, we simple create a new state and add some transitions to it. Of course, there are times when other models are better, but state machines work best for certain kinds of applications. Finally, if you’re more interested, here’s an article on embeddedrelated.com by Jason Sacks that goes over a lot more details that I did. If you find this interesting, you will love that article. Back to Calculators Later on, we decided to use the iPhone’s calculator to identify all the possible states in our calculator state machine simply by playing around doing multiple arithmetic computations. And… It quickly turned out to be much more complicated than I thought. Here’s some thought to not using a state machine: Designing a calculator without thinking about all the state machine’s logic is very simple. It works well for most operations, and noticing the imperfections in it can be subtle. However, there are operations that simply do not work well, such as 2 + 4 * 2, which in reality is 2 + (4 * 2) = 10 and can be erroneously evaluated as (2 + 4) * 2 = 12. Another way to design a calculator is one where the user can input expressions, such as 3 * 4, which can be easily evaluated with functions like eval. Not that I am not suggesting using eval (it’s know to be a bad practice); it’s just a quick solution that could help quickly get down to implementing all the UI for the calculator. However, nicely designing a calculator with a correct finite state machine is not that easy. Nevertheless, I decided to pursue this interesting challenge, and this is what I came up with: That looks quite complicated. Let me explain. Note: if you’d like to skip to the end, I posted JavaScript gist code snippet that implements this. The main idea behind a simple calculator is that we receive inputs, and based on those inputs, we make some operations, and if needed, we change the output display on the screen. Inputs may be: numbers (one of 0,1,2,3,4,5,6,7,8,9,.. note that I included the . as a “number”), operations (one of +,-,*,/), equality (i.e. =), or reset (could be C or AC on iPhone. One of them is clear which is same as clear entry and the other is clear all). Then, we can denote the inputs as follows: Operations are OP  for +,-,*,/, OPS for +,-, and OPC for *,/. C for complex, S for simple. Equality is just =. Input numbers may be one of fk, sk, or tk. The k actually stands for the new input’s index for numbers such that a number is a sequence of digit characters f0,f1,f2,,fk-1, and the input makes the number become f0,f1,,fk. For example, in 123, f0=1, f1=2, f2=3 and k-1=2. The input f3=4 will change that number into 1234. The reset button is RES. This is like pressing AC or C on your iPhone’s calculator. Next, I designed the underlying structure of the calculator as blocks of the form: |---|-----|---|-----|---| | F | OP1 | S | OP2 | T | |---|-----|---|-----|---| F stands for “first” as in “first number” OP1 is the first operation S is stands for “second” as in “second number” OP2 is the second operation, and finally T stands for “trailing” as in “trailing number”. By now, you can probably imagine that we’d be doing operations against the first and second number and against the second number against the trailing number, but how are the operations actually made, what do each of those blocks actually mean, and where does the result get stored? Let me explain all of it! The State Logic What we need is to identify all the possible states for this FSM. This is the difficult part. I learned here that this type of calculators try to make the most logical assumption while respecting the rules of mathematics, and it can be beautifully describes with only 7 states! Before diving into these 7 states, first, here’s what the state parameters in a state represent: F - the value of the first number OP1 - the operation between the first and second number S - the value of the second number OP2 - the operation between the second number and trailing number T - the value of the trailing number D - what is displayed on the screen; it can be one of F, S, and T The inputs that I listed above are what will lead to various state transitions. Now, onto the states: STATE 1: INITIAL State So, the initial state looks like: F: 0 OP1: + S: 0 OP2: + T: 0 D: F This is the state we start off with. There’s nothing interesting, and the values that we start with are just zeros and + operations. Pressing RES will take us back to the initial state: it essentially has no effect. YES, self loops are allowed in FSMs. Pressing any number, denoted by fk (which must be equal to f0 for this input coming from the INITIAL state) will take us to the TRANSITION FROM INITIAL state. I will talk about that state next. The number is denoted with lowercase f because it will be filled into the first number F. Note that adding numbers into other blocks will then have to either be sk or tk for block S and block T respectively. Finally, pressing any operation OP will take us to the TRANSITION state. Note that this will change OP1 to become OP, whatever OP may be among +,-,*,/. This state is upcoming as well. STATE 2: TRANSITION FROM INITIAL Let me point out that my naming convention here is a bit weird, but I tried my best to give these states meaningful names. Without further ado, this state looks like this: F: f0...fk-1 OP1: ~OP1 S: ~S OP2: ~OP2 T: ~T D: F Some things to note: I use the ~ notation to denote that the value of this key is whatever the given state key was before (not that it could be that the state key does not match state key, e.g.: S: ~F). Some later states will cause these values to change and not be + or 0 as in the initial state. So, anyway: Pressing RES will take us to TRANSITION FROM INITIAL state (i.e. back to here) if F is not equal to 0. It will clear F (i.e. set it to 0). Pressing RES will take us back to INITIAL state if F = 0. This means all parameters become what they used to be. i.e. F=0, OP1=+, S=0, D=F, OP2=+, T=0. I will show why this is important at the end. Pressing any number fk will take us back to this same state, TRANSITION FROM INITIAL and simply append fk to f0fk-1. Pressing the = sign will take us to the EQUAL state. Through this, it will make the evaluation (F) OP1 (S) and place the result in the F block when it reaches the equal state. Finally, pressing any operation OP will take us to the TRANSITION state. Note that this will change OP1 to become OP, whatever OP may be among +,-,*,/. This will also duplicate F into S. STATE 3: TRANSITION If you go back to the visual, you will notice that this state is the most frequented state (i.e. has the most arrows coming into it). EQUAL is the second most frequented. Anyway, this state looks like: F: ~F OP1: OP S: ~F OP2: ~OP2 T: ~T D: F Note that to reach this state, one must press an operation OP; that is the value that OP1 takes! There’s also something funny that happens here: the value of F gets duplicated into S. This is an optimization that was made by the iPhone. It’s a design decision that did not have to happen but works very well. Let’s say you press 3 then *. Then, what happens if you press = ? Do you get a zero because you didn’t type the second number? With this design decision, you’d get a 9 because we assume that you meant 3 * 3. I think it’s cool that they thought of this! Then, pressing any OP leads us back to this state. It simply changes the operation to the new one. Pressing = evaluates (F) OP1 (S) and places the result in F. Then, it takes us to the EQUAL state. Note that when it takes us to the equal state, both OP and S and every other parameters of the state remain unchanged. This is also cool. Do you see why? Maybe it’ll be more obvious once we get into the EQUAL state. Pressing RES takes us back to TRANSITION FROM INITIAL. On the way to it, it removes all the values in F and replaces it with 0. All the other parameters remain unchanged. Finally, pressing another number sk takes us to the TRANSITION FROM TRANSITION state. As you can imagine, this changes the value of S. Note that as coming from TRANSITION, sk = s0 (the very first index of the second number regardless of what S currently is, it will overwrite it). STATE 4: TRANSITION FROM TRANSITION (That naming though… Sigh) This state is interesting. It looks like this: F: ~F OP1: ~OP1 S: s0...sk-1 OP2: ~OP2 T: ~T D: S You can probably note that the display has now changed from F to S. Now, we’re displaying the second number! Pressing sk takes us back to this same state, it just appends sk to S so that it now becomes s0sk. Pressing = takes us to the EQUAL state. Again, it will evaluate (F) OP1 (S) and place the result in F and also keep all other parameters unchanged. Pressing RES takes us back to TRANSITION FROM TRANSITION if S is not equal to 0. This will clear S and replaces it with 0. Pressing RES when S = 0 will take us back to INITIAL. This means that everything will get back to what it started off with. Finally, pressing OP is the interesting case. There is actually two possible cases here: If we press OPS, we evaluate the expression (F) OP1 (S) and place its result on F. It will also place that same result on S as well. This is because we’re doing a simple + or operation, so we can just evaluate the pression. OP1 will become OPS, whatever it may be. Then, it will take us back to the TRANSITION state. If we press OPC and OP1 = OPC, then we do the same as when we press OPS except it’s OPC. of course. Finally, if we press OPC, we will be taken to the TRAILING state if OP1 is OPS (i.e. if OP1 is one of + or ). In this state, OP2 becomes OPC (i.e. one of * or /) and OP1 is always an OPS. S remains what it was, which is s0sk-1, but T will now get the value of S. The display D and S remain unchanged. STATE 5: TRAILING Why do we have a trailing state? Imagine the expression 9+5*2, should it evaluate to 14*2=28 or should it evaluate to 9+10=19? If you care about Mathematics, you know that multiplication takes precedence. That is why we have both the TRAILING state and the TRANSITION FROM TRAILING state! Note that in this state, OP1 is always OPS and  OP2 is always OPC. The TRAILING state looks like: F: ~F OP1: ~OP1=OPC S: ~S OP2: OPC T: ~S D: S Pressing = takes us to the EQUAL state. The evaluation is different however. First, we evaluate (S) OP2 (T), place the result into S (note that we make this evaluation before moving to the equal state), then we evaluate (F) OP1 (S), which places the result into F (note that we make this evaluation after moving into the equal state). So, now, F is essentially (F) OP1 ((S) OP2 (T)). All other expressions remain unchanged. Pressing RES will take us to the TRANSITION FROM TRAILING state. This will immediately set T = 0 and all parameters will remain unchanged. The display will become T. Someone pressing tk = t0 is essentially equivalent to pressing RES from the TRAILING state. Pressing OPC leads us back to the TRAILING state and simply change the OPC on OP2. Pressing OPS will run the same evaluation done with pressing =, i.e. it will place (F) OP1 ((S) OP2 (T)) into F but also on place it on S. OP1 will be OPS, whatever it may be, and the display will be F. Other keys will remain unchanged. Finally, pressing tk will take us to the TRANSITION FROM TRAILING state. In this case (i.e. coming from TRAILING), tk = t0. The display also changes to D=T . STATE 6: TRANSITION FROM TRAILING This state looks like: F: ~F OP1: ~OPS S: ~S OP2: ~OPC T: t0...tk-1 D: T Pressing RES if T = 0 will take us back to INITIAL state. Everything will be cleared. However, if T is not equal to 0, pressing RES will just clear T (i.e. set it to 0) and remain in this state. Pressing tk will just append tk into the current value of T. Pressing = will evaluate the expression just as evaluated when pressing = during the TRAILING state, and it will take us to the EQUAL state. Pressing OPC will take us to the TRAILING state. This will evaluate (S) OP2 (T) and place the result in both S and T. Then, it will change OP2 to be the new input OPC . The display will change back to S. Pressing OPS will take us to the TRANSITION state. This will evaluate the expression similar to how it’s evaluated in the TRAILING state. STATE 7: EQUAL Whew! Finally, the EQUAL state. This state looks like: F: (F) OP1 (S) OP1: ~OP1 S: ~S OP2: ~OP2 T: ~T D: F Note that the display in the equal state is always F. Pressing = re-evaluates (F) OP1 (S) and places the result into F. Note that S will remain the same in this case. Pressing OP will take us to the TRANSITION state. Then, it will make a copy of F and place it into S. Then, OP1 will be the newly received operation. Pressing fk will take us to the TRANSITION FROM INITIAL state. In this case, fk = f0. Everything else will remain unchanged. Pressing RES will also take us back to the TRANSITION FROM INITIAL state. However, it will delete F and replace it with 0. The Calculator (an example!) Parting Notes This is the calculator shown in the video above. It’s a really nice state machine that works well for these simple operations, and the design is great because it can be easily expanded to more complicated operations such as sin or floor. I wanted to point out that I didn’t really talk about how we are appending to the numbers. In case fk (or equivalently sk and tk ) is . , we only append when there is no . in the number. For example, pressing . when F=243 will make F=243. . However, pressing . when F=23.5 will have no effects! Also, pressing any number other than 0 when F=0 needs to change F into that number (equivalently for S and T). This is definitely not crazy difficult, but I’d say it’s more complicated that it looks, and it’s been a rewarding exercise to actually design this calculator. Here’s code that I wrote that does this in JavaScript (which is meant to be used for a calculator website) Or, check it out on Github. Thanks for reading! Post Tagged #6.148