/*------------------------------------------------------------- Copyright (C) 2000 Peter Clote. All Rights Reserved. Permission to use, copy, modify, and distribute this software and its documentation for NON-COMMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies. THE AUTHOR AND PUBLISHER MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -------------------------------------------------------------*/ /**************************************** Program: funcmp.c Input: funcmp "x@x" "pow(2,x)" csh script called funcmp Multiplication must be indicated by "@" This program computes least integer n > 0 for which F(x) < G(x), where F is first function and G is second. You MUST indicate the function variable as "x" (lowercase). Sample run: ========== % funcmp "pow((x@x),3)" "pow(2,x)-(x@x)" F(30)=729000000 < G(30)=1073740924 Application for quicksort versus insertionsort ---------------------------------------------- 0.00027@x@log(x)/log(2)+0.00035@x+0.00004 0.000047@x@x+0.35 ****************************************/ #include #include #include #define F(x) FF #define G(x) GG main() { int x=0; do { x++; if ( F(x) < G(x) ) { printf("F(%d)=%.0lf < G(%d)=%.0lf\n", x,(double)F(x),x,(double)G(x)); return(0); } if ( x == INT_MAX ) { printf("For all x<%d, F(x) >= G(x)\n", INT_MAX); return(0); } } while ( F(x)>=G(x) ); }