sandro le 04/08/2011 à 15:12
Bonjour/bonsoir, je vous présente ici la première version de mon projet pour le zContest 2011.
Voici la présentation française (celle du site du concours)
Citation
Calcul exact par étapes Auteur : sandro Langage / Catégorie : TI-Basic Type : Programme
Compatible : TI 82 STATS, TI 83, TI 83 Plus, TI 84 Plus.
Voci un programme de calcul exact. Il s'effectue par étapes, chacune étant affichée (pratique pour les devoirs
de maths quand le prof demande les étapes intermédiaires).
Pour l'insant, ce programme ne gère que des résultats rationnels.
Les oppérations admises pour l'instant sont : l'addition, la soustraction, la multiplication, la division,
le carré, le cube, et l'inverse. Le programme gère également les parrenthèses et les fractions (sous
la forme {entier relatif:entier positif} ). Les constantes et autres oppérations ne son t pas accèptées pour l'instant.
A la fin, le programme affiche le résultat arrondit.
Pour afficher l'étape suivante, appuyez sur [entrer] ( [enter] ); si rien ne s'affiche de plus, c'est que la TI n'a
pas encore trouvée l'étape suivante.
Sandro
Voci les liens :
CALCAUTO.83p
_theta__theta_ADD.83p
_theta__theta_ADDF.83p
_theta__theta_CARCU.83p
_theta__theta_CARCUF.83p
_theta__theta_DETBC.83p
_theta__theta_DIV.83p
_theta__theta_DIVFPN.83p
_theta__theta_DIVPF.83p
_theta__theta_INV.83p
_theta__theta_MULT.83p
_theta__theta_MULTF.83p
_theta__theta_SIGNE.83p
_theta_DELPAR.83p
_theta_MONONIV.83p
_theta_NIVPAR.83p
Voici les codes :
Code
programmeCALCAUTO (programme à lancer, veille à alterner entre le programme de calcul, et celui de supression de parrenthèses (pour l'instant très court, mais qui ce compliquera quand je rajouterrais les racines).
0 -> K
" " -> Str8
"{E,E -> L6
"{1,2 -> L5
Input "CALCUL:",Str0
Str0 -> Str6
" "+Str0+" " -> Str0
" " -> Str7
ClrHome
While Str7=/=Str0
Str0 -> Str7
prgm[théta]MONONIV
prgm[théta]DELPAR
End
sub(Str0,3,length(Str0)-4 -> Str9
1 -> A
While A
inString(Str9,"{",A -> A
If A:Then
"("+sub(Str9,A+1,length(Str9)-A -> Str2
If A=/=1
sub(Str9,1,A-1)+Str2 -> Str2
Str2 -> Str9
End
End
1 -> A
While A
inString(Str9,":",A+1 -> A
If A
sub(Str9,1,A-1)+"/"+sub(Str9,A+1,length(Str9)-A -> Str9
End
1 -> A
While A
inString(Str9,"}",A+1 -> A
If A
Then
sub(Str9,1,A-1)+")" -> Str2
If A=/=length(Str9
Str2+sub(Str9,A+1,length(Str9)-A -> Str2
Str2 -> Str9
End
Pause expr(Str9
Code
programme[théta]NIVPAR (trouve quels sont les "niveaux de parrenthèses" (combien siont ouverte à tel endroit)
{0 -> L1
length(Str0 -> L
L -> dim(L1
For(A,1,L
sub(Str0,A,1 -> Str2
If Str2=")
-1 -> L1(A+1
If inString("(sin(cos(tan(sin-1(cos-1(tan-1([e^(][10^(][racine carré)[racine cube]Ýð(",Str2 //les crochets servent juste pour signaler qu'il s'agit d'un seul et même symbol
1 -> L1(A+1
End
cumSum(L1 -> L2[/pre]
[pre]programme[théta]MONONIV (gère les sous-programmes propre à chaque oppération)
3 -> A
While A+3[inférieur ou égal]length(Str0
If Str8=/=Str0
Then
If K
Pause
1 -> K
Disp sub(Str0,3,length(Str0)-4
Str0 -> Str8
End
A -> B
A+1 -> A
A+1 -> C
1 -> [théta]
sub(Str0,A,1 -> Str9
prgm[théta][théta]SIGNE
If Str9="+
prgm[théta][théta]ADD
If Str9="*
prgm[théta][théta]MULT
If Str9="[carré]
DelVar [théta]prgm[théta][théta]CARCU
If Str9="/
prgm[théta][théta]DIV
If Str9="[^-1]
prgm[théta][théta]INV
If Str9="[cube]
prgm[théta][théta]CARCU
End
Code
programme[théta]DELPAR
If inString(Str0,"("
Then
1ü (
) B
While B
inString(Str0,"(",B+1 -> B
If B:B -> A
End
A -> B
1 -> C
B+1 -> A
While C
A+1 -> A
sub(Str0,A,1 -> Str2
If Str2=")
C-1 -> C
If inString("(sin(cos(tan(sin-1(cos-1(tan-1([10^(][e^(][racine carré][racine cube]",Str2
C+1 -> C
End
A -> C
sub(Str0,B+1,C-B-1 -> Str4
1 -> D
For(A,1,length(Str4
If not(inString("[moins des relatifs]0.123456789{:}",sub(Str4,A,1
0 -> D
If D
Then
sub(Str0,1,B-1)+Str4+sub(Str0,C+1,length(Str0)-C -> Str0
Return
End
sub(Str0,A-1,1 -> Str2
sub(Str0,B+1,1 -> Str3
Code
programme[théta][théta]ADD (addition-soustraction)
"^/*) -> Str1
"^/*([inverse][carré][cube][pi]e -> Str7
If sub(Str0,A,2)="+{" or "}+"=sub(Str0,B,2
Then
1 -> X
prgm[théta][théta]ADDF
If not(X:Return
Else
prgm[théta][théta]DETBC
If not(X:Return
expr(Str2 -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
sub(Str2,4,length(Str2)-3 -> Str2
End
sub(Str0,1,B)+Str2+sub(Str0,C,length(Str0)-C+1 -> Str0
1 -> A
Code
programme[théta][théta]ADDF (addition et soustractions avec fraction)
1 -> X
prgm[théta][théta]DETBC
If not(X:Return
sub(Str0,B+1,A-B-1 -> Str2
sub(Str0,A+1,C-A-1 -> Str3
inString(Str2,": -> H
inString(Str3,": -> M
If H
Then
expr(sub(Str2,2,H-2 -> N
expr(sub(Str2,H+1,length(Str2)-H-1 -> O
Else
expr(Str2 -> N
1 -> O
End
If M
Then
expr(sub(Str3,2,M-2 -> P
expr(sub(Str3,M+1,length(Str3)-M-1 -> Q
Else
expr(Str3 -> P
1 -> Q
End
While fPart(N) or fPart(O
10N -> N
10O -> O
End
While fPart(P) or fPart(Q
10P -> P
10Q -> Q
End
gcd(abs(N),abs(O))^-1 -> H
NH -> N
OH -> O
gcd(abs(P),abs(Q))^-1 -> M
PM -> P
QM -> Q
OQ -> V
NQ+PO -> U
(-2(V<0)+1)gcd(abs(U),abs(V))^-1 -> W
UW -> U
VW -> V
U -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
V -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str3
If U=0
Then
"0 -> Str2
Else
sub(Str2,4,length(Str2)-3 -> Str2
If V=/=1
"{"+Str2+":"+sub(Str3,4,length(Str3)-3)+"} -> Str2
Code
programme[théta][théta]CARCU (carré et cube)
If "}"=sub(Str0,B,1
Then
prgm[théta][théta]CARCUF
Else
While Bø1 and inString("0.123456789à",sub(Str0,B,1
B-1 -> B
End
If ")"=sub(Str0,B,1
Return
If B=1:0 -> B
sub(Str0,B+1,A-B -> Str2
expr(Str2 -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
sub(Str2,4,length(Str2)-3 -> Str2
End
sub(Str0,1,B)+Str2+sub(Str0,A+1,length(Str0)-A -> Str0
1 -> A
Code
programme[théta][théta]CARCUF (cube et carré de fractions)
While Bø1 and "{"øsub(Str0,B,1
B-1 -> B
End
B-1 -> B
If B=1:0 -> B
inString(Str0,":",B+2 -> H
sub(Str0,B+2,H-B-2 -> Str2
sub(Str0,H+1,A-H-2 -> Str3
expr(Str2)^(2+[theta]) -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
expr(Str3)^(2+[theta]) -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str3
"{"+sub(Str2,4,length(Str2)-3)+":"+sub(Str3,4,length(Str3)-3)+"}" -> Str2
Code
PROGRAMME[théta][théta]DETBC (calcule B et C, respectivement le rand du dernier carractère avant la chaîne exprimée et le premier après)
While Bø1 and inString("[le moins des relatifs]0.123456789à{:}",sub(Str0,B,1
B-1 -> B
End
If inString(Str1,sub(Str0,B,1
DelVar XReturn
If B=1:0 -> B
While Cølength(Str0) and inString("-0.123456789à{:}",sub(Str0,C,1
C+1 -> C
End
If inString(Str7,sub(Str0,C,1
DelVar XReturn
If C=length(Str0:C+1 -> C
sub(Str0,B+1,C-B-1 -> Str2
Code
[théta][théta]DIV (division d'un nombre décimal par un autre
"/^) -> Str1
"^([inverse][carré][cube][pi]e -> Str7 //les crochets servent uniquement a marquer les carracteres speciaux
1 -> X
If "}"=sub(Str0,A-1,1) and inString("0.-123456789",sub(Str0,A+1,1
Then
prgm[theta][theta]DIVFPN
If not(X:Return
Else
If "/{"=sub(Str0,A,2
Then
prgm[thete][theta]DIVPF
If not(X:Return
Else
prgm[theta][theta]DETBC
If not(X:Return
expr(Str2 -> E
If not(fPart(E[E des puissances de 10]5
Then
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
sub(Str2,4,length(Str2)-3 -> Str2
Goto Q
End
sub(Str0,B+1,A-B-1 -> Str2
sub(Str0,A+1,C-A-1 -> Str3
expr(Str2 -> U
expr(Str3 -> V
While fPart(U) or fPart(V
10U -> U
10V -> V
End
(-2(V<0)+1)gcd(abs(U),abs(V))^-1 -> N
UN -> U
VN -> V
U -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
V -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str3
"{"+sub(Str2,4,length(Str2)-3)+":"+sub(Str3,4,length(Str3)-3)+"} -> Str2
Lbl Q
End
End
sub(Str0,1,B)+Str2+sub(Str0,C,length(Str0)-C+1 -> Str0
1 -> A
Code
[théta][théta]DIVFPN (division d'une fraction par un un nombre)
prgm[theta][theta]DETBC
If not(X:Return
inString(Str0,":",B+1 -> H
sub(Str0,B+2,H-B-2 -> Str2
sub(Str0,H+1,A-H-2 -> Str3
sub(Str0,A+1,C-A-1 -> Str4
expr(Str2 -> U
expr(Str3 -> V
expr(Str4 -> W
VW -> V
(-2(V<0)+1)gcd(abs(U),abs(V))^-1 -> N
UN -> U
VN -> V
U -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
sub(Str2,4,length(Str2)-3 -> Str2
V -> E
LinReg(ax+b)L5,L6,Y9
EquåString(Y9,Str3
sub(Str3,4,length(Str3)-3 -> Str3
If V=/=0
"{"+Str2+":"+Str3+"}" -> Str2
Code
programme[théta][théta]DIVPF (division par une fraction)
inString(Str0,":",A+2 -> H
inString(Str0,"}",H+2 -> I
sub(Str0,A+2,H-A-2 -> Str2
sub(Str0,H+1,I-H-1 -> Str3
"*{"+Str3+":"+Str2+"}" -> Str2
I+1 -> C
If inString("^[^-1][^2][^3][pi](e",sub(Str0,C,1
DelVar X
Code
programme[théta][théta]INV (inverse d'un nombre)
While inString("[moins des relatifs]0.123456789{:}",sub(Str0,B,1
B-1 -> B
End
sub(Str0,B+1,A-B-1 -> Str4
inString(Str4,":" -> H
If H
Then
sub(Str4,2,H-2 -> Str2
sub(Str4,H+1,length(Str4)-H-1 -> Str3
expr(Str2 -> V
expr(Str3 -> U
Else
expr(Str4) -> V
1 -> U
End
While fPart(U) or fPart(V
10U -> U
10V -> V
End
(-2(U<0)+1)gcd(abs(U),abs(V))^-1 -> H
UH -> U
VH -> V
U -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
V -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str3
If U=0
Then
"0 -> Str2
Else
sub(Str2,4,length(Str2)-3 -> Str2
If V=/=1
"{"+Str2+":"+sub(Str3,4,length(Str3)-3)+"}" -> Str2
sub(Str0,1,B)+Str2+sub(Str0,A+1,length(Str0)-A -> Str0
Code
programme[théta][théta]MULT (multiplication)
"^)/ -> Str1
"^([^-1][^2][^3][pi]e -> Str7
1 -> X
If "}"=sub(Str0,A-1,1) or "{"=sub(Str0,A+1,1
Then
prgm[theta][theta]MULTF
If not(X:Return
Else
prgm[theta][theta]DETBC
If not(X:Return
expr(Str2 -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
sub(Str2,4,length(Str2)-3 -> Str2
End
sub(Str0,1,B)+Str2+sub(Str0,C,length(Str0)-C+1 -> Str0
1 -> A
Code
programme[théta][théta]MULTF (multiplication avec fraction(s) )
While B=/=1 and inString(":{}-0.123456789",sub(Str0,B,1
B-1 -> B
End
If inString("^/)",sub(Str0,B,1
Return
If B=1:0 -> B
sub(Str0,B+1,A-B-1ü (
) Str2
inString(Str2,":" -> H
If H
Then
expr(sub(Str2,2,H-2 -> N
expr(sub(Str2,H+1,length(Str2)-H-1 -> O
Else
expr(Str2 -> N
1 -> O
While fPart(N
10N -> N
10O -> O
End
gcd(abs(N),O)^-1ü (
) G
NG -> N
OG -> O
End
A+1 -> C
While C=/=length(Str0) and inString(":{}-0.123456789",sub(Str0,C,1
C+1 -> C
End
If inString("^)sin(cos(tan(sin-1(cos-1(tan-1([pi]e[10^(][e^(][^-1][^2][^3][racine carre][racine cube] [racine X]",sub(Str0,C,1
DelVar XReturn
If C=length(Str0):C+1 -> C
sub(Str0,A+1,C-A-1 -> Str2
inString(Str2,":" -> H
If H
Then
expr(sub(Str2,2,H-2 -> P
expr(sub(Str2,H+1,length(Str2)-H-1 -> Q
Else
expr(Str2 -> P
1 -> Q
While fPart(P
10P -> P
10Q -> Q
End
gcd(abs(P),Q)^-1ü (
) G
PG -> P
QG -> Q
End
NP -> U
OQ -> V
(-2(V<0)+1)gcd(abs(U),abs(V))^-1ü (
) G
UG -> U
VG -> V
U -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str2
sub(Str2,4,length(Str2)-3 -> Str2
V -> E
LinReg(ax+b)L5,L6,Y9
Equ>String(Y9,Str3
sub(Str3,4,length(Str3)-3 -> Str3
If U=0
Then
"0 -> Str2
Else
If V=/=1
"{"+Str2+":"+Str3+"}" -> Str2
Code
programme[théta][théta]SIGNE (transforme la soustraction en addition)
1 -> Y
While Y
inString(Str0,"[moins des soustractions]",Y -> Y
If Y
Then
If "{"=sub(Str0,Y+1,1
Then
sub(Str0,1,Y-1)+"+{[moins des relatifs]"+sub(Str0,Y+2,length(Str0)-Y-1 -> Str0
Else
sub(Str0,1,Y-1)+"+[moins des relatifs]"+sub(Str0,Y+1,length(Str0)-Y -> Str0
End
End
End
Sandro