-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathif_ln.cpp
253 lines (233 loc) · 6.4 KB
/
if_ln.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include "header.h"
using namespace std;
int ln_token=0;
int all_l=0;
void all_ln()
{
all_l++;
}
bool ln_function(string equ)
{
char* if_ln=strstr(equ.c_str(),"ln");
if(if_ln!=nullptr)
return true;
else return false;
}
void ln_null()
{
all_l = 0;
}
string if_ln(string equ)
{
string ans4="";
string ans5="";
char ln_chain[1000];
int k,j=0;
char ln_var;
for(int i=0; i<equ.size(); i++)
{
if(equ[i]=='(' && i==0)
continue;
if(equ[i]=='(' )
{
if(equ[i+2]==')')
{
k=1;
int n_type=char_type(equ[i+1]);
int n_type2=char_type(equ[i+2]);
if(n_type==1 )
ln_var=equ[i+1];
else if(n_type==2)
ln_var='\0' ;
}
else
{
ln_chain[j] = equ[i];
j++;
ln_chain[j]= equ[i+1];
j++;
}
}
else if(j>0)
{
ln_chain[j] = equ[i+1];
j++;
}
if(equ[i]==')' && equ[i-2] != '(')
ln_chain[j] = '\0' ;
}
int ob=0,i;
for( i=0;i<strlen(ln_chain);i++)
{
if(ln_chain[i]=='(')
ob++;
else break;
}
for(int j=i;j<=strlen(ln_chain);j++)
ln_chain[j-ob]=ln_chain[j];
bool trigono_track_ln=trigonometry_function(ln_chain);
bool ln_track_ln=ln_function(ln_chain);
bool sqrt_ln=root_function(ln_chain);
bool exp_track_ln=exp_function(ln_chain);
if( k != 1 && trigono_track_ln == false && ln_track_ln == false && exp_track_ln == false && sqrt_ln==false )
{
if(all_l>0)
{
int xl=0,yl=0;
char cl='\0';
cout<<"d/d";
for(int i=0; i<equ.size(); i++)
{
if(equ[i] != '(' && yl==0)
continue ;
else
{
yl++;
xl=char_type(equ[i]);
if(xl==1)
{
cl=equ[i];
break;
}
}
}
if(cl=='\0')
{
cl='x';
cout<<cl<<" "<<"(";
}
else cout<<cl<<" "<<"(";
cout<<ln_chain<<"/";
}
ans4 +="(";
ans4 +=for_partition(ln_chain);
ans4 +="/";
for(int i=0; ln_chain[i] != '\0'; i++)
ans4 +=ln_chain[i];
if(all_l>0)
{
cout<<ln_chain;
cout<<"\n\n\t\t\t = ";
}
}
else if(k==1 && trigono_track_ln == false && ln_track_ln == false && exp_track_ln == false && sqrt_ln==false)
{
if(ln_var == '\0')
{
ans4 = "0";
return ans4;
}
else
{
ln_chain[0] = ln_var;
ln_chain[1] = ')' ;
ln_chain[2] = '\0';
ans4 +="1/" ;
ans4 +="(" ;
for(int i=0; ln_chain[i]!='\0'; i++)
ans4 += ln_chain[i];
}
}
else if(trigono_track_ln || ln_track_ln || exp_track_ln || sqrt_ln ==true )
{
string match=str_match(ln_chain);
if(match=="e^")
{
if(all_l>0)
{
all_exp();
cout<<" First of all, we have to differentiate the part inside e^().";
cout<<"\n\n\t\t\tSo-\n\n\t\t\t = ";
}
if(k==1)
{
for(int i=0; i<strlen(ln_chain); i++)
{
if(ln_chain [i] == '(' && ln_chain[i+1]== ')' )
{
ln_chain[i+1] = ln_var;
ln_chain[i+2] =' )' ;
ln_chain[i+3] = '\0' ;
}
}
}
ans5+=if_exp(ln_chain);
ans4+=ans5;
if(all_l>0)
{
cout<<ans5;
cout<<"\n\n\n\t\t\tFinally-\n\n\t\t\t = ";
}
}
else if(match=="sqrt")
{
if(all_l>0)
{
all_root();
cout<<" First of all, we have to differentiate the part inside sqrt().";
cout<<"\n\n\t\t\tSo-\n\n\t\t\t = ";
}
if(k==1)
{
for(int i=0; i<strlen(ln_chain); i++)
{
if(ln_chain [i] == '(' && ln_chain[i+1]== ')' )
{
ln_chain[i+1] = ln_var;
ln_chain[i+2] =' )' ;
ln_chain[i+3] = '\0' ;
}
}
}
ans5+=if_root(ln_chain);
ans4+=ans5;
if(all_l>0)
{
cout<<ans5;
cout<<"\n\n\n\t\t\tFinally-\n\n\t\t\t = ";
}
}
else if(match=="ln")
{
cout<<" First of all, we have to differentiate the part inside ln().";
cout<<"\n\n\t\t\tSo-\n\n\t\t\t = ";
ans4 +=if_ln(ln_chain);
}
else
{
if(all_l>0)
{
all_trigon();
}
if(k==1)
{
for(int i=0; i<strlen(ln_chain); i++)
{
if(ln_chain [i] == '(' && ln_chain[i+1]== ')' )
{
ln_chain[i+1] = ln_var;
ln_chain[i+2] =' )' ;
ln_chain[i+3] = '\0' ;
}
}
}
ans5 +=if_trigonometry(ln_chain);
ans4 +=ans5;
if(all_l>0)
{
cout<<ans5;
cout<<"\n\n\n\t\t\tFinally-\n\n\t\t\t = ";
}
}
ans4+=" / ";
for(int i=0; ln_chain[i]!='\0'; i++)
{
if(ln_chain[i]== '(' && i==0)
continue;
if(ln_chain[i]=='(' && ln_chain[i+1]=='(' )
continue;
ans4+= ln_chain[i];
}
}
return ans4;
}