Pixel World

it's better be burning out than to fade away.

连续性

我们先从一个函数是连续的, 这到底意味着什么开始. 正如我上面所说, 直觉上, 可以一笔画出连续函数的图像.

在一点处的连续

如果f(x)在a点连续,则必须满足以下三个条件:

  • 双侧极限${\lim_{x \to a} f(x)}$存在并且是有限的
  • 函数在点a处有定义,$f(a)$存在并且是有限的
  • 以上两个量相等,即: ${\lim_{x \to a} f(x) = f(x)}$

在一个区间上连续

函数f在[a, b] 上连续,需满足以下三个条件:

  • f在(a,b)的每一点都连续
  • 函数f在x = a处右连续,即 ${\lim_{x \to a^+} f(x)} = f(a)$
  • 函数f在x = b处左连续,即 ${\lim_{x \to b^-} f(x)} = f(b)$

★介值定理

阅读全文 »

基础知识

角度弧度换算

用弧度度量的角 = π/180 × 用度度量的角

用角度度量的角 = 180/π × 用弧度度量的角

sin cos tan csc sec cot

alt

sin(θ) = 对边/斜边

cos(θ) = 临边/斜边

tan(θ) = 对边/临边 = sin(θ)/cos(θ)

csc(θ) = 1/sin(θ)

sec(θ) = 1/cos(θ)

cot(θ) = 1/tan(θ)

常用三角函数速记表

alt

计算三角函数

阅读全文 »

奇函数与偶函数

  • 当对f定义域内所有的x都有f(-x) = -f(x)时,f是奇函数.奇函数的图像关于原点有180°的对称性.
  • 当对f定义域内所有的x都有f(-x) = f(x)时,f是偶函数,偶函数的图像关于y轴具有镜面对称性.

线性函数的图像

形如f(x) = mx + b的函数叫做线性函数,函数的图像为直线,斜率为m.

点斜式

如果已知直线通过点(x0, y0),斜率为m,则它的方程为 y - y0 = m(x - x0)

如果一条直线通过点 (x1, y1) 和 (x2, y2), 则它的斜率等于 (y2 − y1) / (x2 − x1)

常见函数及其图像

多项式

有许多函数是基于 x 的非负次幂建立起来的.你可以以 1、x、$x^2$、$x^3$等为基本项, 然后用实数同这些基本项做乘法, 最后把有限个这样的项加到一起.基本项 $x^n$ 的倍数叫作 $x^n$ 的系数.最大的幂指数n(该项系数不能为零) 叫作多项式的次数.

阅读全文 »

Functor

problem

This solution means that you’d have to rewrite a special version of every existing function you want to use in a Maybe! This greatly limits the usefulness of tools such as Maybe. It turns out Haskell has a type class that solves this problem, called Functor.

definition

