The OERA function resulting from a symbolic solution to the Cover/Keilers Offensive Earned Run Average equation set is enclosed by the horizontal lines. Save this file as a text file and edit out the html preceeding and following the C++ source code.
// oera_sym.c // Copyright (c) 1997-1998 by John F. Jarvis // This surce code may be freely copied and distributed as long as // proper credit is given. // This software is provided "as is" without any express or // implied warranties, including, without limitation, the implied // warranties of merchantibility and fitness for a particular purpose. #include <stdio.h> // Offensive Earned Run Average // Thomas M. Cover, Carroll W. Keilers // Operations Reseach, Vol 25, No 5, Sep-Oct 1977 pp 729-740 // symbolic solution to equation set by S. King using Mathematica typedef double basetype; const int STATES = 24; // 3 outs only in symbolic function double oera(int /* outs */,int pflag, double bf, double sn, double db, double tr, double hr, double bb, double *er) { // parameters: // outs: number of outs in an inning but ignored in this version // pflag: use != 0 value to obtain printing from the function // bf: batters facing pitching = at bats + walks // sn, db, tr, hr: numbers of singles, doubles, triples, home runs // bb: walks. can add hit by pitch counts here and to bf if desired // er: NULL or array long enough to store solution vector // return value is expected runs per game defined 9*e[0] double e[STATES]; int i; basetype p1,p2,p3,p4,pb,p0; basetype p1e2,p1e3; basetype pbe2,pbe3; basetype p0e2; p1 = sn/bf; // probablities of each event p2 = db/bf; p3 = tr/bf; p4 = hr/bf; pb = bb/bf; p0 = 1.0 - (p1+p2+p3+p4+pb); // probability of an out if(p0<=0.0){ printf("oera p0 = %8.5f, <=0\n",p0); return 0.0; } p1e2 = p1*p1; p1e3 = p1*p1e2; pbe2 = pb*pb; pbe3 = pb*pbe2; p0e2 = p0*p0; e[0] = -1+1/p0-(2*(-1+p0))/p0-p2-p3-p0*(1+p0)*(p2+p3)-pb-(p2+p3+p0*(1+p0 +2*p2+3*p0*p2+2*p3+3*p0*p3))*pb-(1+p2+p3+p0*(2+3*p2+3*p3+p0*(3+6*p2+6*p3 )))*pbe2-(1+3*p0+6*p0e2)*pbe3-p1*(1+p0+p0e2+2*(1+p0*(2+3*p0))*pb+2*(1+3 *p0+6*p0e2)*pbe2)-p1e2*(1+pb+p0*(2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4+(1+3*p0)*(p2+p3+p4)*pb); e[16] = -1+1/p0-p2-p3-pb-p1e2*(1+pb)-pb*(1+pb)*(p2+p3+pb)-p1*(1+2*pb*(1+pb)); e[17] = -1+1/p0+p1*(-1+p2+p3+p4)*(1+pb)-pb*(1+pb)+p4*(1+pb+pbe2); e[18] = e[20] = -1+1/p0-p1e2*(1+pb)-pb*(1+pb)-p1*pb*(1+pb)+p4*(1+pb+pbe2); e[19] = e[21] = -1+1/p0-pb+(1+p1)*p2*(1+pb)+(1+p1)*p3*(1+pb)+p4*(2+p1+(2+p1)*pb+pbe2); e[22] = -1+1/p0+p1+p2+p3+2*p4-pb-p1*pbe2-p1e2*(1+pb)+pb*(p2+p3+p4*(2+pb)); e[23] = -1+1/p0+3*p4+p2*(2+pb)+(2+pb)*(p3+p4*pb)+p1*(1+p2+p3+p4+(p2+p3+p4)*pb); if(pflag != 0){ printf("bf %6.0f sn %6.0f db %6.0f tr %6.0f hr %6.0f bb %6.0f\n",bf,sn,db,tr,hr,bb); printf("p0 %6.4f p1 %6.4f p2 %6.4f p3 %6.4f p4 %6.4f pb %6.4f\n",p0,p1,p2,p3,p4,pb); printf("outs "); for(i=0;i<8;i++) printf(" %1d%1d%1d ",i&01, (i&02)>>1, (i&04)>>2); for(i=0;i<STATES;i++){ if((i%8)==0) printf("\n %1d ",i/8); printf(" %7.5f",e[i]); } printf("\n"); } if(er!=NULL) for(i=0;i<STATES;i++) er[i] = e[i]; return 9.0*e[0]; }
.