Edición de «Práctica 3: Cuantificadores (Algoritmos I)»

De Cuba-Wiki
Advertencia: no has iniciado sesión. Tu dirección IP se hará pública si haces cualquier edición. Si inicias sesión o creas una cuenta, tus ediciones se atribuirán a tu nombre de usuario, además de otros beneficios.

Puedes deshacer la edición. Antes de deshacer la edición, comprueba la siguiente comparación para verificar que realmente es lo que quieres hacer, y entonces publica los cambios para así efectuar la reversión.

Revisión actual Tu texto
Línea 7: Línea 7:
# (<math>\forall j \in [0..|s|)) s_j == x </math>
# (<math>\forall j \in [0..|s|)) s_j == x </math>
# (<math>\exists x \in r, x\ mod\ 2 == 0)(\forall j \in [0..|s|)) s_j == x </math>
# (<math>\exists x \in r, x\ mod\ 2 == 0)(\forall j \in [0..|s|)) s_j == x </math>
# <math> ( |s|>5 \land a < b-1 \land (\forall j \in [a..b)) 2 * s_j == s_{j+1})</math>
# <math> ( |s|>5 \land a<b-1 \land (\forall j \in [a..b)) 2 * s_j == s_{j+1})</math>




Línea 46: Línea 46:
'''Respuestas:'''
'''Respuestas:'''


a) aux suc <math>(x: \mathbb{Z}): \mathbb{Z}</math> = x + 1;
a) aux suc <math>(x: \mathbb{Z}): \mathbb{Z}</math> = x+1


b) aux suma <math>(x,y: \mathbb{R}): \mathbb{R}</math> = x + y;
b) aux suma <math>(x,y: \mathbb{R}): \mathbb{R}</math> = x + y


c) aux producto<math>(x, y: \mathbb{R}): \mathbb{R}</math> = x * y;
c) aux producto<math>(x, y: \mathbb{R}): \mathbb{R}</math> = x * y


d) aux cuadrado<math>(x: \mathbb{Z})</math>: Bool = (x <math>\geq</math> 0 <math>\wedge</math>(<math>\exists</math> y <math>\leftarrow</math> [0..x]) y*y == x);
d) aux cuadrado<math>(x: \mathbb{Z})</math>: Bool = (<math>\exists y \leftarrow</math> [1..y]) y*y = x  


e)aux primo<math>(x: \mathbb{Z})</math>: Bool = |[ y | y <math>\leftarrow</math>[1..|x|], x mod y == 0]| == 2 (Recordemos que un número es primo si tiene exactamente dos divisores positivos: el 1 y su valor absoluto)  
e)aux primo<math>(x: \mathbb{Z})</math>: Bool = |[ y | y <math>\leftarrow</math>[1..|x|], x mod y == 0]| == 2 (Recordemos que un número es primo si tiene exactamente dos divisores positivos: el 1 y su valor absoluto)  


f) aux coprimos<math>(x,y: \mathbb{Z})</math>: Bool == |[ z | z <math>\leftarrow</math> [1..x], x mod z==0, y mod z == 0]| == 1 (Dos números son coprimos si tienen un único divisor positivo en común: el uno)
f) aux coprimos<math>(x,y: \mathbb{Z})</math>: Bool == |[ z | z <math>\leftarrow</math> [0..x], x mod z==0, y mod z == 0]| == 1 (Dos números son coprimos si tienen un único divisor positivo en común: el uno)


g) aux divisoresGrandes<math>(x,y : \mathbb{Z})</math>: Bool = (<math>\forall</math> z <math>\leftarrow</math> [ t | t <math>\leftarrow</math> [2..|x|], x mod t == 0]) z > y
g) aux divisoresGrandes<math>(x,y : \mathbb{Z})</math>: Bool = (<math>\forall</math> z <math>\leftarrow</math> [ t | t <math>\leftarrow</math> [2..|x|], x mod t == 0]) z > y
Línea 62: Línea 62:
h) aux mayorPrimo<math>(x: \mathbb{Z}): \mathbb{Z}</math> =  
h) aux mayorPrimo<math>(x: \mathbb{Z}): \mathbb{Z}</math> =  
<math>[y | y \leftarrow [0..|x|], primo(y), x \ mod \ y == 0 ]_{|[ y | y \leftarrow [0..|x|], \ primo(y), x \ mod \ y == 0]|-1}</math>
<math>[y | y \leftarrow [0..|x|], primo(y), x \ mod \ y == 0 ]_{|[ y | y \leftarrow [0..|x|], \ primo(y), x \ mod \ y == 0]|-1}</math>
otras formas:
-utilizar un aux ultimo que sea algo asi como cabeza(invertir(l:[T]))


i) aux mcm<math>(x,y: \mathbb{Z}): \mathbb{Z}</math> = cab([ z | z <math>\leftarrow</math> [0..|x*y|], z \ mod \ x == 0, z \ mod \ y == 0])
i) aux mcm<math>(x,y: \mathbb{Z}): \mathbb{Z}</math> = cab([ z | z <math>\leftarrow</math> [0..|x*y|], z \ mod \ x == 0, z \ mod \ y == 0])


