توضیح پروژه
درخت های دودویی
تحلیل و ساده کردن عبارات ریاضی را می توان همیشه به کمک درختان عبارت انجام داد.برای
این کار هر عملگر را به عنوان یک گره پدر و عملوندهایش را به فرزندان این گره در نظر گرفت .همچنین
3 درخت x- توابع را میتوان یک عنوان یک عملگر که فقط یک ورودی دارد در نطر گرفت.مثل برای عبارت 5
در شکل زیر را رسم شده است.
Illustration 1: Binary Expression Tree of 3x-5
حال در این پروژه از شما خواسته شده است که عبارات ریاضی را گرفته و بتواند موارد زیر را
براورده کند.
۱- ساده سازی:عبارت خروجی برنامه شما تا حد ممکن باید ساده باشد.قواعد ساده سازی که شما
یک عبارت باشد داریم : s باید پیاده سازی نمایید را می توان اینطور خلصه نمود.اگر
S + 0 = S 0 + S = S S - 0 = S
S 0 = 0 0 S = 0 S 1 = S
0 / S = 0 S ^ 0 = 1 S ^ 1 = S
S - S = 0 S / S = 1
3+ همچین ریز عباراتی که فقط شامل ثابتهای عددی هستند نیز باید ساده شوند.مثل عبارت 2
باید با 5 جایگزین شود.
به شما داده می شود و برنامه شما باید مشتق این (x ۲-مشتق:عبارت بر حسب متغییری (فقط
عبارت را بر حسب ان متغییر بدست اورد.قواعد مشتق که بصورت بازگشتی تعریف میشود را میتوان
اینطور خلصه نمود:
Rule 1: The derivative of a constant is zero.
Diff(C) = 0
Rule 2: The derivative of the variable with respect to which you are differentiating is 1.
Diff(X) = 1
Rule 3: The derivative of the sum of expressions S and T is the sum of the derivative of
expression S plus the derivative of expression T.
Diff(S + T) = Diff(S) + Diff(T)
-
5
3 X
Rule 4: The derivative of the difference between expressions S and T is the derivative of
expression S minus the derivative of expression T.
Diff(S - T) = Diff(S) – Diff(T)
Rule 5: The derivative of the product of expressions S and T is equal to the product of
expression S and the derivative of expression T plus the product of expression T and the
derivative of expression S.
Diff(S T) = S Diff(T) + T Diff(S)
Rule 6: The derivative of the division of expression S by expression T is equal to the product of
expression T and the derivative of expression S, minus the product of expression S and the
derivative of expression T, divided by the square of expression T.
Diff(S/T) = ((T Diff(S)) - (S Diff(T)))/SQR(T)
Rule 7: The derivative of expression S raised to the expression T power is expression T times
expression S raised to the T - 1 power times the derivative of expression S. You may assume that
the variable with respect to which you are differentiating does not appear in the expression
representing the exponent. Assuming that X is not contained in expression T,
Diff(S ^ T) = T (S ^ (T - 1)) Diff(S)
نیز وجود دارد. sin ,cos ,tan در عبارت ورودی به برنامه شما توابع ریاضی
Rule 8: The derivative of the function f(S) is product of the derivative of expression S and
derivative of the function F
Diff(F(S)) = Diff(S) Diff(F)(S)
۳-رسم گرافیکی عبارت(اختیاری):رسم عبارت و مشتق عبارت در یک بازه خاص.
داده شده است (خط اول تعداد عبارات و بعد input.txt عبارات ورودی در یک فایل متنی به نام
از ان هر خط یک عبارت) و برنامه شما باید برای هر ورودی دو خط جداگانه که یکی ساده شده عبارت
و خط بعدی ساده شده مشتق ان عبارت چاپ نماید.
سایت مرجع پروژه: http://www.barnamejoo.com