Placeholder Image

字幕列表 影片播放

  • >> DAVID J MALAN: All right, so this is CS50.

    >> 大衛·馬蘭:所有 沒錯,所以這是CS50。

  • And this is clearly a Friday.

    而這顯然是一個星期五。

  • And this is the end of week one.

    而這是一個星期的末端。

  • So you may recall that we left off, last time, with a cliffhanger of sorts.

    所以,你可能還記得,我們​​不放過, 最後一次,有各種各樣的懸念。

  • Whereby we expose this lie, that no matter what you've been taught growing

    我們藉以揭露這個謊言,沒有 不管你被教導成長

  • up, 1 divided by 10 is not, in fact, 0.1 or 0.100 or 0.10000.

    向上,1除以10不是在 事實上,0.1或0.100或0.10000。

  • In fact, if we compile this program, as we did yesterday, with,

    事實上,如果我們編譯這個 計劃,因為我們沒有昨天,有,

  • make imprecision, and then do dot, slash, imprecision,

    使不精確性,然後 做點,斜線,不精確,

  • we learned that this is what's 1 divided by 10 actually is.

    我們了解到,這是什麼 1除以10實際上是。

  • So that's not really quite the case.

    所以這不是真的相當的情況下。

  • But this does hint at some fundamental limitation of computers.

    但是,這確實暗示了一些 電腦的基本限制。

  • And indeed, among the things we're going to do

    事實上,中 我們將要做的事情

  • today is take a look at why this has happened, what implications this has,

    今天就來看看為什麼這有 事情發生了,有什麼意義這有,

  • how humanity has failed to grasp this in some very

    人類如何失敗 掌握這一些很

  • serious situations-- the result of the which

    嚴重situations-- 在其結果

  • has been quite tragic and expensive-- and also

    已經相當慘烈 和expensive--也

  • take a look at how we can actually defend

    看看我們如何 實際上可以捍衛

  • against these kinds of limitations.

    針對這些種類的限制。

  • So intuitively, perhaps, why is 1 divided by 10,

    所以直覺,也許, 為什麼是1除以10,

  • according to my computer here, not just 1/10, 0.10?

    根據我的電腦 這裡,不只是的1/10,0.10?

  • Yeah.

    是啊。

  • What do you think?

    你怎麼看?

  • >> AUDIENCE MEMBER: The radix is different?

    >> 觀眾:基數是不同的?

  • >> DAVID J MALAN: The what is?

    >> 大衛·馬蘭:該是什麼?

  • Oh, the radix is different?

    呵呵,基數是不同的?

  • So not quite.

    因此,不完全是。

  • It's actually more fundamental to the hardware.

    它實際上更多 基本的硬件。

  • Other thoughts?

    其他的想法?

  • Yeah.

    是啊。

  • AUDIENCE MEMBER: They represent numbers differently?

    觀眾:他們 表示數字不同?

  • DAVID J MALAN: So they-- Right.

    大衛·馬蘭:所以they--權。

  • They represent numbers differently.

    他們代表的數字不同。

  • Inaccurately, apparently.

    不準確,很明顯。

  • So that is-- Well, differently from what?

    這樣is--好, 不同於什麼?

  • Or from whom?

    或者從誰?

  • From us?

    從我們呢?

  • AUDIENCE MEMBER: Yeah.

    觀眾:是啊。

  • They don't use the decimal system to [INAUDIBLE].

    它們不使用小數 系統[聽不清]。

  • DAVID J MALAN: OK.

    大衛·馬蘭:OK。

  • So in a sense, they don't use the decimal system.

    因此,從某種意義上說,他們不 使用十進制系統。

  • Underneath the hood, everything is, indeed, binary,

    在系統底層, 一切,的確,二進制,

  • and that's related, in fact.

    這就是相關的,其實。

  • But it's even a simpler explanation than that.

    但是,它甚至更簡單 解釋比。

  • Yeah.

    是啊。

  • >> AUDIENCE MEMBER: They only have so many bits.

    >> 觀眾:他們 只有這麼多的位。

  • They can only store up to a certain extent, like with the decimals.

    他們最多只能存儲一定 某種程度上,像小數。

  • >> DAVID J MALAN: Yeah.

    >> 大衛·馬蘭:是的。

  • This is what's really getting at it.

    這是什麼真正得到它。

  • It turns out that computers typically, will always only

    事實證明,計算機 通常情況下,將永遠只有

  • use a finite amount of information to represent something.

    使用的信息的有限數量 代表什麼。

  • Right?

    對嗎?

  • After all, we only have a fixed amount of hard disk space.

    畢竟,我們只有一個固定的 量的硬盤空間。

  • We only have a fixed amount of RAM, or computer memory.

    我們只有一個固定量 的RAM,或計算機的內存。

  • And if you only have a fixed amount of something,

    如果你只有一個 固定金額的東西,

  • surely you can't actually count up to infinity or any number you want.

    當然你不能真正計數 到無窮大或任何你想要的數字。

  • You, kind of, have to pick and choose what range

    你有種,有 挑選什麼範圍

  • of values you're going to support.

    值你要支持。

  • >> And so for instance, a week or two ago, when we talked about ASCII,

    >> 因此,例如,一兩個星期 以前,當我們談到ASCII,

  • and we talked about 8 bits, or a byte, so to speak,

    我們談了8位, 或字節,可以這麼說,

  • the biggest number we could represent with 8 bits was what?

    最大數我們可以 有8位表示是什麼呢?

  • 255.

    255。

  • And we can represent 256 total values but not if we spend one of them

    我們可以表示256個總價值 但如果我們把其中的一個

  • on 0-- Well, but if we spend one of them on 0,

    在0--好了,但如果我們 花其中的一個0,

  • then the biggest number is, of course, 255.

    那麼最大的數 是,當然,255。

  • >> So it turns out, that this is the case too, in this context.

    >> 所以,事實證明,這是 的情況下也一樣,在這種情況下。

  • We started talking, last time, about floating-point numbers, which

    我們開始談,最後一次, 有關浮點數字,

  • are different from integers, in that they have a decimal point

    來自整數不同,在 他們有一個小數點

  • and, hopefully, some numbers after that, but they are too.

    並希望一些數字 在這之後,但是它們太。

  • A computer is only typically going to use 32 bits, maybe 64 bits

    一台計算機通常只打算 使用32位,也許64位

  • to represent a floating point value.

    來表示一個浮點值。

  • So even though we've grown up learning mathematics and knowing

    因此,即使我們已經長大了 學習數學和了解

  • that you can absolutely have an infinite number of numbers

    你絕對可以有 數的無限數量

  • after the decimal point, not if you have finite memory.

    小數點後不 如果你有有限的內存。

  • You, kind of, have to round, or pick and choose which

    你有種,有圓形, 或者挑選哪些

  • numbers you're going to represent.

    你會數來表示。

  • And so you can think of, in a sense, this being the computer's closest

    所以,你能想到的,從某種意義上說, 這是計算機的最接近

  • approximation to the value 1/10 that it can get, with just 32 or so bits.

    近似​​的值的1/10 它可以得到,只有32左右位。

  • And it's not just 1/10.

    而且它不只是1/10。

  • >> For instance, if I change this to 1/3, which we think is even simpler.

    >> 舉例來說,如果我改變這 1/3,我們認為這是更簡單。

  • So 1 divided by 3.

    因此,1除以3。

  • Let me save the file.

    讓我保存文件。

  • Let me go ahead and recompile it.

    讓我繼續前進,重新編譯它。

  • And let me re-run it.

    讓我重新運行它。

  • Here too, apparently, 1/3 is not 0.3 and then an infinite number of 3's

    在這裡,顯然,三分之一沒有0.3 然後3的無限數量

  • thereafter.

    其後。

  • You have this imprecision at the end.

    你有這樣的不精確性在最後。

  • So we humans are correct, and what you learned is, in fact, correct,

    所以,我們人類是正確的,什麼 你了解,其實,正確的,

  • but we're bumping up against some limitations.

    但是我們撞了 針對一些限制。

  • >> And what I thought we'd do today, is begin

    >> 而我的想法 我們今天會做,是開始

  • by looking at, frankly, the tragic consequences of this

    通過看,坦率地說,在 這種悲慘的後果

  • sometimes, when mankind does not quite implement

    有時,人類的時候 並不完全實現

  • for this reality and these limitations.

    針對這一現實,這些限制。

  • And we'll see a series of vignettes from the History Channel that takes

    而且我們會看到一系列的小插圖 從歷史頻道的需要

  • a look at how things have gone wrong.

    一起來看看如何事情已經出了問題。

  • It's about 8 minutes long, and we'll come back after this

    這是約8分鐘之久, 我們將在這之後回來

  • and take a look at exactly what else can go wrong.

    看一看在完全相同 還有什麼可能出錯。

  • If we could dim the lights--

    如果我們能昏暗的lights--

  • >> [VIDEO PLAYBACK]

    >> [視頻回放]

  • >> -Computers, we've all come to accept the often frustrating problems that

    >> -Computers,我們都逐漸接受 經常令人沮喪的問題,

  • go with them.

    和他們一起去。

  • Bugs, viruses, and software glitches are small prices

    錯誤,病毒,和軟件 故障都是小的價格

  • to pay for the convenience.

    支付的便利。

  • But in high-tech and high-speed military and space program applications,

    但是,在高科技和高速 軍事和航天計劃的應用,

  • the smallest problem can be magnified into disaster.

    可以最小的問題 被放大成災難。

  • On June 4, 1996, scientists prepared to launch an unmanned Ariane 5 rocket.

    1996年6月4日,科學家準備 啟動一個無人阿麗亞娜5型火箭。

  • It was carrying scientific satellites designed

    它攜帶的科學 衛星設計

  • to establish precisely how the Earth's magnetic field interacts

    建立精確如何 地球的磁場相互作用

  • with solar winds.

    與太陽風。

  • The rocket was built for the European Space Agency

    火箭是專為 歐洲航天局

  • and lifted off from its facility on the coast of French Guiana.

    並從其工廠升空 在法屬圭亞那的海岸。

  • >> -And about 30 seconds into the flight, they first

    >> - 和大約30秒後進入 飛行中,他們首先

  • noticed something was going wrong.

    發現了一些打算錯了。

  • That the nozzles were swiveling in a way they really shouldn't.

    使噴嘴被旋轉 在某種程度上,他們真的不應該。

  • Around 40 seconds into the flight, clearly the vehicle was in trouble,

    約40秒後進入飛行, 明確了車輛遇到了麻煩,

  • and that's when they made the decision to destroy it.

    而當他們提出的 決定摧毀它。

  • A Range Safety Officer with tremendous guts pressed the button,

    隨著一系列安全主任 巨大的勇氣按下按鈕,

  • blew up the rocket before it could become a hazard to public safety.

    炸毀了火箭之前,它可能 成為危害公眾安全。

  • >> -This was the maiden voyage of the Ariane 5,

    >> - 這是處女 阿麗亞娜5的航程,

  • and its destruction took place because of a flaw

    它破壞了 地方,因為一個缺陷

  • embedded in the rocket's software.

    嵌在火箭的軟件。

  • -The problem on the Ariane was that there

    在-The問題 阿麗亞娜是,有

  • was a number that required 64 bits to express,

    是一個數字,需要 64位表示,

  • and he wanted to convert it to a 16 bit number.

    他想轉換 它以一個16位的數。

  • They assumed that the number was never going to be very big,

    他們假定數 從來沒有將是非常大的,

  • that most of those digits in the 64 bit number were 0's.

    大多數的這些數字中 64位數字是0。

  • They were wrong.

    但他們錯了。

  • >> -The inability of one software program to accept

    >> 一-The無力 軟件程序接受

  • the kind of number generated by another was at the root of the failure.

    所產生的那種數 另一種是在失敗的根源。

  • Software development had become a very costly part of new technology.

    軟件開發已經成為一個 的新技術非常昂貴的部分。

  • The Ariane 4 rocket had been very successful, so much of the software

    阿麗亞娜-4火箭一直非常 成功的,那麼多的軟件

  • created for it was also used on the Ariane 5.

    創造這也是 用在阿麗亞娜5。

  • >> -The basic problem was that the Ariane 5 was faster, accelerated faster.

    >> -The基本的問題是,阿麗亞娜 5增快,加速快。

  • And the software hadn't accounted for that.

    而且軟件早已不是 佔了這一點。

  • >> -The destruction of the rocket was a huge financial disaster,

    >> 火箭-The破壞 是一個巨大的金融災難,

  • all due to a minute software error.

    全因一分鐘,軟件錯誤。

  • But this wasn't the first time data conversion problems

    但是,這是不是第一次 實時數據轉換問題

  • had plagued modern rocket technology.

    一直困擾現代火箭技術。

  • >> -In 1991, with the start of the First Gulf War,

    >> -in 1991,在開始 第一次海灣戰爭中,

  • the Patriot missile experienced a similar kind

    愛國者導彈 經歷了類似的一種

  • of number conversion problem.

    數轉換的問題。

  • As a result, 28 people, 28 American soldiers

    其結果是,28人, 28美國士兵

  • were killed and about 100 others wounded,

    被打死,約 100人受傷,

  • when the Patriot, which was supposed to protect against incoming scuds,

    當愛國者,這是應該 以防止傳入的飛毛腿導彈,

  • failed to fire a missile.

    沒有發射導彈。

  • >> -When Iraq invaded Kuwait and America launched Desert Storm in early 1991,

    >> - 當伊拉克入侵科威特和美國 在1991年年初推出沙漠風暴,

  • Patriot missile batteries were deployed to protect Saudi Arabia and Israel

    愛國者導彈部署 保護沙特阿拉伯和以色列

  • from Iraqi Scud missile attacks.

    從伊拉克飛毛腿導彈攻擊。

  • The Patriot is a US, medium-range surface-to-air system

    愛國者是美國,中程 表面對空氣系統

  • manufactured by the Raytheon company.

    由雷神公司製造。

  • >> -The size of the Patriot interceptor, itself, is about, roughly 20 feet long.

    >> 愛國者攔截-The大小, 本身就是約,約20英尺長。

  • And it weighs about 2000 pounds.

    而且它的重量約2000磅。

  • And it carries a warhead of about-- I think it's roughly 150 pounds.

    同時還可以進行about--的彈頭 我認為這是約150磅。

  • And the warhead, itself, is a high explosive,

    和彈頭本身, 是一種高爆炸藥,

  • which has fragments around it.

    它有它周圍的碎片。

  • The casing of the warhead is designed to act like buckshot.

    彈頭的外殼是 設計像鹿彈。

  • >> -The missiles are carried, 4 per container,

    >> -The導彈 進行,4%的集裝箱,

  • and are transported by a semi-trailer.

    並通過半拖車被運送。

  • >> -The Patriot anti missile system goes back at least 20 years now.

    >> -The愛國者反導彈系統 追溯到現在至少需要20年。

  • It was originally designed as an air defense missile

    它最初的設計 作為防空導彈

  • to shoot down enemy airplanes.

    擊落敵人的飛機。

  • In the First Gulf War, when that war came along,

    在第一次海灣戰爭, 當戰爭來了,

  • the Army wanted to use it to shoot down scuds, not airplanes.

    陸軍希望用它來 擊落飛毛腿導彈,而不是飛機。

  • The Iraqi Force was not so much of a problem,

    伊拉克隊還是沒有 這麼多的問題,

  • but the Army was worried about scuds.

    但陸軍擔心飛毛腿導彈。