From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Thu, 3 Nov 2005 23:45:43 +0200 From: Michael Shigorin To: smoke-room@lists.altlinux.org, ALT Linux Community Message-ID: <20051103214543.GT14765@osdn.org.ua> Mail-Followup-To: smoke-room@lists.altlinux.org, ALT Linux Community References: <200511021433.32422.ashen@nsrz.ru> <200511021528.09835.ashen@nsrz.ru> <20051102125525.GK14765@osdn.org.ua> <20051102135118.GH7271@osdn.org.ua> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="6sX45UoQRIJXqkqR" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.4.2.1i Cc: Subject: [room] Re: [JT] Re: [Comm] Re: MathCAD, MathLab X-BeenThere: smoke-room@lists.altlinux.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: shigorin@gmail.com, =?koi8-r?b?y9XM2NTV0s7ZyiDPxtTP0MnL?= List-Id: =?koi8-r?b?y9XM2NTV0s7ZyiDPxtTP0MnL?= List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2005 21:46:27 -0000 Archived-At: List-Archive: --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: 8bit On Thu, Nov 03, 2005 at 09:43:30AM -0000, Aleksander N. Gorohovski wrote: > >>>>У него свой язык, типа программирования, но, по моему, лучше > >>>>уж писать на С. > >>>Математику? Ну-ну. > >>Сурьезную математику, а не беллетристику. > >Сурьёзную математику на Це писать сильно дорого выходит. > >Разберёте такую мелочь, как аттачик (в смысле "что оно делает") > Миша, я до конца не понял ваш язык изопа? Вообще-то это был язык C. :] > What is "аттачик"? an attach. Цепляю ещё раз (хотя и тогда вроде не забыл?). > :-) -- ---- WBR, Michael Shigorin ------ Linux.Kiev http://www.linux.kiev.ua/ --6sX45UoQRIJXqkqR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="alkanol.c" /* * ALCANOL -- the alcanol isomeres number calculations * Version 0.20 of May 10 2000 by Michael Shigorin * * THIS IS FREE SOFTWARE - USE FREELY BUT ON YOUR OWN RISK (CISK;) * MAY BE REDISTRIBUTED/MODIFIED UNDER THE TERMS OF GNU GPL ][ * */ #include #include #include #include #include #include "gmp.h" #define counter_t unsigned int /* used for counters -- 32bit for me */ //#define TIMER /* timing support */ //#define DEBUG /* more verbosity */ #define MAX_DEGREE 4096 /* CPU/RAM/time's the limit :) */ #define MAX_LEN 255 /* max length of iofile name */ #define FORMAT "%d:\t" /* ^data file format excl. HUGE numbers$ */ #ifdef TIMER #define LOGFORMAT "%d\t%f" /* number seconds */ #define TIMEXT ".log" /* extension to add for log */ #include #include #endif mpz_t source [MAX_DEGREE], factor, buffer; mpz_t temp; FILE *iofile; char filename [MAX_LEN]; counter_t max; #ifdef TIMER char logname [MAX_LEN]; FILE *logfile; float timer; struct timeval raw_timer; struct timezone tz; /* stub */ float alk_time (void); #endif void init (void); void parse (void); void calculate (void); void print (void); void usage (void); void shutdown (void); int main (int argc, char *argv[]) { if( argc != 2 ) usage (); strncpy (filename, argv [1], strlen (argv [1])+1); #ifdef TIMER snprintf (logname, strlen (filename)+strlen (TIMEXT)+1, "%s%s", filename, TIMEXT); #endif init (); parse (); calculate (); print (); shutdown (); return (0); } #ifdef TIMER float alk_time (void) { gettimeofday (&raw_timer, &tz); return (float)raw_timer.tv_sec + (float)raw_timer.tv_usec/1000000; } #endif void usage (void) { fprintf (stderr, "I need one argument (a file to proceed)!\n"); exit (1); } void init (void) { #ifdef DEBUG fprintf (stderr, "\nReading data from <%s>...\n", filename); #endif if( !(iofile = fopen (filename, "r")) ) { fprintf (stderr, "Error: cannot Open Source file <%s>\n", filename); exit (1); } } void parse (void) { mpz_init (temp); #ifdef DEBUG fprintf (stderr, "Parsing..."); #endif while( !feof(iofile) ) { if( fscanf(iofile, FORMAT, &max) ) { if( mpz_inp_str (temp, iofile, 10) ) mpz_set (source [max], temp); } else { fprintf (stderr, "Error: malformed line #%d", max); exit (2); } } #ifdef DEBUG fprintf (stderr, " ok, maximal degree is %d.\n", max); #endif } void calculate (void) { counter_t i, j; #ifdef TIMER timer = alk_time (); #endif #ifdef DEBUG fprintf (stderr, "Calculating factor by degree %d.\n", max+1); #endif mpz_init_set_ui (factor, 0); /* first part -- C^3(x). Take only those parts of degree == max */ for( i=0; i<=max; i++ ) for( j=0; j<=max-i; j++ ) { mpz_mul (temp, source [i], source [j]); mpz_mul (temp, source [max-i-j], temp); mpz_add (factor, temp, factor); } /* next part -- 3*C(x)*C(x^2). A bit tricky... */ for( i=max%2; i<=max; i+=2 ) { /* evens and odds */ mpz_mul_ui (temp, source [i], 3); mpz_mul (temp, source [(max-i)>>1], temp); mpz_add (factor, temp, factor); } /* last part -- 2*C(x^3). */ if( !(max % 3) ) { mpz_mul_ui (temp, source [max/3], 2); mpz_add (factor, temp, factor); } /* and finally, divide factor by 6. If it doesn't........ */ mpz_tdiv_qr_ui (factor, temp, factor, 6); if( mpz_cmp_ui (temp, 0) ) { fprintf (stderr, "INTERNAL ERROR OR BAD DATA!\n"); fprintf (stderr, " is not divisible by 6 (#%d)\n", max+1); exit (3); /* ...... */ } #ifdef TIMER timer = alk_time () - timer; #endif } void print (void) { if( !(iofile = fopen (filename, "a")) ) { fprintf (stderr, "Error: cannot open output file <%s>\n", filename); fclose (iofile); exit (1); } #ifdef TIMER if( !(logfile = fopen (logname, "a")) ) { fprintf (stderr, "Warning: cannot open log file <%s>\n", logname); } else { fprintf (logfile, LOGFORMAT, max+1, timer); putc ('\n', logfile); } #endif #ifdef DEBUG fprintf (stderr, "Writing to <%s>.\n", filename); #endif fprintf (iofile, FORMAT, max+1); mpz_out_str (iofile, 10, factor); putc ('\n', iofile); } void shutdown (void) { fclose (iofile); #ifdef TIMER fclose (logfile); #endif } --6sX45UoQRIJXqkqR--