74 FormContraction.clear();
75 resource_path.clear();
84 bool ToForm::getRenumberOption(){
87 bool ToForm::getIndexSum(){
90 void ToForm::setIndexSum(
bool flag){
94 void ToForm::setRenumber(
bool flag){
96 if(formRenumber) cout <<
"Setting \"renumber 1;\" in FORM" << endl;
97 else cout <<
"UnSetting \"renumber 1;\" in FORM" << endl;
99 void ToForm::setFilename(
string name){
157 const unsigned int numUpperIds,
const unsigned int numLowerIds, \
160 bool flavorid =
false;
165 else fname = fieldname;
166 if(numLowerIds > 0 || numUpperIds > 0){
169 string functionheader = fname;
172 if(!flavorid && (numLowerIds == 0 || numUpperIds == 0) ){
174 else functionheader +=
"(antisymmetric)";
178 bool newfunc = form.
function(functionheader);
183 bool fieldctr =
false;
185 if(!flavorid && (numLowerIds > 0 && numUpperIds > 0) ) fieldctr =
true;
186 if(flavorid && (numLowerIds > 0 || numUpperIds > 0) ) fieldctr =
true;
190 if(flavorid) idinc = 1;
192 else tmp =
"antisymmetrize " + fname +
" ";
195 for(
int i = 0; i < numUpperIds; i++){
198 if(i < numUpperIds-1) idnum +=
",";
209 if(flavorid) idinc = 1;
210 for(
int i = 0; i < numLowerIds; i++){
213 if(i < numLowerIds-1) idnum +=
",";
222 if(numUpperIds > 0 && numLowerIds > 0){
223 string tmp =
"id " + fname +
"(";
229 for(
int i = 1; i <= numUpperIds; i++){
230 for(
int j=1; j<=numLowerIds; j++){
232 for(
int k=1; k<=(numUpperIds+numLowerIds); k++){
233 if(k==i || k==(j+numUpperIds)) tmp1 +=
"?x";
238 if(k < (numUpperIds+numLowerIds) ) tmp1 +=
",";
246 if(numUpperIds > 1 && numLowerIds > 0){
247 string tmp =
"id " + fname +
"(";
253 for(
int i = 1; i <= numUpperIds; i++){
254 for(
int j=i+1; j<=numUpperIds; j++){
256 for(
int k=1; k<=(numUpperIds+numLowerIds); k++){
257 if(k==i || k==j) tmp1 +=
"?x";
262 if(k < (numUpperIds+numLowerIds) ) tmp1 +=
",";
271 if(numUpperIds > 0 && numLowerIds > 1){
272 string tmp =
"id " + fname +
"(";
278 for(
int i = 1; i <= numLowerIds; i++){
279 for(
int j=i+1; j<=numLowerIds; j++){
281 for(
int k=1; k<=(numUpperIds+numLowerIds); k++){
282 if(k==(i+numUpperIds) || k==(j+numUpperIds)) tmp1 +=
"?x";
287 if(k < (numUpperIds+numLowerIds) ) tmp1 +=
",";
320 bool ToForm::function(
string func){
321 std::vector<string>::iterator it;
322 it = find (Functions.begin(), Functions.end(), func);
323 if(it == Functions.end()) {
324 Functions.push_back(func);
343 void ToForm::contractions(
string func){
344 std::vector<string>::iterator it;
345 it = find (FormContraction.begin(), FormContraction.end(), func);
346 if(it != FormContraction.end()) FormContraction.push_back(func);
352 string ToForm::getFC(){
354 for(
int i = 0; i < FormContraction.size(); i++){
355 func += FormContraction.at(i);
364 string ToForm::getFunction(){
366 if(Functions.empty()==
false){
368 for(
int i = 0; i < Functions.size(); i++){
369 func += Functions.at(i);
370 if( i == Functions.size()-1)
394 std::vector<string>::iterator it;
395 it = find (Functions.begin(), Functions.end(), func);
396 if(it == Functions.end()) Functions.push_back(func);
413 std::vector<string>::iterator it;
414 it = find (FormContraction.begin(), FormContraction.end(), func);
415 if(it == FormContraction.end()) FormContraction.push_back(func);
422 #define stringify( x ) stringify_literal( x )
423 #define stringify_literal( x ) # x
433 if(formin.
rpath().empty()){
438 path = pathtmp.c_str();
441 if(stat (
"form", &buffer) == 0) path=(
char*)
".";
442 else path = getenv(
"PATH_TO_FORM");
447 printf(
"warning: Environment variable PATH_TO_FORM is not set.\n");
449 }
else if (stat(path, &pstat) || !S_ISDIR(pstat.st_mode)) {
451 printf(
"warning: The path \"%s\" does not exist or is not a directory\n.", path);
453 printf(
"warning: The path \"%s\" specified by PATH_TO_FORM does not exist or is not a directory\n.", path);
457 formin.
rpath() = path;
459 formin.
rpath() +=
"/form";
461 if (stat(formin.
rpath().c_str(), &pstat) || !S_ISREG(pstat.st_mode)) {
463 printf(
"warning: The FORM program (\"form\") was not found in \"%s\"\n.", path);
465 printf(
"warning: The FORM program (\"form\") was not found in \"%s\" specified by PATH_TO_FORM.\n.", path);
473 string filenamein = formin.
file() +
"_in.frm";
474 ofstream fileout(filenamein.c_str());
475 if (fileout.is_open()){
476 fileout <<
"#-" << endl;
477 fileout <<
"**********************************************************************" << endl;
478 fileout <<
"* *" << endl;
479 fileout <<
"* Yukawa coupling *" << endl;
480 fileout <<
"* FORM PROGRAM *" << endl;
482 fileout <<
"**********************************************************************" << endl;
483 fileout <<
"*" << endl;
484 fileout <<
"*" << endl;
486 fileout <<
"format 255;" << endl;
487 fileout <<
"CFunction sqrt;" << endl;
488 fileout <<
"Symbols y,z;" << endl;
490 fileout <<
"Off statistics;" << endl;
491 fileout <<
"*" << endl;
495 fileout <<
"*" << endl;
496 fileout <<
"Local R =" << endl;
497 fileout <<
" #do ii = 1, " +
ToString<int>(exp.size()) << endl;
498 fileout <<
" + R`ii'" << endl;
499 fileout <<
" #enddo" << endl;
500 fileout <<
";" << endl;
501 fileout <<
"*" << endl;
502 fileout <<
"contract;" << endl;
503 fileout <<
"contract;" << endl;
504 fileout <<
"contract;" << endl;
505 fileout <<
"contract;" << endl;
506 fileout <<
"contract;" << endl;
507 fileout <<
"contract;" << endl;
508 fileout <<
"contract;" << endl;
509 fileout <<
"*\n" << formin.
getFC() << endl;
511 fileout <<
"sum " <<
IndexList() << endl;
513 for(
int i=1; i<=
getDim() /2; i++){
515 if(i <
getDim() /2) fileout <<
",";
517 fileout <<
")=1;" << endl;
522 fileout <<
"repeat;" << endl;
523 fileout <<
" id 1/(sqrt(y?)) = sqrt(1/y);" << endl;
524 fileout <<
" id sqrt(y?)*sqrt(z?) = sqrt(y*z);" << endl;
525 fileout <<
"endrepeat;" << endl;
527 if(all) fileout <<
"print +s;" << endl;
528 else fileout <<
"print R;" << endl;
529 fileout <<
".end" << endl;
532 cout <<
"Cannot create output file: " << filenamein << endl;
533 cout <<
"Exiting..." << endl;
537 if(
getVerbosity()>
SUMMARIZE) cout <<
"################################################################" << endl;
538 string filenameout = formin.
file() +
"_out.frm";
543 torun << formin.
rpath() <<
" " << filenamein <<
" > " << filenameout;
546 int out_system = system(torun.str().c_str());
550 ifstream myfile(filenameout.c_str());
552 if (myfile.is_open()){
553 while ( myfile.good() ){
554 getline(myfile,line);
555 file << line << endl;
560 cout <<
"Error reading output form file: " << filenameout << endl;
564 string filecontent = file.str();
570 if(filecontent.find(ind)==string::npos)
break;
571 while(filecontent.find(ind)!=string::npos){
572 filecontent.replace(filecontent.find(ind),ind.size(),idsub);
578 ofstream fileout0(filenameout.c_str());
580 fileout0 << filecontent;
583 cout <<
"################################################################" << endl;
584 cout <<
"RESULTS FROM FORM: " << endl;
586 if(filecontent.find(
"R =")==string::npos) {
587 cout <<
"Error, see FORM file for more details, " << filenameout << endl;
590 filecontent.replace(0, filecontent.find(
"R ="),
"");
591 filecontent.replace(filecontent.find(
";")+1, filecontent.length(),
"");
593 if(print) cout << filecontent << endl;
596 filecontent.erase(std::remove(filecontent.begin(), filecontent.end(),
' '), filecontent.end());
597 filecontent.erase(std::remove(filecontent.begin(), filecontent.end(),
'\n'), filecontent.end());
598 filecontent = filecontent.substr(filecontent.find(
"R=")+2, filecontent.find(
';')-filecontent.find(
"R=")-2);
600 std::size_t found = filecontent.find_first_of(
"-+");
601 std::size_t found0 = 0;
602 while (found!=std::string::npos){
603 found=filecontent.find_first_of(
"+-",found0+1);
604 string tmp = filecontent.substr(found0, found-found0);
606 if(!tmp.empty()) sta.push_back(tmp);
611 if(print) cout <<
"################################################################" << endl;
618 Formrun(exp, form, print, all, newidlabel);
double getElapsedTimeInSec()
Get elapsed time in second (same as getElapsedTime)
void setON()
Activate expression term numbering for output writing for each term "Local R?=".
int getDim()
Get the group dimension.
Verbosity getVerbosity()
Return current verbosity level.
void setOFF()
Deactivate expression term numbering for output writing for each term "Local R?=".
template string ToString< int >(int number)
string FormField(const string fieldname, const unsigned int numUpperIds, const unsigned int numLowerIds, const FuncProp funcp)
Function to add field name and create field proprieties to FORM input file.
void expfromForm(vector< string > a)
To pass a expression from form.
void Formrun(Braket &exp, ToForm &formin, bool print, bool all, string newidlabel)
Create file input for FORM and run the FORM program and return the result to file and/or screen...
void CallForm(Braket &exp, bool print, bool all, string newidlabel)
Creat the file input for FORM and run the FORM program and return the result to file and/or screen...
Defintions for all general (initialisation etc.) routines of class DList.
void setFormIndexSum()
Set the index sum in input FORM file, ie, adds "sum i,j,...;" and "id e_(1,...,N) = 1"...
OPMode operator+(const OPMode a, const OPMode b)
calculate the mode for the sum
void unsetFormIndexSum()
Unset the index sum in input FORM file.
Main Sospin header file. Includes C++ macros, to simplify expression writing, B operator, Verbosity level and memory usage.
void setFormRenumber()
Set "renumber 1;" in FORM input file. This option is used to renumber indices in order to allow furth...
ostream & operator<<(ostream &out, const OPMode &a)
Get the mode of the expression.
double getElapsedTimeInMicroSec()
Get elapsed time in micro-second.
void newId(string i)
Store new index of type "string".
const std::string currentDateTime()
Get current date/time, format is YYYY-MM-DD.HH:mm:ss.
void unsetFormRenumber()
Unset "renumber 1;" in FORM input file.
string IndexList()
Index list.
template string ToString< unsigned int >(unsigned int number)