* add conversion from pdf to latex-like (.mmd) format with nougat
* change vector_db_manager.py to handle .mmd * add "conversion" tab * add math mode checkbox in maintab
This commit is contained in:
parent
356f72fedc
commit
11b92baaa8
17 changed files with 247 additions and 33 deletions
|
@ -17,28 +17,32 @@ class InferenceInstance:
|
||||||
self.nb_chunks_retrieved = nb_chunks_retrieved
|
self.nb_chunks_retrieved = nb_chunks_retrieved
|
||||||
|
|
||||||
def get_next_token(self, input_user: str, doc_name: str) -> Iterator[Dict[str, str]]:
|
def get_next_token(self, input_user: str, doc_name: str) -> Iterator[Dict[str, str]]:
|
||||||
|
is_pdf = doc_name.endswith(".pdf")
|
||||||
|
print(f"doc_name: {doc_name}")
|
||||||
new_assistant_message = {"role": "assistant", "content": ""}
|
new_assistant_message = {"role": "assistant", "content": ""}
|
||||||
search_results = self._get_search_results(input_user, doc_name)
|
search_results = self._get_search_results(input_user, doc_name)
|
||||||
print(f"search results: {search_results}")
|
print(f"search results: {search_results}")
|
||||||
pages = self._update_history(input_user, search_results)
|
pages = self._update_history(input_user, search_results, is_pdf)
|
||||||
pages_info = f"pages used : p" + " p".join(pages)
|
pages_info = f"pages used : p" + " p".join(pages)
|
||||||
print(f"history: {self.history}")
|
print(f"history: {self.history}")
|
||||||
completion = self._get_completion()
|
completion = self._get_completion()
|
||||||
|
|
||||||
for chunk in completion:
|
for chunk in completion:
|
||||||
new_assistant_message["content"] += chunk.choices[0].delta.content
|
if chunk.choices[0].delta.content:
|
||||||
yield pages_info + " " + new_assistant_message["content"]
|
new_assistant_message["content"] += chunk.choices[0].delta.content
|
||||||
|
yield pages_info + "\n\n " + new_assistant_message["content"]
|
||||||
|
|
||||||
def _get_search_results(self, input_user: str, doc_name: str):
|
def _get_search_results(self, input_user: str, doc_name: str):
|
||||||
print(f"input_user: {input_user}")
|
print(f"input_user: {input_user}")
|
||||||
vector_db = self.vector_db_manager.get_chroma(doc_name)
|
vector_db = self.vector_db_manager.get_chroma(doc_name)
|
||||||
return vector_db.similarity_search(input_user, k=4)
|
return vector_db.similarity_search(input_user, k=4)
|
||||||
|
|
||||||
def _update_history(self, input_user: str, search_results):
|
def _update_history(self, input_user: str, search_results, is_pdf):
|
||||||
some_context = ""
|
some_context = ""
|
||||||
pages = []
|
pages = []
|
||||||
for result in search_results:
|
for result in search_results:
|
||||||
pages.append(str(result.metadata['page']))
|
if is_pdf:
|
||||||
|
pages.append(str(result.metadata['page']))
|
||||||
some_context += result.page_content + "\n\n"
|
some_context += result.page_content + "\n\n"
|
||||||
self.history.append({"role": "system", "content": f"relevant content for user question {some_context}"})
|
self.history.append({"role": "system", "content": f"relevant content for user question {some_context}"})
|
||||||
self.history.append({"role": "user", "content": input_user})
|
self.history.append({"role": "user", "content": input_user})
|
||||||
|
|
16
backend/pdf_to_mmd.py
Normal file
16
backend/pdf_to_mmd.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def pdf_to_mmd(path_input: str):
|
||||||
|
"""
|
||||||
|
Convert a PDF file to MMD format using the Nougat library
|
||||||
|
https://github.com/facebookresearch/nougat
|
||||||
|
|
||||||
|
stream stderr to the front end
|
||||||
|
"""
|
||||||
|
output_dir = "../documents/mmds"
|
||||||
|
command = ['nougat', path_input, "-o", output_dir]
|
||||||
|
subprocess.run(command)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ class VectorDbManager:
|
||||||
self.db_directory = db_directory
|
self.db_directory = db_directory
|
||||||
self.chunk_size = chunk_size
|
self.chunk_size = chunk_size
|
||||||
|
|
||||||
|
|
||||||
def create_vector_store_from_pdf(self, pdf_path):
|
def create_vector_store_from_pdf(self, pdf_path):
|
||||||
"""
|
"""
|
||||||
create a chroma vector store from a pdf file path
|
create a chroma vector store from a pdf file path
|
||||||
|
@ -26,7 +25,7 @@ class VectorDbManager:
|
||||||
"""
|
"""
|
||||||
pdf_path = Path(pdf_path)
|
pdf_path = Path(pdf_path)
|
||||||
pdf_name = pdf_path.name
|
pdf_name = pdf_path.name
|
||||||
vector_directory = self.db_directory/self.embedding_name/pdf_name
|
vector_directory = self.db_directory / self.embedding_name / pdf_name
|
||||||
|
|
||||||
if os.path.isdir(vector_directory):
|
if os.path.isdir(vector_directory):
|
||||||
print(f"{vector_directory} found, not recreating a vector store")
|
print(f"{vector_directory} found, not recreating a vector store")
|
||||||
|
@ -49,7 +48,7 @@ class VectorDbManager:
|
||||||
docs = text_splitter.split_documents(docs)
|
docs = text_splitter.split_documents(docs)
|
||||||
|
|
||||||
vectorstore = Chroma.from_documents(docs, self.embedding_function, persist_directory=vector_directory)
|
vectorstore = Chroma.from_documents(docs, self.embedding_function, persist_directory=vector_directory)
|
||||||
print("vector store created")
|
print("pdf vector store created")
|
||||||
print(vectorstore)
|
print(vectorstore)
|
||||||
|
|
||||||
def create_vector_store_from_latex(self, latex_path: Path):
|
def create_vector_store_from_latex(self, latex_path: Path):
|
||||||
|
@ -62,7 +61,7 @@ class VectorDbManager:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
doc_name = latex_path.name
|
doc_name = latex_path.name
|
||||||
vector_directory = self.db_directory/self.embedding_name/doc_name
|
vector_directory = self.db_directory / self.embedding_name / doc_name
|
||||||
|
|
||||||
if os.path.isdir(vector_directory):
|
if os.path.isdir(vector_directory):
|
||||||
print(f"{vector_directory} found, not recreating a vector store")
|
print(f"{vector_directory} found, not recreating a vector store")
|
||||||
|
@ -71,10 +70,13 @@ class VectorDbManager:
|
||||||
print(f"creating vector store for {vector_directory}")
|
print(f"creating vector store for {vector_directory}")
|
||||||
|
|
||||||
with open(latex_path, mode="r") as file:
|
with open(latex_path, mode="r") as file:
|
||||||
text_splitter = RecursiveCharacterTextSplitter(chunk_size=self.chunk_size, chunk_overlap=100)
|
text_splitter = RecursiveCharacterTextSplitter.from_language(Language.MARKDOWN, chunk_size=self.chunk_size, chunk_overlap=64)
|
||||||
docs = text_splitter.split_document(file.read())
|
texts = text_splitter.split_text(file.read())
|
||||||
|
|
||||||
vectorstore = Chroma.from_documents(docs, self.embedding_function, persist_directory=vector_directory)
|
print(texts)
|
||||||
|
vectorstore = Chroma.from_texts(texts, self.embedding_function, persist_directory=vector_directory)
|
||||||
|
print("latex vector store created")
|
||||||
|
print(vectorstore)
|
||||||
|
|
||||||
def get_chroma(self, doc_name):
|
def get_chroma(self, doc_name):
|
||||||
"""
|
"""
|
||||||
|
@ -83,6 +85,5 @@ class VectorDbManager:
|
||||||
:param doc_name:
|
:param doc_name:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
vector_directory = self.db_directory/self.embedding_name/doc_name
|
vector_directory = self.db_directory / self.embedding_name / doc_name
|
||||||
return Chroma(persist_directory=vector_directory, embedding_function=self.embedding_function)
|
return Chroma(persist_directory=vector_directory, embedding_function=self.embedding_function)
|
||||||
|
|
||||||
|
|
170
documents/mmds/2009L1feuille2bis.mmd
Normal file
170
documents/mmds/2009L1feuille2bis.mmd
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
**Exercices corriges**
|
||||||
|
|
||||||
|
**Algebre lineaire 1**
|
||||||
|
|
||||||
|
## 1 Enonces
|
||||||
|
|
||||||
|
**Exercice 1**: On rappelle que \((E,+,\cdot)\) est un \(\mathbb{K}\)-espace vectoriel si
|
||||||
|
|
||||||
|
1. \((E,+)\) est un groupe commutatif\(\,\);
|
||||||
|
2. \(\forall x,y\in E,\,\forall\alpha\in\mathbb{K},\,\alpha\cdot(x+y)=\alpha\cdot x +\alpha\cdot y\,\);
|
||||||
|
3. \(\forall x\in E,\,\forall\alpha,\beta\in\mathbb{K},\,(\alpha+\beta)\cdot x= \alpha\cdot x+\beta\cdot x\,\);
|
||||||
|
4. \(\forall x\in E,\,\forall\alpha,\beta\in\mathbb{K},\,\alpha\cdot(\beta\cdot x )=(\alpha\beta)\cdot x\,\);
|
||||||
|
5. \(1\cdot x=x\).
|
||||||
|
|
||||||
|
Soit \((E,+,\cdot)\) un \(\mathbb{K}\)-espace vectoriel. On note \(0_{E}\) l'element neutre de \((E,+)\) (que l'on appelle aussi l'origine de \((E,+,\cdot)\)) et \(0_{\mathbb{K}}\) le nombre zero (dans \(\mathbb{K}\)). Pour tout \(x\) dans \(E\), le symetrique de \(x\) est note \(-x\).
|
||||||
|
|
||||||
|
1. Montrer que, pour tout \(x\in E\), \(x+x=2\cdot x\).
|
||||||
|
2. Montrer que, pour tout \(x\in E\), \(0_{\mathbb{K}}\cdot x=0_{E}\).
|
||||||
|
3. Montrer que, pour tout \(x\in E\), \((-1)\cdot x=-x\).
|
||||||
|
|
||||||
|
**Exercice 2**: Soient \(F_{1},\ldots,F_{m}\) des sous-espaces vectoriels d'un \(\mathbb{R}\)-espace vectoriel \((E,+,\cdot)\). Montrer que \(F:=F_{1}\cap\ldots\cap F_{m}\) est un sous-espace vectoriel de \(E\).
|
||||||
|
|
||||||
|
**Exercice 3**: Soient \((E,+,\cdot)\) un \(\mathbb{R}\)-espace vectoriel, \(\{x_{1},\ldots,x_{m}\}\) une famille de vecteurs de \(E\). Montrer que \(F:=\operatorname{vect}\{x_{1},\ldots,x_{m}\}\) est un sous-espace vectoriel de \(E\).
|
||||||
|
|
||||||
|
**Exercice 4**: Soient \((E,+,\cdot)\) un \(\mathbb{R}\)-espace vectoriel, \(F\) un sous-espace vectoriel de \(E\) et \(A,B\) deux sous-ensembles de \(E\).
|
||||||
|
|
||||||
|
1. Montrer que, si \(A\subset B\), alors \(\operatorname{vect}A\subset\operatorname{vect}B\).
|
||||||
|
2. Montrer que \(A\) est un sous-espace vectoriel de \(E\) si et seulement si \(\operatorname{vect}A=A\).
|
||||||
|
3. Montrer que, si \(A\subset B\subset F\) et \(A\) engendre \(F\), alors \(B\) engendre \(F\).
|
||||||
|
|
||||||
|
**Exercice 5**: Considerons les vecteurs de \(\mathbb{R}^{4}\) suivants :
|
||||||
|
|
||||||
|
\[\mathbf{e}_{1}=\left(\begin{array}{c}1\\ 1\\ 1\\ 1\\ 1\end{array}\right),\quad\mathbf{e}_{2}=\left(\begin{array}{c}0\\ 1\\ 2\\ -1\end{array}\right),\quad\mathbf{e}_{3}=\left(\begin{array}{c}1\\ 0\\ -2\\ 3\end{array}\right),\quad\mathbf{e}_{4}=\left(\begin{array}{c}2\\ 1\\ 0\\ -1\end{array}\right).\]
|
||||||
|
|
||||||
|
La famille \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3},\mathbf{e}_{4}\}\) est-elle libre\(\,\)? Est-ce une base de \(\mathbb{R}^{4}\,\)?
|
||||||
|
|
||||||
|
**Exercice 6**: Considerons les vecteurs de \(\mathbb{R}^{4}\) suivants :
|
||||||
|
|
||||||
|
\[\mathbf{e}_{1}=\left(\begin{array}{c}1\\ 1\\ 1\\ 1\end{array}\right),\quad\mathbf{e}_{2}=\left(\begin{array}{c}0\\ 1\\ 2\\ 1\end{array}\right),\quad\mathbf{e}_{3}=\left(\begin{array}{c}1\\ 0\\ -2\\ 3\end{array}\right),\quad\mathbf{e}_{4}=\left(\begin{array}{c}1\\ 1\\ 2\\ -2\end{array}\right).\]1. La famille \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3},\mathbf{e}_{4}\}\) est-elle libre?
|
||||||
|
2. Quel est le rang de la famille \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3},\mathbf{e}_{4}\}\)?
|
||||||
|
3. Determiner une relation entre les nombres reels \(\alpha\) et \(\beta\) pour que le vecteur \(\mathbf{u}=(1,1,\alpha,\beta)^{t}\) appartienne au sous-espace vectoriel engendre par la famille \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3},\mathbf{e}_{4}\}\).
|
||||||
|
|
||||||
|
**Exercice 7**: Soit \(E=\mathbb{R}^{\mathbb{R}}\), l'espace des fonctions de \(\mathbb{R}\) dans \(\mathbb{R}\).
|
||||||
|
|
||||||
|
1. Soient \(c\) et \(s\) les fonctions definies par \[\forall x\in\mathbb{R},\quad c(x)=\cos x\quad\text{et}\quad s(x)=\sin x.\] Montrer que \(\{c,s\}\) est une famille libre de \(E\). Quelle est la dimension du sous-espace vectoriel \(T\) engendre par la famille \(\{c,s\}\)?
|
||||||
|
2. Soient \(\alpha,\beta,\gamma\) trois reels fixes. Soient \(f,g,h\) les fonctions definies par \[\forall x\in\mathbb{R},\quad f(x)=\cos(x+\alpha),\quad g(x)=\cos(x+\beta) \quad\text{et}\quad h(x)=\cos(x+\gamma).\] Montrer que \(f,g,h\) appartiennent a \(T\), et expliciter leurs coordonnees dans la base \(\{c,s\}\) de \(T\). La famille \(\{f,g,h\}\) est-elle libre? Quel est son rang?
|
||||||
|
3. Soient \(a_{1},a_{2},a_{3}\) trois reels distincts. Pour tout entier \(k\in\{1,2,3\}\) on note \(f_{k}\) la fonction definie sur \(\mathbb{R}\) par \[\forall x\in\mathbb{R},\quad f_{k}(x)=\left|x-a_{k}\right|.\] Montrer que \(\{f_{1},f_{2},f_{3}\}\) est une famille libre de \(E\).
|
||||||
|
|
||||||
|
**Exercice 8**:
|
||||||
|
1. On rappelle que \(\mathcal{C}_{0}(\mathbb{R})\) designe l'espace des fonctions continues de \(\mathbb{R}\) dans \(\mathbb{R}\). Montrer que \(\mathcal{A}:=\{f\in\mathcal{C}_{0}(\mathbb{R})|\forall x\in\mathbb{R},\;f(x)= f(-x)\}\) et \(\mathcal{B}:=\{f\in\mathcal{C}_{0}(\mathbb{R})|\forall x\in\mathbb{R},\;f(x)= -f(-x)\}\) sont des sous-espaces vectoriels de \(\mathcal{C}_{0}(\mathbb{R})\). Sont-ils en somme directe?
|
||||||
|
2. Montrer que \(A:=\{(x,y,z)\in\mathbb{R}^{3}|x+y+z=0\}\) et \(B:=\{(x,y,z)\in\mathbb{R}^{3}|x-y+z=0\}\) sont des sous-espaces vectoriels de \(\mathbb{R}^{3}\). Sont-ils en somme directe?
|
||||||
|
|
||||||
|
**Exercice 9**:
|
||||||
|
1. Soient \(F:=\{(x,x,x)\in\mathbb{R}^{3}|x\in\mathbb{R}\}\) et \(G:=\{(0,y,z)\in\mathbb{R}^{3}|y,z\in\mathbb{R}\}\). Montrer que \(F\) et \(G\) sont deux sous-espaces vectoriels de \(\mathbb{R}^{3}\). Preciser leurs bases et leurs dimensions. Sont-ils en somme directe?
|
||||||
|
2. Soit \(H:=\{(x,y,z,t)\in\mathbb{R}^{4}|x=2y-z,\;t=x+y+z\}\). Verifier que \(H\) est un sous-espace vectoriel de \(\mathbb{R}^{4}\). En donner une base et la dimension.
|
||||||
|
|
||||||
|
**Exercice 10**: Soient \((E,+,\cdot)\) un \(\mathbb{R}\)-espace vectoriel et \(A,B,C\) trois sous-espaces vectoriels de \(E\).
|
||||||
|
|
||||||
|
1. Montrer que \((A\cap C)+(B\cap C)\subset(A+B)\cap C\). Donner un exemple dans \(\mathbb{R}^{2}\) pour lequel l'inclusion est stricte.
|
||||||
|
2. Montrer que, si \(A+B=A+C\), \(A\cap B=A\cap C\) et \(B\subset C\), alors \(B=C\).
|
||||||
|
|
||||||
|
**Exercice 11**: On considere l'application donnee par
|
||||||
|
|
||||||
|
1. Montrer que \(\varphi\) est une application lineaire. Determiner l'image par \(\varphi\) des vecteurs de la base canonique \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3}\}\) de \(\mathbb{R}^{3}\). Calculer \(\varphi(2\mathbf{e}_{1}+\mathbf{e}_{2}-\mathbf{e}_{3})\).
|
||||||
|
2. Determiner le noyau de \(\varphi\). En donner une base et preciser sa dimension.
|
||||||
|
|
||||||
|
3. L'application \(\varphi\) est-elle injective? surjective? bijective?
|
||||||
|
4. Soit \(\psi\) l'application lineaire donnee par \[\psi\colon \mathbb{R}^{2} \longrightarrow \mathbb{R}^{3}\] \[\left(\begin{array}{c}x\\ y\end{array}\right) \longmapsto \left(\begin{array}{c}x-y\\ x+y\\ x+2y\end{array}\right).\] Determiner \(\varphi\circ\psi\).
|
||||||
|
|
||||||
|
**Exercice 12**: On considere l'application donnee par
|
||||||
|
|
||||||
|
\[\varphi\colon \mathbb{R}^{3} \longrightarrow \mathbb{R}^{2}\] \[\left(\begin{array}{c}x\\ y\\ z\end{array}\right) \longmapsto \left(\begin{array}{c}y+z\\ x\end{array}\right)\]
|
||||||
|
|
||||||
|
ainsi que les vecteurs \(\mathbf{u}:=(1,2,3)^{t}\) et \(\mathbf{v}:=(1,1,1)^{t}\).
|
||||||
|
|
||||||
|
1. Montrer que \(\varphi\) est lineaire. Determiner \(\varphi(\mathbf{u})\), \(\varphi(\mathbf{v})\) et \(\varphi(\mathbf{u}-2\mathbf{v})\).
|
||||||
|
2. Determiner le noyau de \(\varphi\). En donner une base et preciser sa dimension.
|
||||||
|
3. Determiner l'image de \(\varphi\). En donner une base et preciser sa dimension.
|
||||||
|
|
||||||
|
**Exercice 13**: Soient \(E\) et \(F\) deux \(\mathbb{R}\)-espaces vectoriels et \(\varphi\) une application lineaire de \(E\) dans \(F\). Soit \(\mathcal{A}:=\{x_{1},\ldots,x_{m}\}\) une famille de vecteurs de \(E\).
|
||||||
|
|
||||||
|
1. Montrer que, si \(\mathcal{A}\) est liee, alors \(f(\mathcal{A})=\{\varphi(x_{1}),\ldots,\varphi(x_{m})\}\) est liee.
|
||||||
|
2. Montrer que, si \(\varphi(\mathcal{A})\) est libre, alors \(\mathcal{A}\) est libre.
|
||||||
|
3. Montrer que, si \(\mathcal{A}\) est libre et \(\varphi\) est injective, alors \(\varphi(\mathcal{A})\) est libre.
|
||||||
|
|
||||||
|
## 2 Solutions
|
||||||
|
|
||||||
|
**Solution de l'exercice 1**
|
||||||
|
|
||||||
|
1. Pour tout \(x\in E\), \(2\cdot x=(1+1)\cdot x=1\cdot x+1\cdot x=x+x\), ou l'on a utilise successivement les axiomes (II-2) et (II-4).
|
||||||
|
2. On a : \[\begin{array}{rcl}0_{\mathbb{K}}\cdot x&=&(0_{\mathbb{K}}2)\cdot x\\ &=&0_{\mathbb{K}}\cdot(2\cdot x)&\text{[d'apres l'axiome (II-3)]}\\ &=&0_{\mathbb{K}}\cdot(x+x)&\text{[d'apres la question (1)]}\\ &=&0_{\mathbb{K}}\cdot x+0_{\mathbb{K}}\cdot x.\end{array}\] En simplifiant (c'est-a-dire, en ajoutant \(-(0_{\mathbb{K}}\cdot x)\) des deux cotes), on obtient l'egalite \(0_{E}=0_{\mathbb{K}}\cdot x\).
|
||||||
|
3. D'apres la question (2), \(0_{E}=0_{\mathbb{K}}\cdot x=(1+(-1))\cdot x=(1\cdot x)+((-1)\cdot x)=x+((-1) \cdot x)\), ou la troisieme egalite resulte de l'axiome (II-2) et ou la derniere egalite resulte de l'axiome (II-4). On en deduit que \((-1)\cdot x\) est le symetrique de \(x\), c'est-a-dire, \(-x\).
|
||||||
|
|
||||||
|
**Solution de l'exercice 2**: Nous devons montrer que pour tous \(x,y\in F\) et pour tout \(\alpha\in\mathbb{R}\), \(x+\alpha y\in F\). Soient donc \(x,y\in F\) et \(\alpha\in\mathbb{R}\) quelconques. Par definition de l'intersection, pour tout \(k\in\{1,\ldots,m\}\), \(x,y\in F_{k}\). Comme \(F_{k}\) est un sous-espace vectoriel de \(E\) nous deduisons que
|
||||||
|
|
||||||
|
\[x+\alpha y\in F_{k},\]et ce pour tout \(k\in\{1,\ldots,m\}\). Donc \(x+\alpha y\) appartient a l'intersection des \(F_{k}\), c'est-a-dire, a \(F\).
|
||||||
|
|
||||||
|
**Solution de l'exercice 3** : Remarquons tout d'abord que \(F\) est non vide, puisque que
|
||||||
|
|
||||||
|
\[0_{E}=0\cdot x_{1}+\cdots+0\cdot x_{m}\in F.\]
|
||||||
|
|
||||||
|
Soient \(x,y\in F\) et \(\alpha\in\mathbb{R}\) quelconques. Alors \(x\) et \(y\) s'ecrivent
|
||||||
|
|
||||||
|
\[x=\alpha_{1}x_{1}+\cdots+\alpha_{m}x_{m}\quad\mbox{et}\quad y=\beta_{1}x_{1}+ \cdots+\beta_{m}x_{m},\]
|
||||||
|
|
||||||
|
avec \(\alpha_{1},\ldots,\alpha_{m},\beta_{1},\ldots,\beta_{m}\in\mathbb{R}\). Donc,
|
||||||
|
|
||||||
|
\[x+\alpha y = (\alpha_{1}x_{1}+\cdots+\alpha_{m}x_{m})+\alpha(\beta_{1}x_{1}+ \cdots+\beta_{m}x_{m})\] \[= (\alpha_{1}+\alpha\beta_{1})x_{1}+\cdots+(\alpha_{m}+\alpha\beta _{m})x_{m}.\]
|
||||||
|
|
||||||
|
Par consequent, \(x+\alpha y\) est une combinaison lineaire des vecteurs \(x_{1},\ldots,x_{m}\), c'est-a-dire, un element de \(F\).
|
||||||
|
|
||||||
|
**Solution de l'exercice 4** :
|
||||||
|
1. Supposons que \(A\subset B\), et montrons que tout element de \(\mbox{vect}\,A\) appartient a vect \(B\). Soit donc \(x\) quelconque dans \(\mbox{vect}\,A=\emptyset\), alors \(\mbox{vect}\,A=\{0\}\) et donc \(x\) est forcement le vecteur nul. Comme \(\mbox{vect}\,B\) est un sous-espace vectoriel, \(\mbox{vect}\,B\ni 0\) et l'on a bien \(\mbox{vect}\,A\subset\mbox{vect}\,B\). Si \(A\) est non vide, alors \[\exists p\in\mathbb{N}^{*},\ \exists x_{1},\ldots,x_{p}\in A,\ \exists\alpha_{1},\ldots, \alpha_{p}\in\mathbb{R}\colon\quad x=\alpha_{1}x_{1}+\cdots+\alpha_{p}x_{p}.\] Puisque \(A\subset B\), les \(x_{k}\) sont aussi dans \(B\), de sorte que \(x\) est une combinaison lineaire de vecteurs de \(B\), c'est-a-dire, un element de \(\mbox{vect}\,B\). On a donc encore \(\mbox{vect}\,A\subset\mbox{vect}\,B\).
|
||||||
|
2. Supposons que \(A=\mbox{vect}\,A\). Puisque \(\mbox{vect}\,A\) est un sous-espace vectoriel, il en est de meme de \(A\). Reciproquement, supposons que \(A\) soit un sous-espace vectoriel, et montrons que \(A=\mbox{vect}\,A\). Remarquons que tout element de \(A\) est une combinaison lineaire particuliere d'elements de \(A\) (prendre \(p=1\), \(\alpha_{1}=1\) et \(x_{1}=x\)). Donc on a clairement l'inclusion \(A\subset\mbox{vect}\,A\). De plus, si \(A\) est un sous-espace vectoriel, alors \(A\) est non vide. Soit alors \(x\in\mbox{vect}\,A\) : \[\exists p\in\mathbb{N}^{*},\ \exists x_{1},\ldots,x_{p}\in A,\ \exists\alpha_{1},\ldots,\alpha_{p}\in\mathbb{R}\colon\quad x= \alpha_{1}x_{1}+\cdots+\alpha_{p}x_{p}.\] Puisque \(A\) est stable par combinaison lineaire, \(x\in A\). On a donc aussi l'inclusion \(\mbox{vect}\,A\subset A\).
|
||||||
|
3. D'apres le point (1), \(\mbox{vect}\,A\subset\mbox{vect}\,B\subset\mbox{vect}\,F\). Or, \(\mbox{vect}\,F=F\) puisque \(F\) est un sous-espace vectoriel. De plus, \(\mbox{vect}\,A=F\) puisque \(A\) engendre \(F\). Finalement, on a : \[F\subset\mbox{vect}\,B\subset F,\] ce qui montre que \(\mbox{vect}\,B=F\). Autrement dit, \(B\) engendre \(F\).
|
||||||
|
|
||||||
|
**Solution de l'exercice 5** : On resout l'equation vectorielle \(\alpha\mathbf{e}_{1}+\beta\mathbf{e}_{2}+\gamma\mathbf{e}_{3}+\delta\mathbf{e}_ {4}=\mathbf{0}\). Ceci revient resoudre le systeme lineaire
|
||||||
|
|
||||||
|
\[\left\{\begin{array}{rcl}0&=&\alpha+\gamma+2\delta,\\ 0&=&\alpha+\beta+\delta,\\ 0&=&\alpha+2\beta-2\gamma,\\ 0&=&\alpha-\beta+3\gamma-\delta.\end{array}\right.\]
|
||||||
|
|
||||||
|
On trouve que la seule solution possible est \(\alpha=\beta=\gamma=\delta=0\). Donc la famille \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3},\mathbf{e}_{4}\}\) est libre, et puisque son cardinal est egal a la dimension de \(\mathbb{R}^{4}\), c'est une base de \(\mathbb{R}^{4}\).
|
||||||
|
|
||||||
|
**Solution de l'exercice 6**:
|
||||||
|
|
||||||
|
1. On resout l'equation vectorielle \(\alpha\mathbf{e}_{1}+\beta\mathbf{e}_{2}+\gamma\mathbf{e}_{3}+\delta\mathbf{e }_{4}=\mathbf{0}.\) Ceci revient resoudre le systeme lineaire \[\left\{\begin{array}{rcl}0&=&\alpha+\gamma+\delta,\\ 0&=&\alpha+\beta+\delta,\\ 0&=&\alpha+2\beta-2\gamma+2\delta,\\ 0&=&\alpha+\beta+3\gamma-2\delta.\end{array}\right.\] On trouve que ce systeme est equivalent au systeme \[\left\{\begin{array}{rcl}0&=&\alpha+\gamma+\delta,\\ 0&=&\beta-\gamma,\\ 0&=&\gamma-\delta.\end{array}\right.\] Ce systeme admet d'autres solutions que la solution nulle. On en deduit que \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3},\mathbf{e}_{4}\}\) n'est pas libre.
|
||||||
|
2. D'apres ce qui precede, le rang de la famille \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3},\mathbf{e}_{4}\}\) est inferieur ou egal a 3. On considere alors la famille \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3}\}.\) On verifie facilement qu'elle est libre, de sorte que le rang cherche est en fait egal a 3.
|
||||||
|
3. Pour que \(\mathbf{u}\) appartienne au _sev_ engendre par \(\{\mathbf{e}_{1},\mathbf{e}_{2},\mathbf{e}_{3},\mathbf{e}_{4}\}\), il faut que l'equation vectorielle \[\mathbf{u}=\alpha\mathbf{e}_{1}+\beta\mathbf{e}_{2}+\gamma\mathbf{e}_{3}+ \delta\mathbf{e}_{4}\] admette au moins une solution. On cherche donc a resoudre le systeme lineaire \[\left\{\begin{array}{rcl}1&=&\alpha+\gamma+\delta,\\ 1&=&\alpha+\beta+\delta,\\ a&=&\alpha+2\beta-2\gamma+2\delta,\\ b&=&\alpha+\beta+3\gamma-2\delta.\end{array}\right.\] On verifie que ce systeme est equivalent au systeme \[\left\{\begin{array}{rcl}1&=&\alpha+\gamma+\delta,\\ 0&=&\beta-\gamma,\\ a-1&=&-\gamma+\delta,\\ b-1&=&3\gamma-3\delta.\end{array}\right.\] En considerant les deux dernieres equations, on voit que le systeme n'a de solution que si \(b-1=-3(a-1)\), c'est-a-dire, si \(b+3a=4.\)
|
||||||
|
|
||||||
|
**Solution de l'exercice 7**:
|
||||||
|
|
||||||
|
1. Considerons l'equation \(\alpha c+\beta s=0\) dans \(\mathbb{R}^{\mathbb{R}}.\) Cette equation est equivalente a \[\forall x\in\mathbb{R},\quad\alpha\cos x+\beta\sin x=0.\] Les choix \(x=0\) et \(x=\pi/2\) donnent respectivement \(\alpha=0\) et \(\beta=0.\) La famille \(\{c,s\}\) est donc libre, et la dimension de \(T\) est egale a 2.
|
||||||
|
2. Puisque \(\cos(x+\alpha)=\cos x\cos\alpha-\sin x\sin\alpha,\) on voit que \[f=\cos\alpha\cdot c-\sin\alpha\cdot s\in T\] et que les coordonnees de \(f\) dans la base \(\{c,s\}\) de \(T\) sont donnees par le couple \((\cos\alpha,-\sin\alpha).\) De meme, \[g=\cos\beta\cdot c-\sin\beta\cdot s\in T\quad\mbox{et}\quad h=\cos\gamma \cdot c-\sin\gamma\cdot s\in T;\]les coordonnees de \(g\) et \(h\) dans la base \(\{c,s\}\) de \(T\) sont donnees respectivement par les couples \((\cos\beta,-\sin\beta)\) et \((\cos\gamma,-\sin\gamma)\). La famille \(\{f,g,h\}\) ne peut pas etre libre, puisque son cardinal est egal a 3 alors que la dimension de l'espace vectoriel \(T\) est egale a 2. Son rang vaut au plus 2 (car \(\dim T=2\)) et au moins 1 (car les fonctions \(f,g,h\) sont non nulles). Le rang est egal a 1 lorsque \(f,g,h\) sont colineaires, c'est-a dire lorsqu'il existe \(a\) et \(b\) dans \(\mathbb{R}\) tels que \(f=ag=bh\) ou, de maniere equivalente, lorsque \[\left(\begin{array}{c}\cos\alpha\\ -\sin\alpha\end{array}\right)=a\left(\begin{array}{c}\cos\beta\\ -\sin\beta\end{array}\right)=b\left(\begin{array}{c}\cos\gamma\\ -\sin\gamma\end{array}\right).\] Des equations \(\cos\alpha=a\cos\beta\) et \(\sin\alpha=a\sin\beta\) on tire, en les elevant au carre et en les sommant, que \(a^{2}=1\), c'est-a-dire, que \(a\in\{-1,1\}\). Si \(a=1\), alors \(\beta=\alpha+2k\pi\), et si \(a=-1\), alors \(\beta=\alpha+\pi+2k\pi\). En resume, \(f\) et \(g\) sont colineaires si et seulement si \(\beta\in\{\alpha\}+\pi\mathbb{Z}\). De meme, \(f\) et \(h\) sont colineaires si et seulement si \(\gamma\in\{\alpha\}+\pi\mathbb{Z}\). La famille \(\{f,g,h\}\) est donc de rang 1 lorsque \(\alpha\), \(\beta\) et \(\gamma\) different d'un multiple entier de \(\pi\) ; elle est de rang 2 dans le cas contraire.
|
||||||
|
3. Considerons l'equation \(\alpha f_{1}+\beta f_{2}+\gamma f_{3}=0\) dans \(\mathbb{R}^{\mathbb{R}}\), qui equivaut a la condition \[\forall x\in\mathbb{R},\quad\alpha f_{1}(x)+\beta f_{2}(x)+\gamma f_{3}(x)=0.\] Les choix \(x=a_{1}\), \(x=a_{2}\) et \(x=a_{3}\) donnent respectivement les equations \[\beta\left|a_{1}-a_{2}\right|+\gamma\left|a_{1}-a_{3}\right| = 0,\] \[\alpha\left|a_{2}-a_{1}\right|+\gamma\left|a_{2}-a_{3}\right| = 0,\] \[\alpha\left|a_{3}-a_{1}\right|+\beta\left|a_{3}-a_{2}\right| = 0.\] Posons \(a:=\left|a_{3}-a_{1}\right|\), \(b:=\left|a_{3}-a_{2}\right|\) et \(c:=\left|a_{1}-a_{2}\right|\). Le systeme d'equations precedent s'ecrit \[\left\{\begin{array}{ccl}0&=&a\alpha+b\beta,\\ 0&=&c\alpha+b\gamma,\\ 0&=&c\beta+a\gamma.\end{array}\right.\] En resolvant ce systeme lineaire, et en tenant compte du fait que \(a\), \(b\) et \(c\) sont non nuls, on voit que la seule solution possible est \(\alpha=\beta=\gamma=0\). On peut aussi ecrire le systeme sous forme matricielle, et remarquer, pour arriver a la meme conclusion, que la matrice \[\left[\begin{array}{ccc}a&b&0\\ c&0&b\\ 0&c&a\end{array}\right]\] a pour determinant le reel non nul \(-2abc\).
|
||||||
|
|
||||||
|
**Solution de l'exercice 8**:
|
||||||
|
|
||||||
|
1. La fonction nulle \(\nu\) (definie par \(\nu(x)=0\) pour tout \(x\in\mathbb{R}\)) appartient a \(\mathcal{A}\) et a \(\mathcal{B}\). Donc, \(\mathcal{A}\) et \(\mathcal{B}\) sont non vides. De plus, pour toutes fonctions \(f,g\in\mathcal{A}\) et tout reel \(\alpha\), la fonction \(f+\alpha g\) satisfait : \[\forall x\in\mathbb{R},\quad(f+\alpha g)(x)=f(x)+\alpha g(x)=f(-x)+\alpha g(-x)=( f+\alpha g)(-x).\] Par consequent, \(f+\alpha g\in\mathcal{A}\). Donc \(\mathcal{A}\) est un sous-espace vetoriel de \(\mathcal{C}_{0}(\mathbb{R})\). De meme, pour toutes fonctions \(f,g\in\mathcal{B}\) et tout reel \(\alpha\), la fonction \(f+\alpha g\) satisfait : \[\forall x\in\mathbb{R},\quad(f+\alpha g)(x)=f(x)+\alpha g(x)=-f(-x)-\alpha g(-x)=-( f+\alpha g)(-x).\]Par consequent, \(f+\alpha g\in\mathcal{A}\). Donc \(\mathcal{B}\) est un sous-espace vetoriel de \(\mathcal{C}_{0}(\mathbb{R})\). Soit maintenant \(f\) une fonction de \(\mathcal{A}\cap\mathcal{B}\). Alors, pour tout \(x\in\mathbb{R}\), \[f(x)=f(-x)\quad\mbox{et}\quad f(x)=-f(-x),\] ce qui montre que \(f(x)=0\). Donc \(f=\nu\). On en deduit que \(\mathcal{A}\cap\mathcal{B}=\{\nu\}=\{0_{\mathcal{C}_{0}(\mathbb{R})}\}\), et que \(\mathcal{A}\) et \(\mathcal{B}\) sont en somme directe.
|
||||||
|
2. Il est facile de voir que \(A\) et \(B\) contiennent le vecteur \(\mbox{nul}\ (0,0,0)\). De plus, si \((x,y,z)\) et \((x^{\prime},y^{\prime},z^{\prime})\) appartiennent a \(A\) et \(\alpha\in\mathbb{R}\), alors \((x,y,z)+\alpha(x^{\prime},y^{\prime},z^{\prime})=(x+\alpha x^{\prime},y+\alpha y ^{\prime},z+\alpha z^{\prime})\) satisfait \[(x+\alpha x^{\prime})+(y+\alpha y^{\prime})+(z+\alpha z^{\prime})=(x+y+z)+ \alpha(x^{\prime}+y^{\prime}+z^{\prime})=0.\] Donc \((x,y,z)+\alpha(x^{\prime},y^{\prime},z^{\prime})\in A\), et \(A\) est un sous-espace vectoriel de \(\mathbb{R}^{3}\). De meme, si \((x,y,z)\) et \((x^{\prime},y^{\prime},z^{\prime})\) appartiennent a \(B\) et \(\alpha\in\mathbb{R}\), alors \((x,y,z)+\alpha(x^{\prime},y^{\prime},z^{\prime})=(x+\alpha x^{\prime},y+\alpha y ^{\prime},z+\alpha z^{\prime})\) satisfait \[(x+\alpha x^{\prime})-(y+\alpha y^{\prime})+(z+\alpha z^{\prime})=(x-y+z)+ \alpha(x^{\prime}-y^{\prime}+z^{\prime})=0.\] Donc \((x,y,z)+\alpha(x^{\prime},y^{\prime},z^{\prime})\in B\), et \(B\) est un sous-espace vectoriel de \(\mathbb{R}^{3}\). Soit maintenant \((x,y,z)\) un vecteur de \(A\cap B\). Alors, \[x+y+z=0\quad\mbox{et}\quad x-y+z=0.\] Le vecteur \((1,0,-1)\) satisfait les deux equations ci-dessus. On voit donc que \(A\cap B\) n'est pas reduit a \(\{(0,0,0)\}\). Les sous-espaces \(A\) et \(B\) ne sont pas en somme directe.
|
||||||
|
|
||||||
|
**Solution de l'exercice 9**:
|
||||||
|
1. Il est facile de voir que le vecteur \((0,0,0)\) appartient a \(F\) et a \(G\). Donc \(F\) et \(G\) sont non vides. Soient \((x,x,x),(y,y,y)\in F\) et \(\alpha\in\mathbb{R}\). Alors \[(x,x,x)+\alpha(y,y,y)=(x+\alpha y,x+\alpha y,x+\alpha y)\in F.\] Donc \(F\) est un sous-espace vectoriel de \(\mathbb{R}^{3}\). Soient \((0,y,z),(0,y^{\prime},z^{\prime})\in G\) et \(\alpha\in\mathbb{R}\). Alors \[(0,y,z)+\alpha(0,y^{\prime},z^{\prime})=(0,y+\alpha y^{\prime},z+\alpha z^{ \prime})\in G.\] Donc \(G\) est un sous-espace vectoriel de \(\mathbb{R}^{3}\). On voit que \[F=\{x(1,1,1)|x\in\mathbb{R}\}=\mbox{vect}\{(1,1,1)\},\] \[G=\{y(0,1,0)+z(0,0,1)|x,y\in\mathbb{R}\}=\mbox{vect}\{(0,1,0),(0,0,1)\}.\] De plus, on verifie facilement que les familles \(\{(1,1,1)\}\) et \(\{(0,1,0),(0,0,1)\}\) sont libres. Elles forment donc des bases respectives de \(F\) et \(G\). On en deduit que \(\mbox{dim}\,F=1\) et \(\mbox{dim}\,G=2\). Enfin, si \((x,y,z)\in F\cap G\), alors \(x=y=z\) et \(x=0\). Donc \(F\cap G=\{(0,0,0)\}\), et \(F\) et \(G\) sont en somme directe.
|
||||||
|
2. On verifie facilement que \((0,0,0,0)\in H\), de sorte que \(F\neq\emptyset\). Soient \((x,y,z,t),(x^{\prime},y^{\prime},z^{\prime},t^{\prime})\in H\) et \(\alpha\in\mathbb{R}\). Alors, \((x,y,z,t)+\alpha(x^{\prime},y^{\prime},z^{\prime},t^{\prime})=(x+\alpha x^{ \prime},y+\alpha y^{\prime},z+\alpha z^{\prime},t+\alpha t^{\prime})\) satisfait : \[x+\alpha x^{\prime}=2y-z+\alpha(2y^{\prime}-z^{\prime})=2(y+\alpha y^{\prime})-( z+\alpha z^{\prime}),\] \[t+\alpha t^{\prime}=x+y+z+\alpha(x^{\prime}+y^{\prime}+z^{\prime})=(x+\alpha x^{\prime})+(y+\alpha y ^{\prime})+(z+\alpha z^{\prime}),\] ce qui montre que \((x,y,z,t)+\alpha(x^{\prime},y^{\prime},z^{\prime},t^{\prime})\in H\). Donc \(H\) est un sous-espace vectoriel de \(\mathbb{R}^{4}\). De plus, \[H = \{(2y-z,y,z,x+y+z)|x,y,z\in\mathbb{R}\}\] \[= \{x(0,0,0,1)+y(2,1,0,1)+z(-1,0,1,1)|x,y,z\in\mathbb{R}\}\] \[= \mbox{vect}\{(0,0,0,1),(2,1,0,1),(-1,0,1,1)\}.\]Considerons l'equation vectorielle \(\alpha(0,0,0,1)+\beta(2,1,0,1)+\gamma(-1,0,1,1)=(0,0,0,0)\). Cette equation equivaut au systeme \[\left\{\begin{array}{rcl}0&=&2\beta+\gamma\\ 0&=&2\beta\\ 0&=&\gamma\\ 0&=&\alpha+\beta+\gamma\end{array}\right.\] dont l'unique solution est \(\alpha=\beta=\gamma=0\). La famille \(\{(0,0,0,1),(2,1,0,1),(-1,0,1,1)\}\) est donc libre, et c'est une base de \(H\).
|
||||||
|
|
||||||
|
**Solution de l'exercice 10**:
|
||||||
|
1. Soit \(x\in(A\cap C)+(B\cap C)\). Alors \(x=a+b\) avec \(a\in A\cap C\) et \(b\in B\cap C\). Puisque \(a\in C\) et \(b\in C\) et \(C\) est un sev, \(a+b\in C\). Donc \(x\) appartient a \(A+B\) et a \(C\). Dans \(\mathbb{R}^{2}\), Si l'on prend \(A=\mbox{vect}\{e_{1}\}\), \(B=\mbox{vect}\{e_{2}\}\) et \(C=\mbox{vect}\{e_{1}+e_{2}\}\), ou \(\{e_{1},e_{2}\}\) est la base canonique, alors \[(A\cap C)+(B\cap C)=\{0\}\cap\{0\}=\{0\}\quad\mbox{et}\quad(A+B)\cap C=\mathbb{ R}^{2}\cap C=C.\]
|
||||||
|
2. Puisque \(B\subset C\), il suffit de montrer que \(C\subset B\). Soit donc \(x\in C\). Puisque \(0_{E}\in A\), \(x=0_{E}+x\in A+C\). Puisque \(A+C=A+B\), on peut ecrire \(x=a+b\) avec \(a\in A\) et \(b\in B\). Maintenant, \(a=x-b\), ou \(x\in C\) et \(x\in B\subset C\), et puisque \(C\) est un sev, \(a\in C\). Donc \(a\in A\cap C=B\cap C\). Donc \(a\in B\). Finalement, \(x=a+b\) avec \(a\in B\) et \(b\in B\). Puisque \(B\) est un sev, \(x\in B\).
|
||||||
|
|
||||||
|
**Solution de l'exercice 11**:
|
||||||
|
1. Verifions que \(\varphi\) est lineaire : \[\varphi\left(\alpha\left(\begin{array}{c}x\\ y\\ z\end{array}\right)+\beta\left(\begin{array}{c}x^{\prime}\\ y^{\prime}\\ z^{\prime}\end{array}\right)\right)\] \[= \varphi\left(\begin{array}{c}\alpha x+\beta x^{\prime}\\ \alpha y+\beta y^{\prime}\\ \alpha z+\beta z^{\prime}\end{array}\right)\] \[= \left(\begin{array}{c}-(\alpha x+\beta x^{\prime})+2(\alpha y+ \beta y^{\prime})+2(\alpha z+\beta z^{\prime})\\ -8(\alpha x+\beta x^{\prime})+7(\alpha y+\beta y^{\prime})+4(\alpha z+\beta z^ {\prime})\\ -13(\alpha x+\beta x^{\prime})+5(\alpha y+\beta y^{\prime})+8(\alpha z+\beta z ^{\prime})\end{array}\right)\] \[= \alpha\left(\begin{array}{c}-x+2y+2z\\ -8x+7y+4z\\ -13x+5y+8z\end{array}\right)+\beta\left(\begin{array}{c}-x^{\prime}+2y^{ \prime}+2z^{\prime}\\ -8x^{\prime}+7y^{\prime}+4z^{\prime}\\ -13x^{\prime}+5y^{\prime}+8z^{\prime}\end{array}\right)\] \[= \alpha\varphi\left(\begin{array}{c}x\\ y\\ z\end{array}\right)+\beta\varphi\left(\begin{array}{c}x^{\prime}\\ y^{\prime}\\ z^{\prime}\end{array}\right).\]
|
||||||
|
|
||||||
|
Ensuite,
|
||||||
|
|
||||||
|
\[\varphi(\mathbf{e}_{1})=\left(\begin{array}{c}-1\\ -8\\ -13\end{array}\right),\quad\varphi(\mathbf{e}_{2})=\left(\begin{array}{c}2\\ 7\\ 5\end{array}\right),\quad\varphi(\mathbf{e}_{3})=\left(\begin{array}{c}2\\ 4\\ 8\end{array}\right).\]
|
||||||
|
|
||||||
|
Enfin, \(2\mathbf{e}_{1}+\mathbf{e}_{2}-\mathbf{e}_{3}=(2,1,-1)^{t}\), de sorte que
|
||||||
|
|
||||||
|
\[\varphi(2\mathbf{e}_{1}+\mathbf{e}_{2}-\mathbf{e}_{3}) = 2\varphi(\mathbf{e}_{1})+\varphi(\mathbf{e}_{2})-\varphi(\mathbf{e }_{3})\] \[= 2\left(\begin{array}{c}-1\\ -8\\ -13\end{array}\right)+\left(\begin{array}{c}2\\ 7\\ 5\end{array}\right)-\left(\begin{array}{c}2\\ 4\\ 8\end{array}\right)\;=\;\left(\begin{array}{c}-2\\ -13\\ -29\end{array}\right).\]2. On cherche les solutions de l'equation vectorielle \(\varphi(\mathbf{x})=\mathbf{0}\). En notant \(\mathbf{x}=(x,y,z)^{t}\), on obtient le systeme \[\left\{\begin{array}{rcl}0&=&-x+2y+2z,\\ 0&=&-8x+7y+4z,\\ 0&=&-13x+5y+8z.\end{array}\right.\] La seule solution de ce systeme est le vecteur nul, ce que l'on peut voir aussi en calculant le determinant de la matrice \[\left[\begin{array}{rrr}-1&2&2\\ -8&7&4\\ -13&5&8\end{array}\right].\] Donc \(\ker\varphi=\{\mathbf{0}\}\), l'unique base de \(\ker\varphi\) est \(\emptyset\), et sa dimension est nulle.
|
||||||
|
3. Puisque \(\ker\varphi=\{\mathbf{0}\}\), l'application \(\varphi\) est injective. Puisque les dimensions des espaces de depart et d'arriveee sont toutes deux egales a 3, \(\varphi\) est aussi surjective, et donc bijective.
|
||||||
|
4. En notant \(\mathbf{x}=(x,y)^{t}\), on a : \[(\varphi\circ\psi)(\mathbf{x}) = \varphi(\psi)(\mathbf{x}))\] \[= \varphi\left(\begin{array}{c}x-y\\ x+y\\ x+2y\end{array}\right)\] \[= \left(\begin{array}{c}-(x-y)+2(x+y)+2(x+2y)\\ -8(x-y)+7(x+y)+4(x+2y)\\ -13(x-y)+5(x+y)+8(x+2y)\end{array}\right)\] \[= \left(\begin{array}{c}3x+7y\\ 3x+23y\\ 34y\end{array}\right).\]
|
||||||
|
|
||||||
|
**Solution de l'exercice 12** :
|
||||||
|
|
||||||
|
1. Verifions que \(\varphi\) est lineaire : \[\varphi\left(\alpha\left(\begin{array}{c}x\\ y\\ z\end{array}\right)+\beta\left(\begin{array}{c}x^{\prime}\\ y^{\prime}\\ z^{\prime}\end{array}\right)\right)\] \[= \varphi\left(\begin{array}{c}\alpha x+\beta x^{\prime}\\ \alpha y+\beta y^{\prime}\\ \alpha z+\beta z^{\prime}\end{array}\right)\] \[= \left(\begin{array}{c}(\alpha y+\beta y^{\prime\prime})+( \alpha z+\beta z^{\prime})\\ \alpha x+\beta x^{\prime}\end{array}\right)\] \[= \alpha\left(\begin{array}{c}y+z\\ x\end{array}\right)+\beta\left(\begin{array}{c}y^{\prime}+z^{\prime}\\ x^{\prime}\end{array}\right)\] \[= \alpha\varphi\left(\begin{array}{c}x\\ y\\ z\end{array}\right)+\beta\varphi\left(\begin{array}{c}x^{\prime}\\ y^{\prime}\\ z^{\prime}\end{array}\right).\] Ensuite, \(\varphi(\mathbf{u})=(5,1)^{t}\), \(\varphi(\mathbf{v})=(2,1)^{t}\) et \[\varphi(\mathbf{u}-2\mathbf{v})=\left(\begin{array}{c}5\\ 1\end{array}\right)-2\left(\begin{array}{c}2\\ 1\end{array}\right)=\left(\begin{array}{c}1\\ -1\end{array}\right).\]2. Le vecteur \((x,y,z)^{t}\) appartient a ker \(\varphi\) si et seulement si \(y+z=0\) et \(x=0\). C'est donc l'ensemble des vecteurs de la forme \((0,y,-y)^{t}\) ou \(y\in\mathbb{R}\) : \[\ker\varphi=\left\{\left(\begin{array}{c}0\\ y\\ -y\end{array}\right)\Bigg{|}\ y\in\mathbb{R}\right\}=\text{vect}\left\{\left( \begin{array}{c}0\\ 1\\ -1\end{array}\right)\right\}.\] Le sous-espace vectoriel ker \(\varphi\) est donc de dimension \(1\), et admet pour base le singleton \(\{(0,1,-1)^{t}\}\).
|
||||||
|
3. D'apres le theoreme du rang, \(\dim\mathbb{R}^{3}=\operatorname{rg}\varphi+\dim\ker\varphi\), ce qui implique que \(\operatorname{rg}\varphi=2\). On en deduit que \(\operatorname{im}\varphi=\mathbb{R}^{2}\) et que n'importe quelle base de \(\mathbb{R}^{2}\), par exemple la base canonique, est une base de \(\operatorname{im}\varphi\).
|
||||||
|
|
||||||
|
**Solution de l'exercice 13**
|
||||||
|
|
||||||
|
1. Si \(\mathcal{A}\) est liee, il existe \(\alpha_{1},\ldots,\alpha_{m}\) non tous nuls tels que \(\alpha_{m}x_{m}+\cdots+\alpha_{m}x_{m}=0\). Mais alors \[\alpha_{1}\varphi(x_{1})+\cdots+\alpha_{m}\varphi(x_{m})=\varphi(\alpha_{1}x_ {1}+\cdots+\alpha_{m}x_{m})=0,\] et puisqu'au moins un des \(\alpha_{j}\) est non nul, non voyons que \(\{\varphi(x_{1}),\ldots,\varphi(x_{m})\}\) est liee.
|
||||||
|
2. Ce point se deduit du precedent par contre-apposition.
|
||||||
|
3. Supposons \(\mathcal{A}\) libre et \(\varphi\) injective, et considerons l'equation \(\alpha_{1}\varphi(x_{1})+\cdots+\alpha_{m}\varphi(x_{m})=0\). Le membre de gauche n'est autre que \(\varphi(\alpha_{1}x_{1}+\cdots+\alpha_{m}x_{m})\), et puisque \(\varphi\) injective, on a necessairement \(\alpha_{1}x_{1}+\cdots+\alpha_{m}x_{m}=0\). Puisque \(\mathcal{A}\) est libre, on deduit de cette derniere equation que \(\alpha_{1}=\ldots=\alpha_{m}=0\). Donc \(\varphi(\mathcal{A})\) est libre.
|
BIN
documents/pdfs/2009L1feuille2bis.pdf
Normal file
BIN
documents/pdfs/2009L1feuille2bis.pdf
Normal file
Binary file not shown.
BIN
documents/pdfs/The-UK-Constitution.pdf
Normal file
BIN
documents/pdfs/The-UK-Constitution.pdf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,9 +0,0 @@
|
||||||
PDF File,output,flag,username,timestamp
|
|
||||||
flagged\PDF File\bc51931986aa4ff95e72\integration.pdf,"'
|
|
||||||
<iframe
|
|
||||||
src=""http://localhost:8000/pdfs/integration.pdf""
|
|
||||||
:width=""1000px""
|
|
||||||
:height=""2000px""
|
|
||||||
frameborder=""0""
|
|
||||||
></iframe>
|
|
||||||
",,,2024-04-15 02:34:48.167890
|
|
|
|
@ -7,6 +7,7 @@ from langchain_community.embeddings.huggingface import HuggingFaceEmbeddings
|
||||||
|
|
||||||
from backend.vector_db_manager import VectorDbManager
|
from backend.vector_db_manager import VectorDbManager
|
||||||
from backend.inference import InferenceInstance
|
from backend.inference import InferenceInstance
|
||||||
|
from backend.pdf_to_mmd import pdf_to_mmd
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,8 +23,6 @@ port = get_accessible_port()
|
||||||
|
|
||||||
|
|
||||||
# Launch a simple HTTP server to serve the PDF files
|
# Launch a simple HTTP server to serve the PDF files
|
||||||
|
|
||||||
|
|
||||||
def start_server():
|
def start_server():
|
||||||
command = ['python', '-m', 'http.server', f"{port}"]
|
command = ['python', '-m', 'http.server', f"{port}"]
|
||||||
# Set the working directory to the documents folder to serve the PDF files
|
# Set the working directory to the documents folder to serve the PDF files
|
||||||
|
@ -57,12 +56,19 @@ def bot(history):
|
||||||
global user_message_global, doc_path
|
global user_message_global, doc_path
|
||||||
|
|
||||||
if doc_path != "":
|
if doc_path != "":
|
||||||
print("FOUND DOC_PATH")
|
print(f"FOUND DOC_PATH {doc_path}")
|
||||||
vector_db_manager.create_vector_store_from_pdf(doc_path)
|
doc_extension = doc_path.split(".")[-1]
|
||||||
|
if doc_extension == "mmd":
|
||||||
|
vector_db_manager.create_vector_store_from_latex(Path(doc_path))
|
||||||
|
elif doc_extension == "pdf":
|
||||||
|
vector_db_manager.create_vector_store_from_pdf(doc_path)
|
||||||
|
else:
|
||||||
|
print(f"Unsupported extension: {doc_extension}")
|
||||||
else:
|
else:
|
||||||
print("NOT FOUND DOC_PATH")
|
print("NOT FOUND DOC_PATH")
|
||||||
|
|
||||||
bot_message = inference_instance.get_next_token(user_message_global, doc_path.split("\\")[-1])
|
doc_name = Path(doc_path).stem + ".mmd" if math_checkbox.value else Path(doc_path).name
|
||||||
|
bot_message = inference_instance.get_next_token(user_message_global, doc_name)
|
||||||
history[-1][1] = ""
|
history[-1][1] = ""
|
||||||
for message in bot_message:
|
for message in bot_message:
|
||||||
history[-1][1] = message
|
history[-1][1] = message
|
||||||
|
@ -70,11 +76,21 @@ def bot(history):
|
||||||
yield history
|
yield history
|
||||||
|
|
||||||
|
|
||||||
def update_path(p):
|
def update_path(p, checked):
|
||||||
"""Update the global variable doc_path with the selected PDF path"""
|
"""Update the global variable doc_path with the selected PDF path"""
|
||||||
|
print("Updating path")
|
||||||
global doc_path
|
global doc_path
|
||||||
doc_path = str(p)
|
name = Path(p).name
|
||||||
print(f"Selected PDF path: {doc_path}")
|
stem = Path(p).stem
|
||||||
|
if checked:
|
||||||
|
if not (Path(r"../documents/mmds") / (stem + ".mmd")).exists():
|
||||||
|
print(f"Converting {name} to MMD")
|
||||||
|
pdf_to_mmd(r"../documents/pdfs/" + name)
|
||||||
|
print(f"Selected DOC path: {stem}.mmd")
|
||||||
|
doc_path = r"../documents/mmds/" + stem + ".mmd"
|
||||||
|
else:
|
||||||
|
print(f"Selected DOC path: {name}")
|
||||||
|
doc_path = str(p)
|
||||||
|
|
||||||
|
|
||||||
def pdf_viewer(pdf_file):
|
def pdf_viewer(pdf_file):
|
||||||
|
@ -107,6 +123,7 @@ with gr.Blocks() as main_tab:
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
with gr.Column(scale=12):
|
with gr.Column(scale=12):
|
||||||
file_input = gr.File(label="Select a PDF file")
|
file_input = gr.File(label="Select a PDF file")
|
||||||
|
math_checkbox = gr.Checkbox(label="Enable math mode (your pdf file will be converted to some latex-like format for the chatbot to understand it better)")
|
||||||
|
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
with gr.Group():
|
with gr.Group():
|
||||||
|
@ -117,7 +134,7 @@ with gr.Blocks() as main_tab:
|
||||||
)
|
)
|
||||||
|
|
||||||
file_input.change(pdf_viewer, inputs=file_input, outputs=pdf_output)
|
file_input.change(pdf_viewer, inputs=file_input, outputs=pdf_output)
|
||||||
file_input.upload(update_path, inputs=file_input)
|
file_input.upload(update_path, inputs=[file_input, math_checkbox])
|
||||||
|
|
||||||
|
|
||||||
# Define options tab
|
# Define options tab
|
||||||
|
@ -129,6 +146,21 @@ with gr.Blocks() as options_tab:
|
||||||
gr.Textbox(label="Options", scale=2)
|
gr.Textbox(label="Options", scale=2)
|
||||||
|
|
||||||
|
|
||||||
app = gr.TabbedInterface([main_tab, options_tab], ["Main", "Options"])
|
# Define conversion tab
|
||||||
|
with gr.Blocks() as conversion_tab:
|
||||||
|
with gr.Column():
|
||||||
|
file_input = gr.File(label="Select a PDF file to convert to MMD")
|
||||||
|
html_output = gr.HTML(label="Output")
|
||||||
|
|
||||||
|
def upload_func(file_input):
|
||||||
|
name = Path(file_input).name
|
||||||
|
file_path = fr"../documents/pdfs/{name}"
|
||||||
|
pdf_to_mmd(file_path)
|
||||||
|
|
||||||
|
|
||||||
|
file_input.upload(upload_func, inputs=file_input)
|
||||||
|
|
||||||
|
|
||||||
|
app = gr.TabbedInterface([main_tab, options_tab, conversion_tab], ["Main", "Options", "Conversion"])
|
||||||
app.queue()
|
app.queue()
|
||||||
app.launch()
|
app.launch()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue