📄 description of calc.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0046)http://www.numbertheory.org/calc/krm_calc.html -->
<HTML><HEAD><TITLE>DESCRIPTION OF CALC</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<STYLE type=text/css>BODY {
FONT-FAMILY: Helvetia, sans-serif
}
A:visited {
TEXT-DECORATION: none
}
A:link {
TEXT-DECORATION: none
}
A:hover {
TEXT-DECORATION: underline
}
</STYLE>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<H2>CALC</H2>CALC is a number theory calculator program which uses arbitrary
precision integer arithmetic. It would be useful in a first course in number
theory.<BR>It is written in ANSI C and Yacc, along the lines of the calculator
programs hoc1,2,3, Kernighan and Pike, <EM>The Unix Programming
Environment</EM>, 233-254, 1984. <BR><!--There is a DOS version which runs on 386/486/586 machinesand which is compiled on a Pentium machine using the <a href="http://www.delorie.com/djgpp/">djgpp</a> C compiler (version 2). <br>To run under windows2000+ from a dos window, the user should first download a dos emulator from <a href="http://dosbox.sourceforge.net/">http://dosbox.sourceforge.net/</a>.-->The
source comes with two makefiles, one for Unix and one for Windows XP.<BR>The
Windows XP version and C source can be downloaded <A
href="http://www.numbertheory.org/calc/Readme.html"><EM>here</EM></A>. <BR>The
author is grateful to Jean-Jacques Delgove for making changes to my code, so as
to allow compilation under Visual C++ 2005. He also pointed out that CALC now
can utilise <A href="http://www.gnu.org/software/gawk/">GAWK</A> scripts such as
the following, invoked by say <TT>calc > gawk -f calc.awk</TT>: <PRE>==== calc.awk ===========
BEGIN {
for(i=1;i < 8;i++){
cmd=sprintf("calc.exe \"(X+1)^%d\"",i)
while (((cmd) | getline a) > 0){
print a
}
close(cmd)
}
}
</PRE>with output: <PRE>X + 1
X^2 + 2X + 1
X^3 + 3X^2 + 3X + 1
X^4 + 4X^3 + 6X^2 + 4X + 1
X^5 + 5X^4 + 10X^3 + 10X^2 + 5X + 1
X^6 + 6X^5 + 15X^4 + 20X^3 + 15X^2 + 6X + 1
X^7 + 7X^6 + 21X^5 + 35X^4 + 35X^3 + 21X^2 + 7X + 1
</PRE><BR>
<HR>
<UL>
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#list_of_functions">CALC
functions</A>
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#examples">Examples</A> of
CALC calculations
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#bibliography">Bibliography</A>
<LI><A href="http://www.numbertheory.org/calc/calc_bugfix.html">Bugfixes and
additions</A> to CALC
<LI><A href="http://www.numbertheory.org/calc/calc_doc.html">Detailed
description</A> of some CALC functions </LI></UL>
<HR>
<A name=examples></A>
<P>To run CALC, type <TT>calc</TT>. One can then perform standard arithmetical
calculations such as the following (the answer is written underneath the
corresponding expression):<BR>>
54321+12345<BR> 66666<BR>>
54321-12345<BR> 41976<BR>>
54321*12345<BR> 670592745<BR>>
54321^10<BR> 223705964292712579004593047803650384459784511201<BR>>
54321/12345<BR> 4<BR>>
54321%12345<BR> 4941<BR>> x=12;y=13<BR>>
x*y<BR> 156<BR><BR>Arrays can be entered in two main ways:
<BR>(i) with an array identifer and a subscript:<BR>> a[0] = 1;a[1] = 2;a[2]
= 3;a[3] = 4;a[4] = 5<BR>(ii) or in the following manner:<BR>> a[ ] =
{1, 2, 3, 4, 5, 6}<BR><BR>Note: Any previous values for the array will be erased
and a new array will be created with the values in the curly braces. <BR>
When one wishes to output the array a[ ], all that must be typed
is:<BR>> a[ ]<BR><BR>alone on a line. <BR> If one uses the former
method, the size of the array will be set to the largest subscript
entered. Any subscripts that have not been defined and which are less than
this subscript, are initialised to zero. eg.<BR>> a[1]=2<BR>>
a[2]=3<BR>> a[4]=10<BR>> a[
]<BR> [0]:0<BR> [1]:2<BR> [2]:3<BR> [3]:0<BR> [4]:10<BR>
<P>Some functions require an mxn integer matrix to be entered, either at the
keyboard, or from a file. The format of such a file is as follows:<BR>m
n<BR>a<SUB>11</SUB> ... a<SUB>1n</SUB> <BR>...<BR>a<SUB>m1</SUB> ...
a<SUB>mn</SUB> <BR>In other words, the first line contains the row and column
size, separated by a space, while the entries on each row are separated by
spaces and each row is terminated by a newline.
<P><BR>Calc is now capable of parsing polynomials. A polynomial can be
entered using the reserved symbol X (capital x) in the following manner: <BR>
<DL>
<DD>> (X+2)^20<BR>
<DD> X^20 + 40X^19 + 760X^18 + 9120X^17 + 77520X^16 +
496128X^15 + 2480640X^14 + 9922560X^13 + 32248320X^12 + 85995520X^11 +
189190144X^10 + 343982080X^9 + 515973120X^8<BR>
<DD>+ 635043840X^7 + 635043840X^6 + 508035072X^5 + 317521920X^4 + 149422080X^3
+ 49807360X^2 + 10485760X + 1048576.<BR></DD></DL>
<P><BR>Once a polynomial has been assigned to a variable, it is also possible to
evaluate that polynomial at a specified integer value. <BR>
<DL>
<DD>> z=(X+2)^20<BR>
<DD>> z(2)<BR>
<DD>1099511627776 </DD></DL>
<P>Polynomial division and remaindering are available as p/q and p%q. Here p is
initially multiplied by c<SUP>deg(p)-deg(q)</SUP> (if deg(p)-deg(q) is not
negative), where c is the leading coefficient of q.
<DL>
<DD>> p=X^2+3X+7; q=2X+5<BR>
<DD>> p/q<BR>
<DD>> 2X+1<BR>
<DD>> p%q<BR>
<DD>> 23 </DD></DL>
<H3>Some more examples</H3>
<HR>
To find z = gcd(4,6), type<BR><BR>> z = gcd(4,6)<BR>Then z is stored and its
value is printed: <BR>> z<BR> 2<BR>
<HR>
To find z = gcd(4,6) together with integers u,v satisfying z = 4u+6v,
type<BR><BR>>z = gcdv(4,6,&u,&v)<BR>The values of u,v are stored and
their values printed by
typing<BR><BR>>u<BR> -1<BR>>v<BR> 1<BR>
<HR>
To find z=gcd(4,6,9), type <BR><BR>>x[0]=4;x[1]=6;x[2]=9 <BR>>z=gcda(x[])
<BR>
<HR>
To find z=gcd(4,6,9), together with integers b[0],b[1],b[2] satisfying
z=4*b[0]+6*b[1]+9*b[2], type
<BR><BR>>x[0]=4;x[1]=6;x[2]=9<BR>>z=gcdav(x[],&b[ ])<BR>The
values of b[0],b[1],b[2] are stored and their values printed by
typing:<BR><BR>>b[ ]<BR> [0]: 4<BR> [1]:
-4<BR> [2]: 1<BR><A name=list_of_functions></A>
<P>
<HR>
<H3>LIST OF FUNCTIONS</H3>
<OL>
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#absmod">z=absmod</A>(a,b)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[56]">euclid</A>(a,b,&q[ ],&r[ ],&s[ ],&t[ ],&n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[1]">z=gcd</A>(x,y)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[2]">z=gcdv</A>(x,y,&u,&v)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[3]">z=gcda</A>(a[ ])
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[4]">z=gcdav</A>(a[ ],
&b[ ])
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[5]">egcd</A>( )
<LI><A href="http://www.numbertheory.org/calc/krm_calc.html#[6]">sgcd</A>(N)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[49]">lllgcd</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[53]">lllgcd0</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[50]">jacobigcd</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[7]">z=lcm</A>(x,y)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[8]">z=lcma</A>(a[ ])
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[9]">z=length</A>(n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[10]">z=pollard</A>(x)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[11]">z=nprime</A>(x)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[12]">z=nprimeap</A>(a,b,m)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[13]">z=jacobi</A>(x,y)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[14]">z=peralta</A>(a,p)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[15]">x=congr</A>(a,b,m,&n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[16]">x=chinese</A>(a,b,m,n,&l)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[17]">x=chinesea</A>(a[ ],m[ ],&l)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[18]">z=mthroot</A>(x,m)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[19]">mthrootr</A>(x,y,m,r)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[20]">z=fund</A>(d,&x,&y)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[21]">z=pell</A>(d,e,&x,&y)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[23]">z=mpower</A>(a,b,c)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[24]">z=inv</A>(a,m)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[59]">z=elliptic</A>(n,m,p)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[25]">z=factor</A>(n)
<LI><A href="http://www.numbertheory.org/calc/krm_calc.html#[26]">z=tau</A>(n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[27]">z=sigma</A>(n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[28]">z=mobius</A>(n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[29]">z=euler</A>(n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[30]">z=lprimroot</A>(n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[31]">z=orderm</A>(a,n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[32]">z=lucas</A>(n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[33]">serret</A>(p,&x,&y)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[34]">collatz</A>(x,n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[35]">miller</A>(m,b)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[36]">hermite</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[51]">lllhermite</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[52]">shermite</A>(N)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[38]">smith</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[39]">mlll</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[40]">fp</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[42]">slv</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[54]">cycle</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[41]">inhomfp</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[44]">e=rsae</A>(p,q)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[45]">encode</A>(e,n)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[46]">decode</A>(e,p,q)
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[47]">addcubicr</A>( )
<LI><A
href="http://www.numbertheory.org/calc/krm_calc.html#[48]">powercubicr</A>( )
<LI><A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -