From: Michael Shigorin <mike@osdn.org.ua> To: smoke-room@lists.altlinux.org, ALT Linux Community <community@lists.altlinux.org> Subject: [room] Re: [JT] Re: [Comm] Re: MathCAD, MathLab Date: Thu, 3 Nov 2005 23:45:43 +0200 Message-ID: <20051103214543.GT14765@osdn.org.ua> (raw) In-Reply-To: <op.sznrysn7hz2pp6@oc.peooc.net> [-- Attachment #1: Type: text/plain, Size: 622 bytes --] On Thu, Nov 03, 2005 at 09:43:30AM -0000, Aleksander N. Gorohovski wrote: > >>>>У него свой язык, типа программирования, но, по моему, лучше > >>>>уж писать на С. > >>>Математику? Ну-ну. > >>Сурьезную математику, а не беллетристику. > >Сурьёзную математику на Це писать сильно дорого выходит. > >Разберёте такую мелочь, как аттачик (в смысле "что оно делает") > Миша, я до конца не понял ваш язык изопа? Вообще-то это был язык C. :] > What is "аттачик"? an attach. Цепляю ещё раз (хотя и тогда вроде не забыл?). > :-) -- ---- WBR, Michael Shigorin <mike@altlinux.ru> ------ Linux.Kiev http://www.linux.kiev.ua/ [-- Attachment #2: alkanol.c --] [-- Type: text/plain, Size: 4243 bytes --] /* * ALCANOL -- the alcanol isomeres number calculations * Version 0.20 of May 10 2000 by Michael Shigorin <michael.shigorin@usa.net> * * THIS IS FREE SOFTWARE - USE FREELY BUT ON YOUR OWN RISK (CISK;) * MAY BE REDISTRIBUTED/MODIFIED UNDER THE TERMS OF GNU GPL ][ * */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #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 <tab> seconds */ #define TIMEXT ".log" /* extension to add for log */ #include <sys/time.h> #include <unistd.h> #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 }
next prev parent reply other threads:[~2005-11-03 21:45 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2005-11-03 9:43 ` Aleksander N. Gorohovski 2005-11-03 11:46 ` Mike Lykov 2005-11-03 11:48 ` Genix 2005-11-03 21:34 ` Michael Shigorin 2005-11-03 21:45 ` Michael Shigorin [this message] 2005-11-04 7:20 ` Andrey Rahmatullin 2005-11-04 23:23 ` Aleksey Korotkov 2005-11-05 7:43 ` Andrey Rahmatullin 2005-11-05 21:54 ` [room] MathLab Aleksey Korotkov 2005-11-05 22:08 ` Michael Shigorin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20051103214543.GT14765@osdn.org.ua \ --to=mike@osdn.org.ua \ --cc=community@lists.altlinux.org \ --cc=shigorin@gmail.com \ --cc=smoke-room@lists.altlinux.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Культурный офтопик This inbox may be cloned and mirrored by anyone: git clone --mirror http://lore.altlinux.org/smoke-room/0 smoke-room/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 smoke-room smoke-room/ http://lore.altlinux.org/smoke-room \ smoke-room@lists.altlinux.org smoke-room@lists.altlinux.ru smoke-room@lists.altlinux.com smoke-room@altlinux.ru smoke-room@altlinux.org smoke-room@altlinux.com public-inbox-index smoke-room Example config snippet for mirrors. Newsgroup available over NNTP: nntp://lore.altlinux.org/org.altlinux.lists.smoke-room AGPL code for this site: git clone https://public-inbox.org/public-inbox.git