Source code for Mes_fctions_generalistes

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 17 19:11:52 2022

@author: jlebovits
"""

from __future__ import division
import sys

import src.scripts.Mes_fctions.Mes_fctions_deterministes
from src.scripts.Mes_fctions.Mes_fctions_deterministes import * 

import math
from random import uniform, Random, randrange, randint

#import numpy as np
#import numpy.random as npr 
from sympy import *
from sympy.stats import *

# from sympy import Eq, simplify, S, Symbol, Rational, binomial, expand_func
from sympy.stats import P, E, variance, Die, Normal, DiscreteUniform, Bernoulli, sample, Binomial, density,  Normal, sample_iter, given
from sympy import Piecewise, log, piecewise_fold
from sympy import S

from sympy.abc import x, y
  
import numpy as np
import numpy.random as npr 

import sys
import copy
from copy import deepcopy



#inf=float("inf")


#print('toto')

#

[docs] def generalistes() : chaine = "generalistes Ok" return chaine
#========================================================================================== #========================================================================================== ## New Function ######## #========================================================================================== #==========================================================================================
[docs] def Replace(A, alpha, beta): "Remplace alpha par beta dans A, qui sont tous les 3 de type string" A = str(A) alpha = str(alpha) beta = str(beta) A = A.replace(alpha, beta) return A
#========================================================================================== #### Début des essais ######## #========================================================================================== # A = 'iuzerzidu' # alpha = 'z' # beta = 'q' # newA = Replace(A, alpha, beta) # print('A = ', newA, '\n') #========================================================================================== #### Fin des essais ######## #========================================================================================== #====================================================================================== #====================================================================================== # New fction #====================================================================================== #======================================================================================
[docs] def prog_remplacement_mots_dans_une_liste(L, alpha, beta): # ============================================================================= """ alpha is replaced by beta in L -whether L is a list (of string) or a string -whether alpha and beta are a list (of string) or a string If L is a list liste L = [L[1], L[2], ..., L[n]] such that L[i] are strings, then this script returns List L where in each string L[i], every word or character in alpha has been repladed by the corresponding word or caracter in beta """ # ============================================================================= Dico = {} if type(L) is str: if type(alpha) is str and type(beta) is str: Dico[alpha] = beta # for word, initial in Dico.items(): # L = L.replace(word.lower(), initial) else: # donc alpha et beta sont des listes if type(alpha) is list and type(beta) is list and len(alpha) == len(beta): for j in range(0,len(alpha),1): Dico[alpha[j]] = beta[j] # for word, initial in Dico.items(): # L = L.replace(word.lower(), initial) else: # donc alpha et beta ne sont ni des listes ni des strings raise Exception("Pbm with the type or the lenght of alpha or beta") for word, initial in Dico.items(): L = L.replace(word.lower(), initial) M = L else: if type(L) is not list: raise Exception("L is neither a string nor a list.") else: # L est donc une liste if type(alpha) is str and type(beta) is str: Dico[alpha] = beta else: if type(alpha) is list and type(beta) is list and len(alpha) == len(beta): for j in range(0,len(alpha),1): Dico[alpha[j]] = beta[j] else: # donc alpha et beta ne sont ni des listes ni des strings raise Exception("Pbm with the type or the lenght of alpha or beta") M = copy.deepcopy(L) for i in range(0,len(M),1): for word, initial in Dico.items(): M[i] = M[i].replace(word.lower(), initial) return M
# ============================================================================= # Début des essais # ============================================================================= # lp = "\\"+'left(' # rp = "\\"+'right)' # lb = "\\"+'left[' # lbnew = "\\"+'left(' # rb = "\\"+'right]' # rbnew = "\\"+'right)' # L= ['^{0}', '^{1}', lp, rp, lb, rb] # alpha = ['^{0}', '^{1}', lp, rp, lb, rb] # beta = ["", "", "", "", lbnew, rbnew] # Dic = {} # for k in range(0,len(alpha),1): # Dic[alpha[k]] = beta[k] # print('Dic =' , Dic, '\n') # Tout = ['2 \\left(\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right)^{3}'] # print('Tout =', Tout, '\n') # UU = prog_remplacement_mots_dans_une_liste_v3(Tout, alpha, beta) # print('UU =', UU, '\n') # U = ['2 \\left(\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right]\\right)^{3}', '- 3 \\left(\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right]\\right)^{2}', '+4 \\left(\\left[\\begin{matrix}1 & 2\\\\3 & 4\\end{matrix}\\right]\\right)^{1}', '- 5 \\left(\\left[\\begin{matrix}1 & 0\\\\0 & 1\\end{matrix}\\right]\\right)^{0}'] # W = prog_remplacement_mots_dans_une_liste_v3(U, alpha, beta) # print('W =', W, '\n') # S = prog_remplacement_mots_dans_une_liste_v3(U, 'a', 'b') # print('U sans a =', S, '\n') # T_1 = 'aaoefirjeorij' # T_2 = 'a' # T_3 = ['oazeidazeoij'] # S_T_1 = prog_remplacement_mots_dans_une_liste_v3(T_1, 'a', 'b') # S_T_2 = prog_remplacement_mots_dans_une_liste_v3(T_2, 'a', 'b') # S_T_3 = prog_remplacement_mots_dans_une_liste_v3(T_3, 'a', 'b') # print('T_1 sans a =', S_T_1, '\n') # print('T_2 sans a =', S_T_2, '\n') # print('T_3 sans a =', S_T_3, '\n') # ============================================================================= # Fin des essais # =============================================================================
[docs] def Reverse_List(L): l = len(L) U = [None]*l for i in range(0,l,1): U[i] = L[l-1-i] return U
# L = [1, 1, 7, -4] # U = Reverse_List(L) # print('Reverse_List([1, 1, 7, -4]) = ', U , '\n') ############################################################################################################# #### Début des essais ######## ############################################################################################################# #print('randnbresstrictpositifs(n,p) = ', randnbresstrictpositifs(4,1,5)) ############################################################################################################# #### Fin des essais ######## ############################################################################################################# #Manque le test de list ou de string!!!! ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### Nelle fction ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### #######
[docs] def find_min_index(lst): min_value = min(lst) min_index = lst.index(min_value) return min_index
[docs] def find_max_index(lst): max_value = max(lst) min_index = lst.index(max_value) return min_index
# Create the list my_list = [50, 2, 19, 11, 27,2] min_index = find_min_index(my_list) max_index = find_max_index(my_list) #print(" The minimum index position:\n", min_index, '\n') #print(" The maximum index position:\n", max_index, '\n') ############################################################################################################# #### Début des essais ######## ############################################################################################################# #print('randnbresstrictpositifs(n,p) = ', randnbresstrictpositifs(4,1,5)) ############################################################################################################# #### Fin des essais ######## ############################################################################################################# ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### Nelle fction ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ############################################################################################################# #### Début des essais ######## ############################################################################################################# #print('randnbresstrictpositifs(n,p) = ', randnbresstrictpositifs(4,1,5)) ############################################################################################################# #### Fin des essais ######## ############################################################################################################# ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### Nelle fction ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ############################################################################################################# #### Début des essais ######## ############################################################################################################# #print('randnbresstrictpositifs(n,p) = ', randnbresstrictpositifs(4,1,5)) ############################################################################################################# #### Fin des essais ######## ############################################################################################################# ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### Nelle fction ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ############################################################################################################# #### Début des essais ######## ############################################################################################################# #print('randnbresstrictpositifs(n,p) = ', randnbresstrictpositifs(4,1,5)) ############################################################################################################# #### Fin des essais ######## ############################################################################################################# ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### Nelle fction ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ############################################################################################################# #### Début des essais ######## ############################################################################################################# #print('randnbresstrictpositifs(n,p) = ', randnbresstrictpositifs(4,1,5)) ############################################################################################################# #### Fin des essais ######## ############################################################################################################# ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### Nelle fction ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ############################################################################################################# #### Début des essais ######## ############################################################################################################# #print('randnbresstrictpositifs(n,p) = ', randnbresstrictpositifs(4,1,5)) ############################################################################################################# #### Fin des essais ######## ############################################################################################################# ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### Nelle fction ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ############################################################################################################# #### Début des essais ######## ############################################################################################################# #print('randnbresstrictpositifs(n,p) = ', randnbresstrictpositifs(4,1,5)) ############################################################################################################# #### Fin des essais ######## ############################################################################################################# ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### Nelle fction ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ####### ############################################################################################################# #### Début des essais ######## ############################################################################################################# #print('randnbresstrictpositifs(n,p) = ', randnbresstrictpositifs(4,1,5)) ############################################################################################################# #### Fin des essais ######## #############################################################################################################