Fundamentals of Computer Mathematics ④ (Algorithms and Functions)

Algorithms and Functions

Functions in General

Definition 4.1. Formally, a function consists of three parts:A collection A of possible inputs. We call this the domain of our
function.A collection B describing the type of outputs that our function
will generate. We call this the codomain of our function.A rule f that takes in inputs from A and generates outputs in B.
Furthermore, in order for this all to be a function, we need it to satisfy
the following property:

For every potential input a from A, there should be exactly one b in
B such that f(a) = b.

In other words, we never have a value a in A for which f(a) is undefined,
as that would cause our programs to crash! As well, we also do not allow
for a value a ∈ A to generate “multiple” outputs; i.e. we want to be able
to rely on f(a) not changing on us without warning, if we keep a the
same.

Generally a function consists of three parts:

  • A set of possible inputs. We call it the domain of the function.
  • A set B that describes the output that the function will generate. We call this the function's 上域(Note that this is not a range)。
  • A rule f that takes input from A and produces output in B.

Furthermore, in order for it to be a function, we need it to satisfy the following property:
For every possible input a in A, there should be a b such that f(a) = b.

In other words, no value a in a is undefined by f(a), because that would cause our program to crash! Likewise, we also do not allow a value a ∈ a to produce "multiple" outputs; that is, We hope that f(a) will not change without warning if we keep a constant.

What is the upper domain?
The range is a subset of the upper domain, the upper domain is the set of possible outputs, and the range is the set of actual outputs!
A function must specify a unique result for each valid input.


Suppose you have a ball of kneaded white flour, ready to make colorful steamed buns, you can add purple potato to make purple steamed buns, add pitaya to make pink steamed buns, add chocolate, add wormwood, add...
let f(x) = " The color of the steamed bun made by adding white flour to the ingredient x”, the upper domain is the set of all colors, and the value domain is the set of objects after the function transforms the domain.
---------- The range is a subset of the upper domain, the upper domain is the set of possible outputs, and the range is the set of actual outputs!

insert image description here
The definition of the range is explained here:
we define the range of f as the set of all values ​​for which the function in the upper domain actually sends a value in the domain.

insert image description here
The conformity of the function is defined. In addition to mastering the symbolic expression, the value domain of the internal function must be a subset of the domain of the external function!

Algorithms

Definition 4.3. An algorithm is a precise and unambiguous set of
instructions.

An algorithm is a set of precise and unambiguous instructions.

insert image description here
The figure shows two algorithms:

  • a%n's algorithm
  • Algorithms to determine prime numbers

There are also classic sorting algorithms (10 kinds), you can understand by yourself

Comparing Runtimes: Limits

insert image description here
involves the concept of limits

insert image description here
If the above equation is satisfied, then we can say that the function f(n) grows faster than g(n)

Limit Techniques and Heuristics

Observation 4.12. Plugging In Values. Probably the simplest thing
you can do, when given a limit, is just physically plug in numbers and
figure out where the function is going.

Substitute the value. Probably the easiest thing you can do, when given a limit, is to physically plug in the numbers and figure out where the function goes.

insert image description here
Here is a suggestion to simplify the importance of fractions for finding limits

insert image description here
Another trick for finding the limit: break it into small parts, and then find the limit for each part

The focus of this section is to find the limit, you can directly refer to Advanced Mathematics (I)

Guess you like

Origin blog.csdn.net/zyb18507175502/article/details/124252954