vault backup: 2023-11-13 13:50:53

This commit is contained in:
2023-11-13 13:50:53 +01:00
parent 480ec6cbfe
commit bb839a2db9
25 changed files with 61 additions and 31 deletions

View File

@ -0,0 +1,66 @@
An abstract type have a signature, which contains types, uses and operations, and have some axioms.
An axiom let us determine the value of the application of the observers with the internal operations (in the example below, the operation modify). We can see that as a validation. An axiom must be precise. An axiom is the application of the observer on an internal operation : `observer(internal operation)`
```
Types
vector
Uses
integer, element
Operations
Modify : vector x integer x element -> vector /*internal operation*/
Nth: vector x integer -> element /* Observers */
Lowerlimit: vector -> integer /* Observers */
Upperlimit: vector -> integer /* Observers */
Axioms
lowerlimit(v) =< i =< upperlimit(v) -> nth(modify(v,i,e), i) = e
```
In this example, the axiom explain that it check nth position in the modified vector
The axiom can't be contradictory. Two (or more) contradictory axioms are call the consistency. When we create the axiom, we have to remove all the consistency.
Example:
```
nth(v,1)=0
nth(v,i)=i
```
That an consistency, because the two `nth`axioms are contradictory
The completeness is when we have enough axioms for our abstract type :
1. **Completeness**: Axioms should provide a complete and unambiguous specification of the ADT's behavior. This means that they should cover all possible scenarios and outcomes for the ADT's operations. Users of the ADT should be able to rely on these axioms to understand how the ADT behaves in different situations.
2. **Consistency**: Axioms should be consistent with each other and with the intended behavior of the ADT. This means that the axioms should not contradict each other, and they should accurately reflect the expected behavior of the ADT's operations. Inconsistent axioms can lead to confusion and incorrect usage of the ADT.
To use partial operations we have to create some preconditions
```
Types
vector
Uses
integer, element, boolean
Operations
Vect: integer x integer -> vector /* internal operation */
Modify : vector x integer x element -> vector /*internal operation*/
Nth: vector x integer -> element /* Observers */
isint: vector x integer -> boolean
Lowerlimit: vector -> integer /* Observers */
Upperlimit: vector -> integer /* Observers */
Preconditions
nth(v,i) is-defined-iaoi lowerlimit(v) =< (i) =< upperlimit(v) & isinit(v,i) = true
Axioms
lowerlimit(v) =< i =< upperlimit(v) -> nth(modify(v,i,e), i) = e
lowerlimit(v) =< i =< upperlimit(v) & lowerlimit(v) =< j =< upperlimit(v) & i≠j -> nth(modifiy(v,i,e), j) = nth(v,j)
isinit(vect(i,j),k)= false
lowerlimit(v) =< i =< upperlimit(v) -> isinit(modifiy(v,i,e),i)= true
... (all the other axioms)
```
Here, `nth`is a partial operation and `isinit` is a auxiliary operation
## Important things to create a abstract type
- What we want to create
- Add all necessary operations
- Preconditions
- Axios

View File

@ -0,0 +1,52 @@
## Outline
- Abstract Algebraic Data types
- Elementary types
- List
- Stack
- Queue
- Set
- Searching algorithms
- Tree
- Binary
- General
- BST
- AVL
- A234
## Abstract Algebraic Data Types
### Signature and hierarchy
- a signature is composed by
- a type (integer, stack, queue, graph)
- an operations (name: profile)
- Exemple:
- ``insert: list x integer x element -> list``
- ``insert(l, i, e)``
- return a result of type `list`
- We can use the `_`to pass an argument without parentheses
- `facotrial: interger -> integer`= `_!: interger -> integer`
- `power: integer x integer -> integer`= `_^_: integer x integer -> integer`
- Operations
- `0: -> integer`
- `false: -> boolean`
- `pi: -> real`
- Types
- Boolean
- Opération:
- `false: -> boolean`
- `true: -> boolean`
- `not_: boolean -> boolean`
- `_and_: boolean x boolean -> boolean`
- `_or_: boolean x boolean -> boolean`
- Vectors (defined type)
- Uses: integer and element (predefined types)
- Operations:
- `modify: vector x integer x element -> vector` (internal operation)
- `nth: vector x integer -> element` (observers)
- `lowerlimit: vector -> integer` (observers)
- `upperlimit: vector -> integer` (observers)
- Use
- `nth(v, i+2)`
> Every time that an operation return a defined type, is a **internal operation.** An internal operation will really modify the data
> **An observer** is when there is AT LEAST 1 defined type vector and who return a predefined type. The observer just look into the data and return the selected value, but he don't change any values.

54
Algo/B1/CM/Lists.md Normal file
View File

@ -0,0 +1,54 @@
List is the most fundamental data type. Is a sequencial argument, is a final sequence of element. It is no possible to have more than one element per box.
There is two different way to declare a list, the recursive one and the iterative one.
## Recursive list
- The first box is the **head of the list**
- The rest of the list is **the tail of the list**
- The signature of the recursive list is the following:
```
TYPES
list, box
USES
element
OPERATIONS
emptylist : -> list (* Internal operations of list*)
cons : element x list -> list (* Internal operations of list *)
tail : list -> list (* Internal operations of list *)
head : list -> box (* Internal operations of box *)
contents : box -> element (* Observer of box *)
first : list -> element (* Observer of list *)
next : box -> box (* Internal operation of box *)
PRECONDITIONS
tail(l) is-defined-iaoi l ≠ emptylist
head(l) is-defined-iaoi l ≠ emptylist
first(l) is-defined-iaoi l ≠ emptylist
AXIOMS
first(_l_) = contents(head(l))
tail(cons(_e,l_)) = l
first(cons(_e,l_)) = e
next(head(_l_)) = head(tail(l))
WITH
list l
element e
```
`cons` add en element to the head of the list (eg. li <- cons(cloud, li))
`head`return the element in the head of the list (eg. pl <- head(li))
`contents`return what is the element of the head
`first`return the first element of the list (is equivalent to contents)
`tail`remove the first element of the list (eg. fl <- tail (li))
`next`return the element after a box (eg. pspt <= next(head(li))))
## Array implementation
Let's take a list l = E ; D ; C ; B ; A. An array implementation of the list l will be:
|1|2|3|4|5|
|:----:|:----:|:----:|:----:|:----:|
|A|B|C|D|E|
|5|
The first line of the table is the $n^{th}$ place of the element, the second line is all the element of the list, and the third line is the place of the first element of the list (here E is at the $5^{th}$ position).