factor, factorial, factorization, fibonacci.
看/写parser时,时常遇到expression, term, factor之流,或更糟,E, T, F.
Expression- Term, Factor, Coefficient :Definition and examples - Cuemath
多项式的项、因子的因,因式分解的因,这是小学数学啊。:-)
byjus.com/maths/polynomial: The terms of polynomials are the parts of the expression that are generally separated by “+” or “-” signs.
In mathematics, polynomial functions, or polynomials, are an important class of simple and smooth functions. Here, simple means they are constructed using only multiplication and addition. Smooth means they are infinitely differentiable, i.e., they have derivatives of all finite orders.
Because of their simple structure, polynomials are very easy to evaluate, and are used extensively in numerical analysis for polynomial interpolation or to numerically integrate more complex functions.
In linear algebra, the characteristic polynomial of a square matrix encodes several important properties of the matrix. In graph theory the chromatic polynomial of a graph encodes the different ways to vertex color the graph using x colors.
Integer factorization | Factorization of polynomials | LU decomposition
factorial: the result when you multiply a whole number by all the numbers below it. 以上这些f-words都是乘法相关。
我们再看个加法相关的:
#include <stdio.h> int fibonacci(int n) { if (n == 0) return 0; if (n == 1) return 1; return fibonacci(n - 1) + fibonacci(n - 2); } int main() { enum { N = 10 }; int f[N], f2[N], i; for (i = 0; i < N; i++) f2[i] = fibonacci(i); f[0] = 0; f[1] = 1; for (i = 0; i < N - 2; i++) f[i + 2] = f[i] + f[i + 1]; for (i = 0; i < N; i++) printf("%d %d\n", f[i], f[i] - f2[i]); getchar(); return 0; }
F(n)=F(n-1) + F(n-2); 令i=n-2, 得F(i+2)=F(i+1) + F(i);再交换=两边,F(i+1) + F(i)=F(i+2). 递归是“想知道F(3)吗?得先知道F(2)和F(1)”,"动态规划"是“如果有了F(1)和F(2),就能算出F(3)”,殊途同归。
自顶向下递归下降分析和自底向上用状态机,也是殊途同归。递归在堆栈里记录状态。
为啥好像没有根据BNF自动生成递归下降分析器的工具?可能是因为看着BNF手写并不麻烦。看到expr显然要写个parse_expr(). 可如果规则是:
expr : expr '+' expr | expr '*‘ expr ;
parse_expr()的头一句就是parse_expr(); 那不就无限递归了吗?上面的规则,不指定'+'和'*'的结合性和优先级是不行的。或者用上f-word:
expr : term '+' term ;
term : factor '*' factor ;
factor : '(' expr ')' ;
parse_expr() -> parse_term() -> parse_factor(): 看是不是'(". 非终结符是“定海神针”。
二维向量的夹角的余弦值为啥和点击相关?cos(α-β) = cosαcosβ + sinαsinβ 高中数学。
虽然我不知道三维和高维为啥也对,但是一维的恒等于1,很合理啊。:-)
标签:term,expr,some,parse,fibonacci,words,factor,polynomial From: https://www.cnblogs.com/funwithwords/p/17041654.html