j) aux mcd<math>(x,y: \mathbb{Z}): \mathbb{Z}</math> = <math>[ z | z \leftarrow [0..|x|], x \ mod \ z == 0, y \ mod \ z == 0 ]_{[ z | z \leftarrow [0..|x|], x \ mod \ z == 0, y \ mod \ z == 0 ] - 1}</math>
j) aux mcd<math>(x,y: \mathbb{Z}): \mathbb{Z}</math> = <math>[ z | z \leftarrow [0..|x|], x \ mod \ z == 0, y \ mod \ z == 0 ]_{[ z | z \leftarrow [0..|x|], x \ mod \ z == 0, y \ mod \ z == 0 ] - 1}</math>


===Ejercicio 3===
===Ejercicio 3===
Línea 74: Línea 73:
1. ''capicua'', que determina si una secuencia es capicúa. (Por ejemplo, [0,2,1,2,0] es capicúa y [0,2,1,4,0] no).
1. ''capicua'', que determina si una secuencia es capicúa. (Por ejemplo, [0,2,1,2,0] es capicúa y [0,2,1,4,0] no).


''capicua''(x: [T]): Bool = (<math>\forall</math>i <math> \leftarrow</math> [0..|x|) ) <math>x_i==x_{|x|-i-1}</math>
''capicua''(x: [T]): Bool = (<math>\forall</math>i <math> \leftarrow</math> [0..|x|/2]) <math>x_{i-1}==x_{|x|-i}</math>




Línea 80: Línea 79:


''esPrefijo''(x,y: [T]): Bool = (<math>\exists</math> i <math>\leftarrow</math> [0..|y|-1]) x==[<math>y_i</math>| j <math>\leftarrow</math> [0..i] ]
''esPrefijo''(x,y: [T]): Bool = (<math>\exists</math> i <math>\leftarrow</math> [0..|y|-1]) x==[<math>y_i</math>| j <math>\leftarrow</math> [0..i] ]
otra forma:
(|b| > |a| <math>\wedge</math> (<math>\forall i \leftarrow</math> [0..|a|) ) <math>a_i==b_i</math>);


3. ''estaOrdenada'', que determina si la secuencia está ordenada de menor a mayor.
3. ''estaOrdenada'', que determina si la secuencia está ordenada de menor a mayor.
Línea 119: Línea 114:


''sinRepetidos''(x: [T]): Bool = (<math>\forall</math> i,j <math>\leftarrow</math> [0..|x|-1], i <math>\neq</math>j) <math>x_i \neq x_j </math>
''sinRepetidos''(x: [T]): Bool = (<math>\forall</math> i,j <math>\leftarrow</math> [0..|x|-1], i <math>\neq</math>j) <math>x_i \neq x_j </math>
otra forma:
(<math>\forall</math> i <math>\leftarrow</math> [0..|x|-1]), <math>x_i \not\in x_{[0..i)}) </math>
otra más:
(<math>\forall</math> e <math>\leftarrow</math> x, cuenta(e, x) == 1)




Línea 150: Línea 141:


''enTresPartesPrima''(x: [<math>\mathbb{Z}]</math>): Bool = ( estaOrdenada(x) <math> \land (\forall</math> a <math>\leftarrow</math> x) <math> (0 \geq a  \ \land \ a \leq 2 </math> ) )
''enTresPartesPrima''(x: [<math>\mathbb{Z}]</math>): Bool = ( estaOrdenada(x) <math> \land (\forall</math> a <math>\leftarrow</math> x) <math> (0 \geq a  \ \land \ a \leq 2 </math> ) )


===Ejercicio 4===
===Ejercicio 4===
1- "Todos los naturales menores a 10 que cumplen P, cumplen Q":
aux a: Bool (<math>\forall x \in</math> [0..10)) (<math>P(x) \wedge Q(x)</math>)
Esta mal porque no queremos que para todos, todos cumplan P y Q, sino que cuando P sea verdadero, Q tambien lo sea:
aux a: Bool (<math>\forall x \in</math> [0..10))(<math>P(x) \Rightarrow Q(x)</math>)
2- "No hay ningún natural menor a 10 que cumpla P y Q":
aux c: Bool = <math>(\neg ( \exists x \in [0..10) P(x)  \wedge \neg ( \exists x \in [0..10) Q(x))</math>
Pero esto diría que ninguno en s cumple P y ninguno en s cumple Q.
En su lugar deberíamos poner:
aux c: Bool = <math>\neg ( \exists x \in [0..10) ) P(x) \wedge Q(x)</math>;
Ten en cuenta que todas las contribuciones a Cuba-Wiki pueden ser editadas, modificadas o eliminadas por otros colaboradores. Si no deseas que las modifiquen sin limitaciones, no las publiques aquí.
Al mismo tiempo, asumimos que eres el autor de lo que escribiste, o lo copiaste de una fuente en el dominio público o con licencia libre (véase Cuba-Wiki:Derechos de autor para más detalles). ¡No uses textos con copyright sin permiso!

Para editar esta página, responde la pregunta que aparece abajo (más información):

Cancelar Ayuda de edición (se abre en una ventana nueva)