精华内容
下载资源
问答
  • 什么是闭包

    千次阅读 2014-06-10 10:59:19
    ----本文摘自programming in lua 当一个函数内部嵌套另一个函数定义时,内部的函数体可以访问外部... 下面看一个简单的例子,假定有一个学生姓名的列表和一个学生名和成绩对应的表,现在想根据学生的成绩从高到低对学生

            ----本文摘自programming in  lua

    如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure)

    当一个函数内部嵌套另一个函数定义时,内部的函数体可以访问外部的函数的局部变量,这种特征我们称作词法定界。虽然这看起来很清楚,事实并非如此,词法定界加上第一类函数在编程语言里是一个功能强大的概念,很少语言提供这种支持。 

          下面看一个简单的例子,假定有一个学生姓名的列表和一个学生名和成绩对应的表,现在想根据学生的成绩从高到低对学生进行排序,可以这样做: 
    names = {"Peter", "Paul", "Mary"} 
    grades = {Mary = 10, Paul = 7, Peter = 8} 
    table.sort(names, function (n1, n2) 
      return grades[n1] > grades[n2]    -- compare the grades 
    end) 

    假定创建一个函数实现此功能: 
    function sortbygrade (names, grades) 
      table.sort(names, function (n1, n2) 
        return grades[n1] > grades[n2]    -- compare the grades 
      end) 
    end 

    例子中包含在 sortbygrade 函数内部的 sort 中的匿名函数可以访问 sortbygrade 的参数grades,在匿名函数内部 grades 不是全局变量也不是局部变量,我们称作外部的局部变量(external local variable)或者 upvalue。(upvalue 意思有些误导,然而在 Lua 中他的存在有历史的根源,还有他比起 external local variable 简短)。 


    看下面的代码: 

    function newCounter() 
      local i = 0 
      return function()     -- anonymous function 
        i = i + 1 
        return i 
      end 
    end 

    c1 = newCounter() 
    print(c1())  --> 1 
    print(c1())  --> 2 


    匿名函数使用 upvalue i 保存他的计数,当我们调用匿名函数的时候 i 已经超出了作用范围,因为创建 i 的函数 newCounter 已经返回了。然而 Lua 用闭包的思想正确处理了这种情况。简单的说闭包是一个函数加上它可以正确访问的 upvalues。如果我们再次调用 newCounter,将创建一个新的局部变量 i,因此我们得到了一个作用在新的变量 i 上的新闭包。 

    c2 = newCounter() 
    print(c2())  --> 1 
    print(c1())  --> 3 
    print(c2())  --> 2 

    c1、c2 是建立在同一个函数上,但作用在同一个局部变量的不同实例上的两个不同的闭包。 技术上来讲,闭包指值而不是指函数,函数仅仅是闭包的一个原型声明;尽管如此,在不会导致混淆的情况下我们继续使用术语函数代指闭包。 闭包在上下文环境中提供很有用的功能,如前面我们见到的可以作为高级函数(sort)的参数;作为函数嵌套的函数(newCounter)。这一机制使得我们可以在 Lua 的函数世界里组合出奇幻的编程技术。闭包也可用在回调函数中,比如在 GUI 环境中你需要创建一系列 button,但用户按下 button 时回调函数被调用,可能不同的按钮被按下时需要处理的任务有点区别。具体来讲,一个十进制计算器需要 10 个相似的按钮,每个按钮对应一个数字,可以使用下面的函数创建他们: 

    function digitButton (digit) 
      return Button{  label = digit, 
          action = function () 
            add_to_display(digit) 
          end 
      } 
    end 


    这个例子中我们假定 Button 是一个用来创建新按钮的工具,  label 是按钮的标签,action 是按钮被按下时调用的回调函数。(实际上是一个闭包,因为他访问 upvalue digit)。digitButton 完成任务返回后,局部变量 digit 超出范围,回调函数仍然可以被调用并且可以访问局部变量 digit。 闭包在完全不同的上下文中也是很有用途的。因为函数被存储在普通的变量内我们可以很方便的重定义或者预定义函数。通常当你需要原始函数有一个新的实现时可以重定义函数。例如你可以重定义 sin 使其接受一个度数而不是弧度作为参数: 
    oldSin = math.sin 
    math.sin = function (x) 
      return oldSin(x*math.pi/180) 
    end 


    更清楚的方式: 

    do 
      local oldSin = math.sin 
      local k = math.pi/180 
      math.sin = function (x) 
        return oldSin(x*k) 
      end 
    end 


    这样我们把原始版本放在一个局部变量内,访问 sin 的唯一方式是通过新版本的函数。 利用同样的特征我们可以创建一个安全的环境(也称作沙箱,和 java 里的沙箱一样),当我们运行一段不信任的代码(比如我们运行网络服务器上获取的代码)时安全的环境是需要的,比如我们可以使用闭包重定义 io 库的 open 函数来限制程序打开的文件。 
    do 
      local oldOpen = io.open 
      io.open = function (filename, mode) 
        if access_OK(filename, mode) then 
          return oldOpen(filename, mode) 
        else 
          return nil, "access denied" 
        end 
      end 
    end 

    展开全文
  • 超实数(Hyper-reals)是什么人发明的?在英语里面,形容“Hyper”有高度紧张的含义。所谓“Hyperrealss”意思是超级紧密的实数系,是一种比实数更加紧密的理想数系。从中学时代起,学生都知道:几何直线(数轴)...

    超实数(Hyper-reals)是什么人发明的?

    在英语里面,形容词“Hyper”有高度紧张的含义。所谓“Hyperrealss”意思是超级紧密的实数系,是一种比实数更加紧密的理想数系。

    从中学时代起,学生都知道:几何直线(数轴)上布满了所谓“实数”,点与实数是一一对应的,没有任何空隙。

    实际情况是,几何直线的数学结构远远不是这么简单,它可以承载更加紧密的数系。何故?拿出证据来。

    实际情况是,年仅28岁的美国数学家Edwin Hewitt (1920 - 1999)1948年最早构造出这种超实数,震惊了数学界。

    1961年,A.Robinson在超实数基础上确立了无穷小微积分。1976年,追随Robinson的无穷小思想,J.Keisler出版了名著《基础微积分》(无穷小方法)。

     但是,国内菲氏微积分的徒子徒孙,闭起眼睛,不看历史发展,整天在课堂上唠叨极限论微积分。

    袁萌   107

    附:基础微积分的EPILOGUE(后记)

    How does theinfinitesimal calculus as developed in this book relate to the traditional (orε, δ ) calculus? To get the proper perspective we shall sketch the history ofthe calculus. 

    Many problemsinvolving slopes, areas and volumes, which we would today call calculusproblems, were solved by the ancient Greek mathematicians. The greatest of themwas Archimedes( 287-212 B.C.) . Archimedes anticipated both the infinitesimaland the ε, δ approach to calculus. He sometimes discovered his results byreasoning with infinitesimals, but always published his proofs using the“method of exhaustion,” which is similar to the ε, δ approach.

    Calculus problemsbecame important in the early 1600’s with the development of physics andastronomy. The basic rules for differentiation and integration were discoveredin that period by informal reasoning with infinitesimals. Kepler, Galileo,Fermat, and Barrow were among the contributors.

    In the 1660’s and1670’s Sir Isaac Newton and Gottfried Wilhelm Leibniz independently “invented”the calculus. They took the major step of recognizing the importance of acollection of isolated results and organizing them into a whole.

    Newton, atdifferent times, described the derivative of γ (which he called the “fluxion”of γ) in three different ways, roughly

    (1) The ratio ofan infinitesimal change in y to an infinitesimal change in x ( Theinfinitesimal method.)

     

    (2) The limit ofthe ratio of the change in y to the change in x, Δy/Δx, as Δx approaches zero.(The limit method.)

    (3) The velocityof y where x denotes time. (The velocity method.)

    In his laterwritings Newton sought to avoid infinitesimals and emphasized the methods (2)and (3).

    Leibniz ratherconsistently favored the infinitesimal method but believed (correctly) that thesame results could be obtained using only real numbers. He regarded theinfinitesimals as “ideal” numbers like the imaginary numbers. To justify themhe proposed his law of continuity: “In any supposed transition, ending in anyterminus, it is permissible to institute a general reasoning, in which theterminus may also be included.” This “law” is far too imprecise by presentstandards. But it was a remarkable forerunner of the Transfer Principle onwhich modern infinitesimal calculus is based. Leibniz was on the right track,but 300 years too soon!

    The notationdeveloped by Leibniz is still in general use today, even though it was meant tosuggest the infinitesimal method: dy /dx for the derivative (to suggest aninfinitesimal change in y divided by an

    infinitesimal change in x ), and baƒ(x )dx for theintegral (to suggest the sum of infinitely many infinitesimal quantities ƒ(x ) dx ).

    All threeapproaches had serious inconsistencies which were criticized most effectivelyby Bishop Berkeley in 1734. However, a precise treatment of the calculus was beyondthe state of the art at the time, and the three intuitive descriptions(1)-(3)of the derivative competed with each other for the next two hundred years.Until sometime after 1820, the infinitesimal method (1) of Leibniz was dominanton the European continent, because of its intuitive appeal and the convenienceof the Leibniz notation. In England the velocity method (3) predominated; italso has intuitive appeal but cannot be made rigorous.

    In 1821 A. L.Cauchy published a forerunner of the modern treatment of the calculus based onthe limit method (2). He defined the integral as well as the derivative interms of limits, namely

     

    baƒ(χ)dχ=lim Σƒ(χ)Δχ

     

    He still usedinfinitesimals, regarding them as variables which approach zero. From that timeon, the limit method gradually became the dominant approach to calculus, whileinfinitesimals and appeals to velocity survived only as a manner of speaking.There were two important points which still had to be cleared up in Cauchy’swork, however. First, Cauchy’s definition of limit was not sufficiently clear;it still relied on the intuitive use of infinitesimals. Second, a precisedefinition of the real number system was not yet available. Such a definitionrequired a better understanding of the concepts of set and function which werethen evolving.

    A completelyrigorous treatment of the calculus was finally formulated by Karl Weierstrassin the 1870’s. He introduced the ε, δ condition as the definition of limit. Atabout the same time a number of mathematicians, including Weierstrass,succeeded in constructing the real number system from the positive integers.The problem of constructing the real number system also led to development ofset theory by Georg Cantor in the 1870’s. Weierstrass’ approach has become thetraditional or “standard” treatment of calculus as it is usually presentedtoday. It begins with the ε, δ condition as the definition of limit and goes onto develop the calculus entirely in terms of the real number system(with nomention of infinitesimals). However, even when calculus is presented in thestandard way, it is customary to argue informally in terms of infinitesimals,and to use the Leibniz notation which suggests infinitesimals.

    From the time ofWeierstrass until very recently, it appeared that the limit method(2) hadfinally won out and the history of elementary calculus was closed. But in 1934,Thoralf Skolem constructed what we here call the hyperintegers and proved thatthe analogue of the Transfer Principle holds for them. Skolem’s construction(now called the ultraproduct construction) was later extended to a wide classof structures, including the construction of the hyperreal numbers from thereal numbers.

    'See Kline,p.385. Boyer, p. 217.

    The name“hyperreal” was first used by E. Hewitt in a paper in 1948. The hyperrealnumbers were known for over a decade before they were applied to the calculus.

    Finally in 1961Abraham Robinson discovered that the hyperreal numbers could be used to give arigorous treatment of the calculus with infinitesimals. The presentation of thecalculus which was given in this book is based on Robinson’s treatment (butmodified to make it suitable for a first course).

    Robinson’scalculus is in the spirit of Leibniz’ old method of infinitesimals. There aremajor differences in detail. For instance, Leibniz defined the derivative asthe ratio Δy/Δx where Δx is infinitesimal, while Robinson defines thederivative as the standard part of the ratio Δy/Δx where Δx is infinitesimal.This is how Robinson avoids the inconsistencies in the old infinitesimalapproach. Also, Leibniz’ vague law of continuity is replaced by the preciselyformulated Transfer Principle.

    The reasonRobinson’s work was not done sooner is that the Transfer Principle for the hyperrealnumbers is a type of axiom that was not familiar in mathematics until recently.It arose in the subject of model theory, which studies the relationship betweenaxioms and mathematical structures. The pioneering developments in model theorywere not made until the 1930’s, by GÖdel, Malcev, Skolem, and Tarski; and thesubject hardly existed until the 1950’s.

    Looking back wesee that the method of infinitesimals was generally preferred over the methodof limits for over 150 years after Newton and Leibniz invented the calculus,because infinitesimals have greater intuitive appeal. But the method of limitswas finally adopted around 1870 because it was the first mathematically precisetreatment of the calculus. Now it is also possible to use infinitesimals in amathematically precise way. Infinitesimals in Robinson’s sense have beenapplied not only to the calculus but to the much broader subject of analysis.They have led to new results and problems in mathematical research. SinceSkolem’s infinite hyperintegers are usually called nonstandard integers.Robinson called the new subject “nonstandard analysis.” (he called the realnumbers “standard” and the other hyperreal numbers “nonstandard.” This is theorigin of the name “standard part.”)

    The startingpoint for this course was a pair of intuitive pictures of the real andhyperreal number systems. These intuitive pictures are really only roughsketches that are not completely trustworthy. In order to be sure that theresults are correct, the calculus must be based on mathematically precisedescriptions of these number systems, which fill in the gaps in the intuitivepictures. There are two ways to do this. The quickest way is to list themathematical properties of the real and hyperreal numbers. These properties areto be accepted as basic and are called axioms. The second way of mathematicallydescribing the real and hyperreal numbers is to start with the positiveintegers and, step by step, construct the integers, the rational numbers, the realnumbers, and the hyperreal numbers. This second method is better because itshows that there really is a structure with the desired properties. At the endof this epilogue we shall briefly outline the construction of the real andhyperreal numbers and give some examples of infinitesimals.

    We now turn tothe first way of mathematically describing the real and hyperreal numbers. Weshall list two groups of axioms in the epilogue, one for the real numbers andone for the hyperreal numbers. The axioms for the hyperreal numbers will justbe more careful statements of the Extension Principle and Transfer Principle ofChapter 1. The axioms for the real numbers come in three sets: the AlgebraicAxioms, the Order Axioms, and the Completeness Axiom. All the familiar factsabout the real numbers can be proved using only these axioms.

    1.ALGEBRAICAXIOMS FOR THE REAL NUMBERS

       A    Closure laws 0 and 1 are realnumbers. If a and b are real numbers, then so are a + b, ab and -a. If a is areal number and a 0, then 1/a is a realnumber.

     

    B    Commutative laws     a+b =b+a  ab = ba

    C    Associative laws     a+(b+c) = (a+b) +c     a(bc) = (ab) c.

    D    Identity laws        0+a =a               1· a = a .

    E    Inverse laws         a +(-a)=0     if a 0,     a. 1                                                     

    F    Distributivelaw        a·(b + c) = ab + ac

     

    DEFINITION

             The positive integers are the real numbers 1,2 = 1+1, 3 = 1+1+1 ,

              4= 1+1+1+1, and so on.

    .  ORDER AXIOMS FORREAL NUMBERS

    A    0<1.

    B    Transitive law  if a< b and b< c.

    C    Trichotomy law Exactly one of the relations a

    D    Sum law  If a< b , then a+c < b+c.

    E    product law  If a < bc.

    F    Root axiom   For every real number a>0 and every positive integer n, there is a real number b>0 such that _____=a

     

    .  COMPLETENESS  AXIOM

     

        Let A be a set of real numbers such that wheneverx and y are in A, any real number between x and y is in A. Then A is aninterval.

     

    THEOREM     

    An increasing sequence <</font>___ > either converges ordiverges to .

     

    PROOF  let T be the set of all real number x such that x ____ for some n.T is obviously nonempty.

     

    Case 1  T is the whole real line. If H is infinite we have x ____ for all realnumbers x. So __ is positive infinite and <</font>__ > diverges to

    .

    Case 2   T is not the whole real line. By the CompletenessAxiom, T is an interval (-∞, b] or (-∞, b). For eachreal x < b, we have

     

     

     

         for some n. It follows that for infiniteH, __ b and __b. Therefore<</font>__> converges to b.

     

    We now take up the second group of axioms, which give the properties ofthe hyperreal numbers. There will be two axioms, called the Extension Axiom andthe Transfer Axiom, which correspond to the Extension Principle and TransferPrinciple of Section 1.5. We first state the Extension Axiom.

     

    1*. EXTENSION AXIOM

              (a ) Theset R of real numbers is a subset of the set R* of hyperreal numbers.

              (b) Thereis given a relation <* on R*, such that the order relation < on R is asubset of <*, <* is transitive (a <*b and b <* c implies a<* c),and <* satisfies the Trichotomy Law: for all a ,b in R*, exactly one ofa<* b, a = b, b<* a holds.

     

    (c) There is a hyperreal number ε such that 0<* ε and ε< * r foreach positive real number r.

    (d) For each real function f, there is given a hyperreal function f*with the same number of variables, called the natural extension of f.

     

    Part (c ) of the Extension Axiom states that there is at least onepositive infinitesimal. Part (d) gives us the natural extension for each real function.The Transfer Axiom will say that this natural extension has the same propertiesas the original function.

     

    Recall that the Transfer Principle of Section 1.5 made use of theintuitive idea of a real statement. Before we can state the Transfer Axiom, wemust give an exact mathematical explanation of the notion of a real statement.This will be done in several steps, first introducing the concepts of a realexpression and a formula.

     

    We begin with the concept of a real expression, or term, built up fromvariables and real constants using real functions. Real expressions can bebuilt up as follows:

    (1) A real constant standing alone is a real expression.

    A variable standing alone is a real expression.

     If e is a real expression, and f is a real function of onevariable, then f(e) is a real expression. Similarly, if ____________ are realexpressions, and g is a real function of n variables, then g(_________) is areal expression.

     

    Step(3) can be used repeatedly to build up longer expressions. Here aresome examples of real expressions, where x and y are variables:

     

     

     

     

    By a formula, we mean a statement of one of the following kinds, whered and e are real expressions:

    (1)An equation between two real expressions, d = e.

    (2)An inequality between two real expressions, d< e, de, d> e, de, or de.

     

    3A statement ofthe form e is defined or e is undefined.

     

    Here are some examples of formulas:

     

                        x + y= 5,

     

                     f (x)=  1x²

                              1+x²

                     g (x,y ) <</i> f (t),

                     f (x, x) is undefined.

     

    If each variable in a formula is replaced by a real number, the formulawill be either true or false. Ordinarily, a formula will be true for somevalues of the variables and false for others. For example, the formula x + y =5will be true when (x, y)=(4,1) and false when (x,y) =(7, 2).

     

    DEFINITION

     

    A real statement is either a nonempty finite set of formulas T or acombination involving two nonempty finite sets of formulas S and T that statesthat “whenever every formula in S is true, every formula in T is true.”

     

    We shall give several comments and examples to help make thisdefinition clear. Sometimes, instead of writing “whenever every formula in S istrue, every formula in Tis true” we use the shorter form “if S then T” for areal statements.Each of the Algebraic Axioms for the Real Numbers is a realstatement. The commutative laws, associative laws, identity laws, anddistributive laws are real statements.

    For example, the commutative laws are the pair of formulas

     

                                a+ b = b+a,     ab=ba,

    Which involve the two variables a and b. The closure laws may beexpressed as four real statements:

                                   a +b is defined,

                                  abis defined,

                                   -ais defined,

                                    If a0, then 1/ais defined.

     

    The inverse laws consist of two more real statements. The TrichotomyLaw is part of the Extension Axiom, and all of the other Order Axioms for theReal Numbers are real statements. However, the Completeness Axioms is not areal statement, because it is not built up from equations and inequalitiesbetween terms.

     

    A typical example of a real statement is the inequality for exponentsdiscussed in Section 8.1:

     

                     if a 0, and q 1, then(a+1)q aq+1

     

    This statement is true for all real numbers aand q.

     

    A formula can be given a meaning in the hyperreal number system as wellas in the real number system. Consider a formula with the two variables xand y.When x and yare replaced by particular real numbers, the formula in thehyperreal number system. To give the formula a meaning in the hyperreal numbersystem, we replace each real function by its natural extension and replace thereal order relation < by the hyperreal relation<*. When x and yarereplaced by hyperreal numbers, each real function fis replaced by its naturalextension f *, and the real order relation <</span>is replacedby<*, the formula will be either true or false in the hypereal numbersystem.

     

    For example, the formula x + y=5 is true in the hyperreal number systemwhen(x,y)=(2-ε, 3 + ε),

     

    but false when (x,y ) = (2+ε, 3+ε) , if εis nonzero.

     

    We are now ready to state the Transfer Axiom.

     

    * .  TRANSFER AXIOM

     

    Every real statement that holds for all real numbers holds for allhyperreal numbers.

     

    It is possible to develop the whole calculus course as presented inthis book from these axioms for the real and hyperreal numbers. By the TransferAxiom, all the Algebraic Axioms for the Real Numbers also hold true for thehyperreal numbers. In other words, we can transfer every Algebraic Axiom forthe real numbers to the hyperreal numbers. We can also transfer every OrderAxiom for the real numbers to the hyperreal numbers. The Trichotomy Law is partof the Extension Axiom. Each of the other Order Axioms is a real statement andthus carries over to the hyperreal numbers by the Transfer Axiom. Thus we canmake computations with the hyperreal numbers in the same way as we do for thereal numbers.

     

    There is one fact of basic importance that we state now as a theorem.

     

    THEOREM  (Standard  Part  Principle)

     

     For every finite hyperreal number b, there is exactly one realnumber r that is infinitely close to b.

     

    PROOF We first show that there cannot be more than one real numberinfinitely close to b.Suppose r and sare real numbers such that  r band s b. Then r s, and sincer  and s are real, r must be equal to s . Thus there is at most one realnumber infinitely close to b.

     

    We now show that there is a real number infinitely close to b. Let Abethe set of all real numbers less than b. Then any real number between twoelements of Ais an element of A. By the Completeness Axiom for the realnumbers, Ais an interval. Since the hyperreal number bis finite. Amust be aninterval of the form(-∝, r ) or (-∝, r ]for somereal number r. Every real number s belongs to A,so s < b. Also, every realnumber  t > r  does not belong to A, so t b. This showsthat ris infinitely close to b.

    It was pointedout earlier that the Completeness Axiom does not qualify as a real statement.For this reason, the Transfer Principle cannot be used to transfer theCompleteness Axiom to the hyperreal numbers. In fact, the Completeness Axiom isnot true for the hyperreal numbers. By a closed hyperreal interval, we mean aset of hyperreal numbers of the form [a, b], the set of all hyperreal numbersxfor which a x b, where aandbare hyperreal constants. Open and half-open hyperreal intervals are defined ina similar way. When we say that the Completeness Axiom is not true for thehyperreal numbers, we mean that there actually are sets A of hyperreal numberssuch that:

    (a) whenever xandyare in A, any hyperreal number between xand yis in A.

    (b) A is not ahyperreal interval.

    Here are twoquitefamiliar examples.

    EXAMPLE1 The setAof all infinitesimals has property (a ) above but is not a hyperreal interval.It has property (a ) because any hyperreal number that is between twoinfinitesimals is itself infinitesimal. We show that Ais not a hyperrealinterval. Acannot be of the form [a, ] or (a,) because everyinfinitesimal is less than 1. Acannot be of the form [a, b] or (a, b], becauseif bis positive infinitesimal, then 2·b is a largerinfinitesimal. Acannot be of the form [a,b) or (a,b), because if bis positive andnot infinitesimal, then b/2 is less than b but still positive and notinfinitesimal.

    The set B of allfinite hyperreal numbers is another example of a set that has property (a )above but is not an interval.

    Here are someexamples that may help to illustrate the nature of the hyperreal number systemand the use of the Transfer Axiom.

     

    EXAMPLE2 let f bethe real function given by the equation.

    Its graph is theunit semicircle with center at the origin. The following two real statementshold for all real numbers x:

    By the TransferAxiom, these real statements also hold for all hyperreal numbers x. Thereforethe natural extension  f* of f  is given by the same equation

    The domain off*is the set of all hyperreal numbers between 1 and 1. Thehyperreal graph of f*, shown in Figure E.1, can be drawn on paper by drawingthe real graph of f(x)and training an infinitesimal microscope on certain keypoints.

    EXAMPLE3 let fbethe identity function on the real numbers, f(x)=x. By the Transfer Axiom, theequation f(x)= x is true for all hyperreal x. Thus the natural extension f*offis defined, and f*(x )=x for all hyperreal x. Figure E.2 shows the hyperrealgraph of f*. Under a microscope, it has a 45°slope.

    Here is anexample of a hyperreal function that is not the natural extension of a realfunction.

     

     

     

     

     

     

    Figure E.1

     

     

     

    Figure E.2

     

     

     

    EXAMPLE4 One hyperreal function, which we have already studied in somedetail, is the standard part function st(x). For real numbers the standard partfunction has the same values as the identity function,

     

    st(x) = x for all real x.

    However, thehyperreal graph of st(x), shown in Figure E.3, is very different from thehyperreal graph of the identity function f*. The domain of the standard partfunction is the set of all finite numbers, while f* has domain R*. Thus forinfinite x, f*(x) = x, but st(x)is undefined. If xis finite but not real, f*(x)=x but st(x) x. Under the microscope, aninfinitesimal piece of the graph of the standard part function is horizontal,while the identity function has a 45° slope.

    The standard partfunction is not the natural extension of the identity function, and hence isnot the natural extension of any real function.

     

     

     

     

     

     

    Figure E.3

    The standard partfunction is the only hyperreal function used in this course except for naturalextensions of real functions.

    We conclude witha few words about the construction of the real and the hyperreal numbers.Before Weierstrass, the rational numbers were on solid ground but the realnumberswere something new. Before one could safely use the axioms for the realnumbers, it had to be shown that the axioms did not lead to a contradiction.This was done by starting with the rational numbers and constructing astructure which satisfied all the axioms for the real numbers. Since anythingproved from the axioms is true in this structure, the axioms cannot lead to acontradiction.

    The idea is toconstruct real numbers out of Cauchy sequences of rational numbers.

    DEFINITION

    A Cauchy Sequence is a sequence <</i>________> of numberssuch that for every real ε > 0 there is an integer ____ such that thenumbers

     

     

     

     

    are all within ε of each other.

     

    Two Cauchy sequences

     

     

     

    of rational numbers are called Cauchy equivalent, in symbols<</span>_____> =<</span>____>, if the differencesequence

     

     

     

    converges to zero. (Intuitively this means that the two sequences havethe same limit.)

     

    PROPERTIES OF CAUCHY EQUIVALENCE

     

    (1)If <</span>_______> =<</span>______> and< ______> = <</span>_______>

     then the sum sequences are equivalent.

     

     

    (2)Under the same hypotheses, the product sequences are equivalent,

     

     

    (3)if__ = __ for all but finitely many n, then

       

     

     

     

    The set of real numbers is then defined as the set of all equivalenceclasses of Cauchy sequences of rational numbers. A rational number rcorresponds to the equivalence class of the constant sequence < r, r,r,…>. The sum of the equivalence class of <</span>___ > and theequivalence class of < ___ > is defined as the equivalence class of thesum sequence

     

     

     

    The product is defined in a similar way. It can be shown that all theaxioms for the real numbers hold for this structure.

     

    Today the real numbers are on solid ground and the hyperreal numbersare a new idea. Robinson used the ultraproduct construction of Skolem to showthat the axioms for the hyperreal numbers (for example, as used in this book)do not lead to a contradiction. The method is much like the construction of thereal numbers from the rationals. But this time the real number system is thestarting point. We construct hyperrealnumbers out of arbitrary (not justCauchy) sequences of real numbers.

     

    By an ultraproduct equivalence we mean an equivalence relation= on theset of all sequences of real numbers which have the properties of Cauchyequivalence (1)-(3) and also

     

    (4)If each __belongs to the set {0,1} the <</span>__> isequivalent to exactly one of the constant sequences <0,0,0,…> or<1,1,1,…>.

     

    Given an ultraproduct equivalence relation, the set of hyperrealnumbers is defined as the set of all equivalence classes of sequences of realnumbers. A real number rcorresponds to the equivalence class of the constant sequence<</span>r, r,r…>. Sums and products are defined as for Cauchysequences. The natural extension f*of a real function f(x)is defined so thatthe image of the equivalence class of <</span>__> is theequivalence class of <</span>___>. It can be proved thatultraproduct equivalence relations exist, and that all the axioms for the realand hyperreal numbers hold for the structure defined in this way.

     

    When hyperreal numbers are constructed as equivalence classes ofsequences of real numbers, we can give specific examples of infinite hyperrealnumbers. The equivalence class of

                             <1,2,3,……n,……>

    is a positive infinite hyperreal number. The equivalence class of

                             <1,4,9……n²……>

    is larger, and the equivalence class of

                             <1,2,4……__……>

    is a still larger infinite hyperreal number.

    We can also give examples of nonzero infinitesimals. The equivalenceclasses of

                        <1, 1/2, 1/3……1/n, ……>,

                        <1,1/4,1/9……n–², ……>,

    and                 <1,1/2,1/4……___________, ……>,

    are progressively smaller positive infinitesimals.

     

    The mistake of Leibniz and his contemporaries was to identify all theinfinitesimals with zero. This leads to an immediate contradiction becausedy/dxbecomes 0/0. In the present treatment the equivalence classes of

                                

                             <1, 1/2, 1/3, ……, 1/n, ……>

    and      <0, 0, ……0, ……>

    are different hyperreal numbers. They are not equal but merely have thesame standard part, zero. This avoids the contradiction and once again makesinfinitesimals a mathematically sound method.

     

    For more information about the ideas touched on in this epilogue, seethe instructor’s supplement, Foundations of Infinitesimal Calculus,which has aself-contained treatment of ultraproducts and the hyperreal numbers.

     

    FOR FURTHER READING ON THE HISTORY OF THE CALCULUS SEE:

    The History of the Calculus and its Conceptual Development: Carl c.Boyer, Dover, New York, 1959.

    Mathematical Thought from Ancient to Modern Times; Morris Kline, OxfordUniv.

    Press, New York, 1972.

    No-standard Analysis: Abraham Robinson, North-Holland, Amsterdam,London, 1966.

     

    FOR ADVANCED READING ON INFINITESIMAL ANALYSIS SEE NO-STANDARD ANALYSISBY ABRAHAM ROBINSON AND:

     

    Lectures on Non-standard Analysis; M. Machover and J. Hirschfeld,Springer-Verlag, Berlin, Heidelberg, New York, 1969.

    Victoria Symposium on Nonstandard Analysis; A. Hurd and p. Loeb,Springer-Verlag, Berlin, Heidelberg, New York, 1973.

    Studies in Model Theory; M. Morley, Editor, Mathematical Association ofAmerica, Providence, 1973.

    Applied Nonstandard Analysis: M. Davis, Wiley, New York, 1977.

    Introduction to the Theory of Infinitesimals: K.D Stroyan and W.A. J.Luxemburg, Academic Press, New York and London, 1976.

    Foundations of Infinitesimal Stochastic Analysis: K.D. Stroyan and J.M..Bayod, North-Holland Publ.Co., in press.

     

     

     

     

     

    展开全文
  • 量词分类:中文里有62616964757a686964616fe58685e5aeb931333431353264很多量词,常见的如“只”、“个”,其中有几十个量词在英语里没有对应词。这些量词使得在描述事物时显得丰富多采。为了帮助在美国学中文的学生...

    展开全部

    可以填弯。

    一(弯)月牙。

    量词分类:

    中文里有62616964757a686964616fe58685e5aeb931333431353264很多量词,常见的如“只”、“个”,其中有几十个量词在英语里没有对应词。

    这些量词使得在描述事物时显得丰富多采。为了帮助在美国学中文的学生掌握这些量词,现把它们按功能归类说明,以词组形式出现:

    1、表示人的量词:

    个、位、条、位是比较正式客气的用法。一个司机、一个工人、一个农民、一个士兵、一个朋友。

    2、表示动物的量词:

    只、匹、头、条、峰。

    一只狗、一只鸟、一只猴子、一只鸡、一条鱼、一条虫、一峰骆驼。

    3、表示人和动物器官部位的量词:

    个、只、颗、根、张、片条。除了个和只以外其他大都表示形状。

    一个脑子、一颗脑袋、一根头发、一根眉毛、一只眼睛、一条腿、一只脚、一条尾巴、一颗心。

    4、表示植物的量词:

    棵、株。一棵树、一棵白杨、一棵草、一棵松、一株水稻、一株麦子。

    5、表示水果的量词:

    一粒葡萄、一根香蕉、一个苹果、一个橘子、一个梨、一个李子、一根香蕉。

    5f8d45c15f29a2c6ace57705fc26865d.png

    扩展资料:

    表示地理天文气候的量词:

    一座山 、一道梁 、一条江 、一条河、 一个池子、一个湖、 一个海 、一弯月牙、 一轮明月、

    一颗星星、 一个太阳、 一朵云、 一阵风、 一场雨、 一个响雷、 一道闪电。

    表示形状的量词:

    条、根、支、道、面、片、张、颗、粒、块。

    参考资料来源:百度百科-量词

    展开全文
  • 每日算法--5--散列表

    2020-04-03 22:38:06
    例如:开发一个学生管理系统,需要通过输入学号快速查出对应学生的姓名的功能,这里不必每次都去查询数据库,而可以再内存之中建立一个缓存表,这样做可以提高查询效率 因为这些需求,一个重要的数据结构诞生...

    说在前面:本文是通过阅读作者魏梦舒的《漫画算法》所总结的笔记,仅供学习,如侵即删

     

    • 为什么需要散列表?

    在我们的程序直接中,往往也需要再内存之中存放一个“词典”,为了方便我们进行高效的查询和统计

    例如:开发一个学生管理系统,需要通过输入学号快速查出对应学生的姓名的功能,这里不必每次都去查询数据库,而可以再内存之中建立一个缓存表,这样做可以提高查询效率

    因为这些需求,一个重要的数据结构诞生了,这个数据结构叫做散列表

     

    • 什么是散列表

    散列表也叫作哈希表(hash table)这种数据结构提供了键(key)和值(Value)的映射关系,只要给出一个key,就可以高效的查找到它所匹配的Value,时间复杂度接近于O(1)

    一,哈希函数

    散列表如何通过Key来快速找到所匹配的Value的呢?

    其实散列表再本质上也是一个数组

     

    我们需要一个“中转站”,通过某种方式,把Key和数组下标进行转换,这个中转站就叫作哈希函数

    这里以Java的常用集合HashMap为例,来看一看哈希函数在Java中的实现

    在Java中以及大多数面向对象的语言中,每一个对象都有属于自己的hashcode,这个hashcode是区分不同对象的重要标识,无论对象自身的类型是什么,它们的hashcode都是一个整型变量

    既然都是整型变量,想要转化成数组的下标也就不难实现了,通过数组长度进行取模运算

    index = HashCode(Key)%Array.length

    实际上,JDK中的哈希函数并没有直接采取模运算,而是利用了位运算的方式来优化性能,

    通过哈希函数我们可以把字符串或其他类型的Key,转化成数组的下标index

     

    例如给出一个长度为8的数组,则当

    Key = 001121时,

           index = HashCode("001121")%Array.length = 1420036703%8 = 7

    而当Key = this时

           index = HashCode("this")%Array.length = 3559070%8 = 6

     

    二,散列表的读写操作

    有了哈希函数就可以在散列表中进行读写操作了

    1,写操作

    写操作就是在散列表里面插入新的键值对(Entry)

    如调用hashMap.put("001","小明"),意思就是插入一组Key为001,Value为小明的键值对

    具体怎么做:

    1):通过哈希函数,把Key转化成数组下标5

    2):如果下标5对应的位置没有元素,就把这个Entry填充到数组下标5的位置

    当然,数组的长度是有限的,当插入的Entry越来越多的时候,不同的Key通过哈希函数获取的下标可能是相同的,这种情况就叫做哈希冲突

    解决哈希冲突的方法主要有两种:

    1):开放寻址法:

    当一个Key通过哈希函数获得对应的数组下标已被占用时,我们可以寻找下一个空挡位置

    就是往后挪有空位置再写入

    2);链表法:

    这种方法被应用在Java的集合类HashMap当中

    HashMap数组的每一个元素不仅是一个Entry对象,还是一个链表的头节点,每一个Entry对象通过next指针指向它的下一个Entry节点,当新来的Entry映射到与之冲突的数组位置时,只需要插入到对应的链表中即可

     

    2,读操作(get)

    例如调用hashMap.get("001"),意思是查找Key为001的Entry在散列表中所对应的值

    1):通过哈希函数,把Key转化成数组下标2

    2):找到数组下标2所对应的元素,如果这个元素的Key是001,那么就找到了,如果这个Key不是001也没关系,由于数组的每个元素都与链表对应,我们可以顺着链表慢慢往下找,看看能不能找到与Key相匹配的节点

    首先查找到节点Entry的key是002,和待查找的001不符,接着定位到链表的下一个节点Eetry1的Key 001正是我们所要寻找的,所以返回Entry1的Value即可 

     

    3,扩容(resize)

    什么时候需要扩容?

    当经过多次元素元素插入,散列表达到一定饱和度时,Key映射位置发生冲突的概率会逐渐提高,这样一来,大量元素拥挤在相同的数组下标位置,形成很长的链表,对后续插入操作和查询操作的性能都有很多的影响

    影响扩容的因素有两个:

    • Capacity 即HashMap的当前长度
    • LoadFactor 即HashMap的负载因子,默认值为0.75f

    衡量HashMap需要进行扩容的条件如下:

    HashMap.Size >= Capacity * LoadFactor

     

    扩容并不是简单的把散列表的长度扩大,而是经历了下面两个步骤

    1,扩容,创建一个新的Entry空数组,长度时原数组的2倍

    2,重新Hash,遍历原Entry数组,把所有的Entry重新Hash到新数组中,为什么要重新hash呢?因为长度扩大之后,Hash的规则也随之改变

     

    扩容前的HashMap

    扩容后的HashMap

    展开全文
  • 翻译内容可选择出现在窗口顶部,这样让学生先自己想想是什么意思,实在不知其意,再稍微往上看一下就知道了。 听力测试:软件朗读英语句子,让学生找到对应的句子,软件会判断是否正确,并保留记录方便家长了解学习...
  • 翻译内容可选择出现在窗口顶部,这样让学生先自己想想是什么意思,实在不知其意,再稍微往上看一下就知道了。 听力测试:软件朗读英语句子,让学生找到对应的句子,软件会判断是否正确,并保留记录方便家长了解学习...
  • 其他的对照还包括了实证经济学(研究「是什么」)以及规范经济学(研究「应该是什么」)、经济理论与实用经济学、行为经济学与理性选择经济学、主流经济学(研究理性-个体-均衡等)与非主流经济学(研究体制-历史-...
  • oracle数据库经典题目

    2011-02-17 15:05:20
    同义词是数据库对象的一个替代名,在使用同义词时,Oracle会将其翻译为对应的对象名称 B.在创建同义词时,所替代的模式对象必须存在 C.Oracle中的同义词分为公有同义词和私有同义词 D.公有同义词在数据库中所有的...
  • 然后这是学生成绩表,其中定义了外键约束 [sql] view plain copy create table GRADE( STU_ID INT NOT NULL, STU_SCORE INT, foreign key(STU_ID) references STUDENT(STU_ID) ); insert into GRADE values...
  • 大话数据结构

    2019-01-10 16:35:22
    事先建立一个有2050大的数组,然后把所有年份按下标数字对应,如果闰年,此数组项的值就是1,如果不是就是0。这样,所谓的判断某一年是否闰年就变成了查找这个数组的某一项的值多少的问题。 2.13总结回顾 37 ...
  • 大话数据结构 程杰

    2018-09-01 10:06:43
    事先建立一个有2050大的数组,然后把所有年份按下标数字对应,如果闰年,此数组项的值就是1,如果不是就是0。这样,所谓的判断某一年是否闰年就变成了查找这个数组的某一项的值多少的问题。 2.13总结回顾 37 ...
  • 事先建立一个有2050大的数组,然后把所有年份按下标数字对应,如果闰年,此数组项的值就是1,如果不是就是0。这样,所谓的判断某一年是否闰年就变成了查找这个数组的某一项的值多少的问题。 2.13总结回顾 37 ...
  • 2.11 最坏情况与平均情况 35 2.12 算法空间复杂度 36 事先建立一个有2050大的数组,然后把所有年份按下标数字对应,如果闰年,此数组项的值就是1,如果不是就是0。这样,所谓的判断某一年是否闰年就变成了查找...
  • 事先建立一个有2050大的数组,然后把所有年份按下标数字对应,如果闰年,此数组项的值就是1,如果不是就是0。这样,所谓的判断某一年是否闰年就变成了查找这个数组的某一项的值多少的问题。 2.13总结回顾 37 ...
  • 顶部滑动选+弹出汉字面板选,支持滑动。 具有记忆功能,之前选中过的词语首先显示,支持单个拼音多个汉字,自动调整优先级。 具有造词功能,可以直接打开文件文件写入自定义词组,最高级别显示。 支持数字小键盘...
  • 大话数据结构-程杰

    2014-07-13 23:45:52
    事先建立一个有2050大的数组,然后把所有年份按下标数字对应,如果闰年,此数组项的值就是1,如果不是就是0。这样,所谓的判断某一年是否闰年就变成了查找这个数组的某一项的值多少的问题。 2.13 总结回顾 37...
  • Linux的最早起源在1991年10月5日由一位芬兰的大学生Linux Torvalds (Torvalds@kruuna.helsinki.fi)写了 Linux核心程序的 0.02 版开始的,但其后的发展却几乎都 由互联网上的 Linux社团(Linux Community)互通...
  • 黑客(hacker)实际褒义,维基百科的解释喜欢用智力通过创造性方法来挑战脑力极限的人,特别他们所感兴趣的领域,例如软件编程或电气工程。个人电脑、软件和互联网等划时代的产品都黑客创造出来的,如...
  • 黑客(hacker)实际褒义,维基百科的解释喜欢用智力通过创造性方法来挑战脑力极限的人,特别他们所感兴趣的领域,例如软件编程或电气工程。个人电脑、软件和互联网等划时代的产品都黑客创造出来的,如...
  • 软件工程教程

    热门讨论 2012-07-06 23:10:29
    问:开发这个软件目标是什么? 答: 提高用户对音乐的学习和娱乐 参与创作音乐 项目背景--钢琴练奏师 问:为什么传统音乐程序不好? 答: 传统音乐程序功能单一,容易令人感到枯燥无味,没有吸引力; 传统音乐...
  • 想象一下自己到超市购物的情况,我们购买某些商品的次数肯定会超过总次数的1%,这些商品可能牛奶、面包、可口可乐或百事可乐什么的。我们甚至相信,虽然我们不购买尿布,但是会有1%的顾客会购买尿布。然而,货架上...
  • 想象一下自己到超市购物的情况,我们购买某些商品的次数肯定会超过总次数的1%,这些商品可能牛奶、面包、可口可乐或百事可乐什么的。我们甚至相信,虽然我们不购买尿布,但是会有1%的顾客会购买尿布。然而,货架上...
  • Cassandra 的数据模型与此非常不同,起先可能很难吸引你,特别是对于数据库(应该)是什么已经有了先入为主的概念的人,更是如此。使用Cassandra 并不意味着你必须成为一个Java 开发者。不过,Cassandra 是用Java ...
  • 2.1 为什么是c++ 19 2.2 程序设计范型 19 2.3 过程式程序设计 20 2.3.1 变量和算术 21 2.3.2 检测和循环 22 2.3.3 指针和数组 23 2.4 模块程序设计 23 2.4.1 分别编译 24 2.4.2 异常处理 25 2.5 数据抽象 ...
  • 2.1 为什么是c++ 19 2.2 程序设计范型 19 2.3 过程式程序设计 20 2.3.1 变量和算术 21 2.3.2 检测和循环 22 2.3.3 指针和数组 23 2.4 模块程序设计 23 2.4.1 分别编译 24 2.4.2 异常处理 25 2.5 数据抽象 ...
  • C++程序设计语言(特别版)--源代码

    热门讨论 2012-04-23 07:33:51
    2.1 为什么是c++ 19 2.2 程序设计范型 19 2.3 过程式程序设计 20 2.3.1 变量和算术 21 2.3.2 检测和循环 22 2.3.3 指针和数组 23 2.4 模块程序设计 23 2.4.1 分别编译 24 2.4.2 异常处理 25 2.5 数据抽象 ...
  • 从就业与择业的角度来讲,计算机相关专业的大学生从事oracle方面的技术职业发展中的最佳选择。 其一、就业面广:全球前100强企业99家都在使用ORACLE相关技术,中国政府机构,大中型企事业单位都能有ORACLE技术的...
  • 6.3.3 使用CONTAINS根据的相邻搜索结果 197 6.4 排名搜索 197 6.4.1 根据含义返回排名搜索结果 198 6.4.2 根据权值返回排名搜索结果 199 第7章 视图 201 7.1 普通视图 201 7.1.1 创建基本视图 202 ...

空空如也

空空如也

1 2
收藏数 29
精华内容 11
关键字:

学生对应词是什么