Maybe is a member of the Functor type class. The Functor type class requires only one definition: fmap.
alt
_fmap provides an adapter_, Notice that we’re using <$>, which is a synonym for fmap (except it’s a binary operator rather than a function._This ability to transform the types of values inside a Maybe is the true power of the Functor type class._
alt

Though fmap is the official function name, in practice the binary operator <$> is used much more frequently
alt

Applicative

_the Applicative type class allows you to use functions that are inside a context, such as Maybe or IO, Functor is a superclass of Applicative._
alt
alt

The pure method

阅读全文 »

IO TYPES

Haskell has a special parameterized type called IO. Any value in an IO context must stay in this context. This prevents code that’s pure (meaning it upholds referential transparency and doesn’t change state) and code that’s necessarily impure from mixing.

IO types—dealing with an impure world

IO in Haskell is a parameterized type that’s similar to Maybe.The first thing they share in common is that they’re parameterized types of the same kind.The other thing that Maybe and IO have in common is that (unlike List or Map) they describe a context for their parameters rather than a container. The context for the IO type is that the value has come from an input/output operation.To keep Haskell code pure and predictable, you use the IO type to provide a context for data that may not behave the way all of the rest of your Haskell code does. IO actions aren’t functions.

Examples of IO actions

main doesn’t return any meaningful value; it simply performs an action. It turns out that main isn’t a function, because it breaks one of the fundamental rules of functions: it doesn’t return a value. Because of this, we refer to main as an IO action. IO actions work much like functions except they violate at least one of the three rules we established for functions early in the book. Some IO actions return no value, some take no input, and others don’t always return the same value given the same input.
alt

Do-notation

This do-notation allows you to treat IO types as if they were regular types. This also explains why some variables use let and others use <-. Variables assigned with <- allow you to act as though a type IO a is just of type a. You use let statements whenever you create variables that aren’t IO types.

<-

阅读全文 »

01. TYPE BASICS

in Haskell, you haven’t had to write down any information about the
type you’re using for any of your values. It turns out this is because Haskell has done it
for you! Haskell uses type inference to automatically determine the types of all values at
compile time based on the way they’re used! You don’t have to rely on Haskell to determine your types for you.

alt

list tuple function

alt

Functions with multiple arguments

why are type signatures this way? The reason is that behind the scenes in Haskell, all functions take only one argument. By rewriting makeAddress by using a series of nested lambda functions.

alt

Types for first-class functions

阅读全文 »

01. Functions

All functions in Haskell follow three rules that force them to behave like functions in
math:

  • All functions must take an argument.
  • All functions must return a value.
  • Anytime a function is called with the same argument, it must return the same
    value

The third rule is part of the basic mathematical definition of a function. When the rule
that the same argument must always produce the same result is applied to function in a
programming language, it’s called referential transparency.

02. LAMBDA FUNCTIONS AND LEXICAL SCOPE

Lambda functions

One of the most foundational concepts in functional programming is a function without
a name, called a lambda function (hence lambda calculus). Lambda functions are often
referred to using the lowercase Greek letter λ. Another common name for a lambda
function is an anonymous function.
alt

Practical lambda functions and lexical scope

IIFE works on exactly the same principles as our example of replacing a where statement. Whenever you create a new function, named or not, you
create a new scope, which is the context in which a variable is defined. When a variable is
used, the program looks at the nearest scope; if the definition of the variable isn’t there,
it goes to the next one up. This particular type of variable lookup is called lexical scope.
Both Haskell and JavaScript use lexical scoping, which is why IIFE and your lambda function variables behave in a similar fashion.

阅读全文 »

枚举(enum)

当一个变量有几种可能的取值时,可以将它定义为枚举类型,

  1. 当我们声明一个枚举类型是,虽然没有给它们赋值,但是它们的值其实是默认的数字类型,而且默认从0开始依次累加
  2. 因此当我们把第一个值赋值后,后面也会根据第一个值进行累加
  3. 枚举类型的值其实也可以是字符串类型
  4. 字符串枚举可以和数字枚举混合使用

枚举的本质 & 双向映射

枚举具有双向映射的特性,所谓双向映射指的是通过key可以索引到value,同时通过value也可以索引到key.
原因就在编译后的 JavaScript把枚举类型构造成为了一个对象,而由于其特殊的构造,导致其拥有正反向同时映射的特性
alt

常量枚举

枚举可以被 const 声明为常量,这样做的好处是,编译后的js代码中实际上是不存在枚举和枚举对象的,使用的是枚举的值,这是性能提升的一个方案。

如果你非要 TypeScript 保留对象 Direction ,那么可以添加编译选项 —preserveConstEnums

联合枚举类型

阅读全文 »

interface

概述

TypeScript的核心原则之一是对值所具有的结构进行类型检查,它有时被称做”鸭式辩型法”或”结构型子类型化”.
TypeScript里接口的作用就是为这些类型命名和为你的代码和第三方代码定义契约.
alt

可选属性 & 只读属性

alt

函数类型

alt

索引签名

通过定义key和value的类型宽泛的描述接口”形状”.
alt

阅读全文 »

typeScript类型系统

类型注解

基本注解采用 :TypeAnnotation语法,在类型声明空间中可用的任何内容都可以用作类型注解

原始类型

JavaScript 原始类型也同样适应于 TypeScript 的类型系统,因此 string、number、boolean 也可以被用作类型注解.

alt

数组

针对数组的类型注解有两种方式 :TypeAnnotation[] 或者 Array\,这两种方式是等价的
alt

接口

阅读全文 »
0%