general.tex 151 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777
  1. @comment -*-texinfo-*-
  2. @comment This file was generated by doc2tex.pl from general.doc
  3. @comment DO NOT EDIT DIRECTLY, BUT EDIT general.doc INSTEAD
  4. @comment Id: general.tex,v 1.1 2003/08/08 14:27:06 pertusus Exp $
  5. @comment this file contains the general information about Singular
  6. @c The following directives are necessary for proper compilation
  7. @c with emacs (C-c C-e C-r). Please keep it as it is. Since it
  8. @c is wrapped in `@ignore' and `@end ignore' it does not harm `tex' or
  9. @c `makeinfo' but is a great help in editing this file (emacs
  10. @c ignores the `@ignore').
  11. @ignore
  12. %**start
  13. \input texinfo.tex
  14. @setfilename general.hlp
  15. @node Top, General concepts
  16. @menu
  17. * General concepts::
  18. @end menu
  19. @node General concepts, Data types, Introduction, Top
  20. @chapter General concepts
  21. %**end
  22. @end ignore
  23. @menu
  24. * Interactive use::
  25. * Emacs user interface::
  26. * Rings and orderings::
  27. * Implemented algorithms::
  28. * The SINGULAR language::
  29. * Input and output::
  30. * Procedures::
  31. * Libraries::
  32. * Guidelines for writing a library::
  33. * Debugging tools::
  34. @end menu
  35. @c ---------------------------------------------------------------------------
  36. @node Interactive use, Emacs user interface, General concepts, General concepts
  37. @section Interactive use
  38. @cindex Interactive use
  39. In this section, aspects of interactive use are discussed. This
  40. includes how to enter and exit @sc{Singular}, how to interpret its
  41. prompt, how to get the online help, and so on.
  42. There are a few important notes which one should not forget:
  43. @itemize @bullet
  44. @item
  45. every command has to be terminated by a @code{;} (semicolon) followed
  46. by a @key{RETURN}
  47. @item
  48. the online help is accessible by means of the @code{help} function
  49. @end itemize
  50. @menu
  51. * How to enter and exit::
  52. * The SINGULAR prompt::
  53. * The online help system::
  54. * Interrupting SINGULAR::
  55. * Editing input::
  56. * Command line options::
  57. * Startup sequence::
  58. @end menu
  59. @c --------------------------------------------------------------------------
  60. @node How to enter and exit, The SINGULAR prompt, Interactive use, Interactive use
  61. @subsection How to enter and exit
  62. @cindex How to enter and exit
  63. @sc{Singular} can either be run in ASCII-terminal or within Emacs.
  64. To start @sc{Singular} in its ASCII-terminal user interface, enter
  65. @code{Singular} at the system prompt. The
  66. @sc{Singular} banner appears which, among others, reports the version
  67. and the compilation date.
  68. To start @sc{Singular} in its Emacs user interface, either enter
  69. @code{ESingular} at the system prompt, or type @code{M-x singular}
  70. within a running Emacs (provided you have loaded the file
  71. @code{singular.el} in your running Emacs, see @ref{Running SINGULAR
  72. under Emacs} for details).
  73. Generally, we recommend to use @sc{Singular} in its Emacs interface,
  74. since this offers many more features and is more convenient to
  75. use than the ASCII-terminal interface (@pxref{Emacs user interface}).
  76. To exit @sc{Singular} type @code{quit;}, @code{exit;} or @code{$} (or,
  77. when running within Emacs preferably type @code{C-c $}).
  78. @sc{Singular} and @code{ESingular} may also be started with command line
  79. options and with
  80. filenames as arguments. More generally, the synopsis of @sc{Singular} is
  81. @smallexample
  82. Singular [options] [file1 [file2 @dots{}]]
  83. ESingular [options] [file1 [file2 @dots{}]]
  84. @end smallexample
  85. @xref{Command line options}, @ref{Startup sequence}, @ref{Running SINGULAR
  86. under Emacs}.
  87. @c --------------------------------------------------------------------------
  88. @node The SINGULAR prompt,The online help system,How to enter and exit, Interactive use
  89. @subsection The SINGULAR prompt
  90. @cindex prompt
  91. @cindex error recovery
  92. The @sc{Singular} prompt @code{>} (larger than) asks the user for input
  93. of commands. The ``continuation'' prompt @code{.} (period) asks the
  94. user for input of missing parts of a command (remember the semicolon at
  95. the end of every command).
  96. @sc{Singular} does not interpret the semicolon as the end of a command
  97. if it occurs inside a string. Also, @sc{Singular} waits for blocks
  98. (sequences of commands enclosed in curly brackets) to be closed before
  99. prompting with @code{>} for more commands. Thus, if @sc{Singular} does
  100. not respond with its regular prompt after typing a semicolon it may wait
  101. for a @code{"} or a @code{@}} first.
  102. Additional semicolons will not harm @sc{Singular} since they are
  103. interpreted as empty statements.
  104. @c --------------------------------------------------------------------------
  105. @node The online help system,Interrupting SINGULAR, The SINGULAR prompt,Interactive use
  106. @subsection The online help system
  107. @cindex The online help system
  108. @cindex online help
  109. @cindex help, online help system
  110. The online help system is invoked with the @code{help} command.
  111. @code{?} may be used as a synonym for @code{help}. Simply typing
  112. @code{help;} displays the ``top'' of the help system (i.e., the title
  113. page of the @sc{Singular} manual) which offers a
  114. short table of contents. Typing @code{help} topic@code{;} shows the
  115. available documentation on topic. Here, topic may be either a function
  116. name or, more generally, any index entry of the @sc{Singular}
  117. manual. Furthermore, topic may contain wildcard characters.
  118. @xref{help}, for more information.
  119. @cindex browsers
  120. @cindex help browsers
  121. Online help information can be displayed in various help browsers. The
  122. following table lists a summary of the supported browsers. See below for
  123. more details about particular browsers.
  124. @multitable @columnfractions .2 .2 .6
  125. @item @strong{Browser} @tab @strong{Platform}
  126. @tab @strong{Description}
  127. @item html
  128. @cindex help browsers, html
  129. @cindex html, default help
  130. @tab Windows
  131. @tab displays html version of manual in your default html browser
  132. @item winhlp
  133. @cindex help browsers, winhlp
  134. @cindex html, default help
  135. @tab Windows
  136. @tab displays Windows help (.hlp) version of manual
  137. @item netscape
  138. @cindex netscape
  139. @cindex help browsers, netscape
  140. @tab Unix, Windows
  141. @tab uses @code{netscape} to display html version of manual
  142. @item tkinfo
  143. @cindex tkinfo
  144. @cindex help browsers, tkinfo
  145. @tab Unix
  146. @tab uses the @code{tkinfo} program to display texinfo version of manual
  147. @item xinfo
  148. @cindex xinfo
  149. @cindex help browsers, xinfo
  150. @tab Unix, Windows
  151. @tab uses the @code{info} program to display texinfo version of manual in an
  152. extra @code{xterm}
  153. @item info
  154. @cindex info
  155. @cindex help browsers, info
  156. @tab Unix, Windows
  157. @tab uses the @code{info} program to display texinfo version of manual
  158. @item builtin
  159. @cindex help browsers, dummy
  160. @tab all
  161. @tab simply outputs the help information in plain ASCII format
  162. @item emacs
  163. @cindex help browsers, emacs
  164. @tab Unix, Windows
  165. @tab when running @sc{Singular} within (X)emacs, display help in
  166. (X)emacs info buffer.
  167. @item dummy
  168. @tab all
  169. @cindex help browsers, dummy
  170. @tab displays error message about no available help browser
  171. @end multitable
  172. The browser which is used to display the help information, can be either
  173. set at startup time with the command line option (@pxref{Command line
  174. options})
  175. @smallexample
  176. --brower=<browser>
  177. @end smallexample
  178. or with the @sc{Singular} command (@pxref{system})
  179. @smallexample
  180. system("--browser", <browser>);
  181. @end smallexample
  182. The @sc{Singular} command
  183. @smallexample
  184. system("browsers");
  185. @end smallexample
  186. lists all available browsers and the command
  187. @smallexample
  188. system("--browser");
  189. @end smallexample
  190. returns the currently used browser.
  191. If no browser is explicitly set by the user, then the first (w.r.t. the
  192. order of the browsers in the table above) available browser is
  193. chosen. In other words, the default browser is @code{netscape} for Unix
  194. platforms, and @code{html} for Windows, unless
  195. your local set-up does not allow to run it.
  196. The @code{.singularrc} (@pxref{Startup sequence}) file is a good place
  197. to set your default browser. Recall that if a file
  198. @code{$HOME/.singularrc} exists on your system, then the content of this
  199. file is executed before the first user input. Hence, putting
  200. @smallexample
  201. if (system("version") >= 1306) // keep backwards-compatibility
  202. @{
  203. if (! system("--emacs")
  204. @{
  205. // only set help browser if not running within emacs
  206. system("--browser", "info");
  207. @}
  208. // if help browser is later on set to netscape,
  209. // allow it to fetch HTML pages from the net
  210. system("--allow-net", 1);
  211. @}; // the last semicolon is important: otherwise no ">", but "." prompt
  212. @end smallexample
  213. in your file @code{$HOME/.singularrc} sets your default browser to
  214. @code{info}, unless @sc{Singular} is run within emacs (in which case the
  215. default browser is set automatically to @code{emacs}).
  216. Obviously, certain external files and programs are required for the
  217. @sc{Singular} help system to work correctly. If something is not available
  218. or goes wrong, here are some tips for troubleshooting the help system:
  219. @itemize @bullet
  220. @item
  221. @cindex DISPLAY environment variable
  222. @cindex environment variable, DISPLAY
  223. Under Unix, the environment variable @code{DISPLAY} has to be set for
  224. the browsers @code{netscape}, @code{tkinfo}, and @code{xinfo} to work.
  225. @item
  226. @cindex NETSCAPE environment variable
  227. @cindex XINFO environment variable
  228. @cindex XTERM environment variable
  229. @cindex INFO environment variable
  230. @cindex help browsers, setting command to use
  231. The help browsers @code{netscape}, @code{tkinfo}, @code{xinfo}, and
  232. @code{info} are only available if the respective programs are installed
  233. on your system (for @code{xinfo}, the programs @code{xterm} and
  234. @code{info} are necessary). You can explicitly specify which program to
  235. use, by setting appropriate environment variables (whose names
  236. are the names of the respective programs in all up-case letters).
  237. @*For example,
  238. to use the program @code{navigator} with a private colormap as
  239. @code{netscape} help browser, set the environment variable
  240. @code{NETSCAPE} to the value
  241. @code{"navigator -install"}.
  242. @c TBC (@xref{Setting environment variables}).
  243. @item
  244. If the help browser @code{netscape} can not find the local html
  245. pages of the @sc{Singular} manual (which it looks for at
  246. @code{$RootDir/html} -- see @ref{Loading of a library} for more info on
  247. @code{$RootDir}) @emph{and} the (command-line) option @code{--allow-net}
  248. has @emph{explicitly} been set (see @ref{Command line options} and
  249. @ref{system} for more info on
  250. setting values of command-line options), then it dispatches the html
  251. pages from
  252. @url{http://www.singular.uni-kl.de/Manual} (note that
  253. the non-local net-access of HTML pages is disabled, by default).
  254. @*An
  255. alternative location of a local directory where the html pages reside
  256. can be specified by setting the environment variable
  257. @code{SINGULAR_HTML_DIR}.
  258. @c TBC (@xref{Setting environment variables}).
  259. @item
  260. The help browsers @code{tkinfo}, @code{xinfo}, @code{info}, and
  261. @code{builtin} need the (info) file @code{singular.hlp} which it looks
  262. for at @code{$RootDir/info/singular.hlp} (see @ref{Loading of a library}
  263. for more info on @code{$RootDir}). An alternative
  264. location of the info file of the manual can be specified by setting the
  265. environment variable @code{SINGULAR_INFO_FILE}.
  266. @c TBC (@xref{Setting environment variables}).
  267. @end itemize
  268. @c inserted refs from general.doc:308
  269. @ifinfo
  270. @menu
  271. See also:
  272. * Command line options::
  273. * Loading of a library::
  274. * Startup sequence::
  275. * system::
  276. @end menu
  277. @end ifinfo
  278. @iftex
  279. @strong{See also:}
  280. @ref{Command line options};
  281. @ref{Loading of a library};
  282. @ref{Startup sequence};
  283. @ref{system}.
  284. @end iftex
  285. @c end inserted refs from general.doc:308
  286. @subsubheading Info help browsers
  287. @cindex info
  288. The help browsers @code{tkinfo}, @code{xinfo} and @code{info} (so-called
  289. info help browsers) are based on the
  290. @code{info} program from the Gnu @code{texinfo} package. @xref{Top, An
  291. Introduction to Info, Getting started, info, The Info Manual}, for more
  292. information.
  293. For info help browsers, the online manual is decomposed into ``nodes''
  294. of information, closely
  295. related to the division of the printed manual into sections and
  296. subsections. A node contains text describing a specific topic at a
  297. specific level of detail. The top line of a node is its ``header''.
  298. The node's header tells the name of the current node (@code{Node:}), the
  299. name of the next node (@code{Next:}), the name of the previous node
  300. (@code{Prev:}), and the name of the upper node (@code{Up:}).
  301. To move within info, type commands consisting of single characters. Do
  302. not type @code{RETURN}. Do not use cursor keys, either. Using some of
  303. the cursor keys by accident might pop to some totally different node.
  304. Type @code{l} to return to the original node. Some of the @code{info}
  305. commands read input from the command line at the bottom line. The
  306. @code{TAB} key may be used to complete partially entered input.
  307. The most important commands are:
  308. @table @asis
  309. @item @code{q}
  310. leaves the online help system
  311. @item @code{n}
  312. goes to the next node
  313. @item @code{p}
  314. goes to the previous node
  315. @item @code{u}
  316. goes to the upper node
  317. @item @code{m}
  318. picks a menu item specified by name
  319. @item @code{f}
  320. follows a cross reference
  321. @item @code{l}
  322. goes to the previously visited node
  323. @item @code{b}
  324. goes to the beginning of the current node
  325. @item @code{e}
  326. goes to the end of the current node
  327. @item @code{SPACE}
  328. scrolls forward a page
  329. @item @code{DEL}
  330. scrolls backward a page
  331. @item @code{h}
  332. invokes info tutorial (use @code{l} to return to the manual or
  333. @code{CTRL-X 0} to remove extra window)
  334. @item @code{CTRL-H}
  335. shows a short overview on the online help system (use @code{l} to return
  336. to the manual or @code{CTRL-X 0} to remove extra window)
  337. @item @code{s}
  338. searches through the manual for a specified string, and selects the node in
  339. which the next occurrence is found
  340. @item @code{1}, @dots{}, @code{9}
  341. picks i-th subtopic from a menu
  342. @end table
  343. @c --------------------------------------------------------------------------
  344. @node Interrupting SINGULAR,Editing input,The online help system,Interactive use
  345. @subsection Interrupting SINGULAR
  346. @cindex Interrupting SINGULAR
  347. On Unix-like operating systems and on Windows NT, typing @code{CTRL-C}
  348. (or, alternatively @code{C-c C-c}, when running within Emacs),
  349. interrupts @sc{Singular}. @sc{Singular} prints the current command and
  350. the current line and prompts for further action. The following choices
  351. are available:
  352. @table @code
  353. @item a
  354. returns to the top level after finishing the current (kernel) command. Notice
  355. that commands of the @sc{Singular} kernel (like @code{std}) can not be
  356. aborted, i.e. (@code{a})bort only happens whenever the interpreter is active.
  357. @item c
  358. continues
  359. @item q
  360. quits @sc{Singular}
  361. @end table
  362. @c --------------------------------------------------------------------------
  363. @node Editing input,Command line options,Interrupting SINGULAR,Interactive use
  364. @subsection Editing input
  365. @cindex Editing input
  366. @cindex SINGULARHIST
  367. @c This section describes only a subset of the key bindings of
  368. @c @sc{Singular} binaries built with the GNU Readline library.
  369. @c @xref{Command Line Editing, GNU Readline Library, Command Line Editing,
  370. @c readline, The GNU Readline Library Manual}, for more information.
  371. The following keys can be used for editing the input and retrieving
  372. previous input lines:
  373. @table @code
  374. @item TAB
  375. provides command line completion for function names and file names
  376. @item CTRL-B
  377. moves cursor left
  378. @item CTRL-F
  379. moves cursor right
  380. @item CTRL-A
  381. moves cursor to beginning of line
  382. @item CTRL-E
  383. moves cursor to end of line
  384. @item CTRL-D
  385. deletes character under cursor
  386. @* Warning: on an empty line, @code{CTRL-D} is interpreted as the
  387. @code{EOF} character which immediately terminates @sc{Singular}.
  388. @item BACKSPACE
  389. @itemx DELETE
  390. @itemx CTRL-H
  391. deletes character before cursor
  392. @item CTRL-K
  393. kills from cursor to end of line
  394. @item CTRL-U
  395. kills from cursor to beginning of line
  396. @item CTRL-N
  397. saves current line on history and gives next line
  398. @item CTRL-P
  399. saves current line on history and gives previous line
  400. @item RETURN
  401. saves the current line to the history and
  402. sends it to the @sc{Singular} parser for interpretation
  403. @end table
  404. When run under a Unix-like operating system and in its ASCII-terminal
  405. user interface, @sc{Singular} tries to dynamically link at runtime
  406. with the GNU Readline library. @xref{Command Line Editing, GNU Readline
  407. Library, Command Line Editing, readline, The GNU Readline Library
  408. Manual}, for more information. If a shared version of this library can
  409. be found on your machine, then additional command-line editing
  410. features like history completion are available.
  411. In particular, if @sc{Singular} is able to load that library and
  412. if the environment
  413. variable @code{SINGULARHIST} is set and has a name of a file as value,
  414. then the input history is stored across sessions using this
  415. file. Otherwise, i.e., if the environment variable @code{SINGULARHIST}
  416. is not set, then the history of the last inputs is only available for
  417. the commands of the current session.
  418. @c --------------------------------------------------------------------------
  419. @node Command line options, Startup sequence, Editing input, Interactive use
  420. @subsection Command line options
  421. @cindex Command line options
  422. The synopsis of @sc{Singular} is
  423. @smallexample
  424. Singular [options] [file1 [file2 @dots{}]]
  425. ESingular [options] [file1 [file2 @dots{}]]
  426. @end smallexample
  427. Options can be given in both, their long and short format. The following
  428. options control the general behavior of @sc{Singular}:
  429. @table @asis
  430. @item @code{-d}, @code{--sdb}
  431. @cindex -d
  432. @cindex --sdb
  433. @cindex Source code debugger, invocation
  434. Enable the use of the source code debugger.
  435. @xref{Source code debugger}.
  436. @item @code{-e}, @code{--echo[=VAL]}
  437. @cindex -e
  438. @cindex --echo
  439. Set value of variable @code{echo} to @code{VAL} (integer in the range
  440. 0, @dots{}, 9). Without an argument, @code{echo} is set to 1, which echoes
  441. all input coming from a file. By default, the value of @code{echo} is
  442. 0. @xref{echo}.
  443. @item @code{-h}, @code{--help}
  444. @cindex -h
  445. @cindex --help
  446. @cindex command-line options, short help
  447. Print a one-line description of each command line option and exit.
  448. @item @code{--allow-net}
  449. @cindex --allow-net
  450. @cindex net access
  451. @cindex allowing net access
  452. @cindex help, accessing over the net
  453. Allow the @code{netscape} and @code{html} help browser to fetch HTML manual pages over
  454. the net from the WWW home-site of @sc{Singular}. @xref{The online help
  455. system}, for more info.
  456. @item @code{--browser=VAL}
  457. @cindex --browser
  458. @cindex browser, command line option
  459. Use @code{VAL} as browser for the @sc{Singular} online manual.
  460. @*@code{VAL} may be one of @code{html} (Windows only), @code{netscape}, @code{xinfo},
  461. @code{tkinfo}, @code{info}, @code{builtin}, or @code{emacs}. Depending
  462. on your platform and local
  463. installation, only some browsers might be available. The default browser
  464. is @code{html} for Windows and @code{netscape} for Unix
  465. platforms. @xref{The online help system}, for more info.
  466. @item @code{--no-rc}
  467. @cindex --no-rc
  468. @cindex .singularrc file, no loading
  469. Do not execute the @code{.singularrc} file on start-up. By default,
  470. this file is executed on start-up. @xref{Startup sequence}.
  471. @item @code{--no-stdlib}
  472. @cindex --no-stdlib
  473. Do not load the library @code{standard.lib} on start-up. By default,
  474. this library is loaded on start-up. @xref{Startup sequence}.
  475. @item @code{--no-warn}
  476. @cindex --no-warn
  477. Do not display warning messages.
  478. @item @code{--no-out}
  479. @cindex --no-out
  480. Suppress display of all output.
  481. @item @code{-t}, @code{--no-tty}
  482. @cindex --no-tty
  483. Do not redefine the terminal characteristics. This option should be
  484. used for batch processes.
  485. @item @code{-q}, @code{--quiet}
  486. @cindex -q
  487. @cindex --quiet
  488. Do not print the start-up banner and messages when loading
  489. libraries. Furthermore, redirect @code{stderr}
  490. (all error messages) to @code{stdout} (normal output channel). This
  491. option should be used if @sc{Singular}'s output is redirected to a file.
  492. @item @code{-v}, @code{--verbose}
  493. @cindex --verbose
  494. @cindex -v
  495. Print extended information about the version and configuration of
  496. @sc{Singular} (used optional parts, compilation date, start of random
  497. generator etc.). This information should be included if a user reports
  498. an error to the authors.
  499. @end table
  500. The following command line options allow manipulations of the timer and
  501. the pseudo random generator and enable the passing of commands and strings
  502. to @sc{Singular}:
  503. @table @asis
  504. @item @code{-c}, @code{--execute=STRING}
  505. @cindex -c
  506. @cindex --execute
  507. Execute @code{STRING} as (a sequence of) @sc{Singular} commands on
  508. start-up after the @code{.singularrc} file is executed, but prior to
  509. executing the files given on the command line. E.g., @code{Singular -c
  510. "help all.lib; quit;"} shows the help for the library @code{all.lib} and
  511. exits.
  512. @item @code{-u}, @code{--user-option=STRING}
  513. @cindex -u
  514. @cindex --user-option
  515. Returns @code{STRING} on @code{system("--user-option")}. This is useful
  516. for passing arbitrary arguments from the command line to the
  517. @sc{Singular} interpreter. E.g.,
  518. @*@code{Singular -u "xxx.dump" -c 'getdump(system("--user-option"))'}
  519. reads the file @code{xxx.dump} at
  520. start-up and allows the user to start working with all the objects
  521. defined in a previous session.
  522. @item @code{-r}, @code{--random=SEED}
  523. @cindex -r
  524. @cindex --random
  525. Seed (i.e., set the initial value of) the pseudo random generator with
  526. integer @code{SEED}. If this option is not given, then the random
  527. generator is seeded with a time-based @code{SEED} (the number of
  528. seconds since January, 1, 1970, on Unix-like operating systems, to be
  529. precise).
  530. @item @code{--min-time=SECS}
  531. @cindex --min-time
  532. If the @code{timer} (@pxref{timer}), resp.@: @code{rtimer}
  533. (@pxref{rtimer}) , variable is
  534. set, report only
  535. times larger than @code{SECS} seconds (@code{SECS} needs to be a
  536. floating point number greater than 0). By default, this value is set to
  537. 0.5 (i.e., half a second). E.g., the option @code{--min-time=0.01}
  538. forces @sc{Singular} to report all times larger than 1/100 of a
  539. second.
  540. @item @code{--ticks-per-sec=TICKS}
  541. @cindex --ticks-per-sec
  542. Set unit of timer to @code{TICKS} ticks per second (i.e., the value
  543. reported by the @code{timer} and @code{rtimer} variable divided by
  544. @code{TICKS} gives the time in seconds). By default, this value is 1.
  545. @end table
  546. The next three options are of interest for the use with MP links:
  547. @table @asis
  548. @item @code{-b}, @code{--batch}
  549. @cindex -b
  550. @cindex --batch
  551. Run in MP batch mode. Opens a TCP/IP connection with host specified by
  552. @code{--MPhost} at the port specified by @code{--MPport}. Input is read
  553. from and output is written to this connection in the MP format.
  554. @xref{MPtcp links}.
  555. @item @code{--MPport=PORT}
  556. @cindex --MPport
  557. Use @code{PORT} as default port number for MP connections (whenever not
  558. further specified). This option is mandatory when the @code{--batch}
  559. option is given. @xref{MPtcp links}.
  560. @item @code{--MPhost=HOST}
  561. @cindex --MPhost
  562. Use @code{HOST} as default host for MP connections (whenever not
  563. further specified). This option is mandatory when the @code{--batch}
  564. option is given. @xref{MPtcp links}.
  565. @end table
  566. Finally, the following options are only available when running
  567. @code{ESingular} (see @ref{Running SINGULAR under Emacs} for details).
  568. @table @code
  569. @item --emacs=EMACS
  570. @cindex --emacs
  571. Use @code{EMACS} as Emacs program to run the @sc{Singular} Emacs
  572. interface, where @code{EMACS} may e.g. be emacs ore xemacs.
  573. @item --emacs-dir=DIR
  574. @cindex --emacs-dir
  575. Set the singular-emacs-home-directory, which is the directory where
  576. singular.el can be found, to @code{DIR}.
  577. @item --emacs-load=FILE
  578. @cindex --emacs-load
  579. Load @code{FILE} on Emacs start-up, instead of the default load file.
  580. @item --singular=PROG
  581. @cindex --singular
  582. Start @code{PROG} as @sc{Singular} program within Emacs
  583. @end table
  584. The value of options given to @sc{Singular} (resp.@: their default values,
  585. if an option was not given), can be checked with the command
  586. @code{system("--}long_option_name@code{")}. @xref{system}.
  587. @smallexample
  588. @c computed example Command_line_options general.doc:658
  589. system("--quiet"); // if ``quiet'' 1, otherwise 0
  590. @expansion{} 1
  591. system("--min-time"); // minimal reported time
  592. @expansion{} 0.5
  593. system("--random"); // seed of the random generator
  594. @expansion{} 12345678
  595. @c end example Command_line_options general.doc:658
  596. @end smallexample
  597. Furthermore, the value of options (e.g., @code{--browser}) can be
  598. re-set while @sc{Singular} is running with the command
  599. @code{system("--}long_option_name_string @code{",}expression@code{)}. @xref{system}.
  600. @smallexample
  601. system("--browser", "builtin"); // sets browser to 'builtin'
  602. system("--ticks-per-sec", 100); // sets timer resolution to 100
  603. @end smallexample
  604. @c --------------------------------------------------------------------------
  605. @node Startup sequence, , Command line options, Interactive use
  606. @subsection Startup sequence
  607. @cindex Startup sequence
  608. On start-up, @sc{Singular}
  609. @enumerate
  610. @item
  611. loads the library @code{standard.lib} (provided the @code{--no-stdlib}
  612. option was not given),
  613. @item
  614. @cindex file, .singularrc
  615. @cindex .singularrc file
  616. @cindex singularrc
  617. searches the current directory and then the
  618. home directory of the user, and then all directories contained in the
  619. library @code{SearchPath} (see @ref{Loading of a library} for more info
  620. on @code{SearchPath}) for a file named @code{.singularrc} and
  621. executes it, if found (provided the @code{--no-rc} option was not
  622. given),
  623. @item
  624. executes the string specified with the @code{--execute} command line
  625. option,
  626. @item
  627. executes the files @code{file1}, @code{file2} @dots{} (given on the command
  628. line) in that order.
  629. @end enumerate
  630. @strong{Note:} @code{.singularrc} file(s) are an appropriate place for
  631. setting some default values of (command-line) options.
  632. For example, a system administrator might remove the locally installed
  633. HTML version of the manual and put a @code{.singularrc} file
  634. with the following content
  635. @smallexample
  636. if (system("version") >= 1306) // assure backwards-compatibility
  637. @{
  638. system("--allow-net", 1);
  639. @}; // the last semicolon is important: otherwise no ">", but "." prompt
  640. @end smallexample
  641. in the directory containing the @sc{Singular} libraries, thereby
  642. allowing to fetch the HTML on-line help from the WWW home-site of
  643. @sc{Singular}.
  644. On the other hand, a single user might put a @code{.singularrc} with the
  645. following content
  646. @smallexample
  647. if (system("version") >= 1306) // assure backwards-compatibility
  648. @{
  649. if (! system("--emacs"))
  650. @{
  651. // set default browser to info, unless we run within emacs
  652. system("--browser", "info");
  653. @}
  654. @}; // the last semicolon is important: otherwise no ">", but "." prompt
  655. @end smallexample
  656. in his home directory, which sets the default help browser to
  657. @code{info} (unless @sc{Singular} is run within emacs) and thereby
  658. prevents the execution of the"global"
  659. @code{.singularrc} file installed by the system administrator (since the
  660. @code{.singularrc} file of the user is found before the "global"
  661. @code{.singularrc} file installed by the system administrator).
  662. @c ---------------------------------------------------------------------------
  663. @node Emacs user interface, Rings and orderings, Interactive use, General concepts
  664. @section Emacs user interface
  665. @cindex Emacs, user interface
  666. @cindex Emacs
  667. @cindex interface, Emacs
  668. @cindex user interface, Emacs
  669. Besides running @sc{Singular} in an ASCII-terminal, @sc{Singular} might
  670. also be run within Emacs. Emacs (or, XEmacs which is very similar) is a
  671. powerful and freely available text editor, which, among others,
  672. provides a framework for the implementation of interactive user
  673. interfaces. Starting from version 1.3.6, @sc{Singular} provides such an
  674. implementation, the so-called @sc{Singular} Emacs mode, or Emacs user
  675. interface.
  676. Generally, we recommend to use the Emacs interface,
  677. instead of the ASCII-terminal interface: The Emacs interface does not
  678. only provide everything the ASCII-terminal interface provides, but
  679. offers much more. Among others, it offers
  680. @itemize @bullet
  681. @item
  682. color-highlighting
  683. @item
  684. truncation of long lines
  685. @item
  686. folding of input and output
  687. @item
  688. TAB-completion for help topics
  689. @item
  690. highlighting of matching parentheses
  691. @item
  692. key-bindings and interactive menus for most user interface commands and
  693. for basic @sc{Singular} commands (such as loading of libraries and files)
  694. @item
  695. a mode for running interactive @sc{Singular} demonstrations
  696. @item
  697. convenient ways to edit @sc{Singular} input files
  698. @item
  699. interactive customization of nearly all aspects of the user-interface.
  700. @end itemize
  701. To use the @sc{Singular}-Emacs interface you need to have Emacs version
  702. 20 or higher, or XEmacs
  703. version 20.3 or higher installed on your system. These
  704. editors can be downloaded for most hard- and software platforms
  705. (including Windows
  706. 95/98/NT, but excluding the Macintosh), from either
  707. @uref{http://www.fsf.org/software/emacs/emacs.html} (Emacs), from
  708. @uref{http://www.xemacs.org} (XEmacs), or from our ftp site at
  709. @uref{ftp://www.mathematik.uni-kl.de/pub/Math/Singular/utils/}. The
  710. differences between Emacs and XEmacs w.r.t. the @sc{Singular}-Emacs
  711. interface are marginal -- which editor to use is mainly a matter of personal
  712. preferences.
  713. The simplest way to start-up @sc{Singular} in its Emacs interface is by
  714. running the program @code{ESingular} which is contained in the Singular
  715. distribution. Alternatively, @sc{Singular} can be started within an
  716. already running Emacs -- see @ref{Running SINGULAR under Emacs} for
  717. details.
  718. The next section gives a tutorial-like introduction to Emacs. This
  719. introductory section is
  720. followed by sections which explain the functionality of various aspects
  721. of the Emacs user interface in more detail: how to start/restart/kill
  722. @sc{Singular} within Emacs, how to run an interactive demonstration, how
  723. to customize the Emacs user interface, etc. Finally, the 20 most
  724. important commands of the Emacs interface together with their key
  725. bindings are listed.
  726. @menu
  727. * A quick guide to Emacs::
  728. * Running SINGULAR under Emacs::
  729. * Demo mode::
  730. * Customization of the Emacs interface::
  731. * Editing SINGULAR input files with Emacs::
  732. * Top 20 Emacs commands::
  733. @end menu
  734. @c --------------------------------------------------------------------------
  735. @node A quick guide to Emacs, Running SINGULAR under Emacs, Emacs user interface, Emacs user interface
  736. @subsection A quick guide to Emacs
  737. @cindex Emacs, overview
  738. @cindex Emacs, a quick guide
  739. This section gives a tutorial-like introduction to Emacs. Especially to
  740. users who are not familiar with Emacs, we recommend that they go through
  741. this section and try out the described features.
  742. Emacs commands generally involve the @code{CONTROL} key (sometimes
  743. labeled @code{CTRL} or @code{CTL}) or the @code{META} key. On some
  744. keyboards, the @code{META} key is labeled @code{ALT} or @code{EDIT} or
  745. something else (for example, on Sun keyboards, the diamond key to the
  746. left of the space-bar is @code{META}). If there is no @code{META} key,
  747. the @code{ESC} key can be used, instead. Rather than writing out
  748. @code{META} or
  749. @code{CONTROL} each time we want to prefix a character, we will use the
  750. following abbreviations:
  751. @multitable @columnfractions .2 .8
  752. @item @code{C-<chr>}
  753. @tab means hold the @code{CONTROL} key while typing the character
  754. @code{<chr>}. Thus, @code{C-f} would be: hold the @code{CONTROL} key and
  755. type @code{f}.
  756. @item @code{M-<chr>}
  757. @tab means hold the @code{META} key down while typing @code{<chr>}. If there
  758. is no @code{META} key, type @key{ESC}, release it, then type the
  759. character @code{<chr>}.
  760. @end multitable
  761. For user new to Emacs, we highly recommend that they go through the
  762. interactive Emacs tutorial: type @code{C-h t} to start it.
  763. For others, it is important to understand the following Emacs concepts:
  764. @table @asis
  765. @item window
  766. In Emacs terminology, a window refers to separate panes within the same
  767. window of the window system, and not to overlapping, separate
  768. windows. When using @sc{Singular} within Emacs, extra windows may appear
  769. which display help or output from certain commands. The most important
  770. window commands are:
  771. @multitable @columnfractions 2. .3 .5
  772. @item @code{C-x 1}
  773. @tab @code{File->Un-Split}
  774. @tab Un-Split window (i.e., kill other windows)
  775. @item @code{C-x o}
  776. @tab
  777. @tab Goto other window, i.e. move cursor into other window.
  778. @end multitable
  779. @item cursor and point
  780. The location of the cursor in the text is also called "point". To
  781. paraphrase, the cursor shows on the screen where point is located in
  782. the text. Here is a summary of simple cursor-moving operations:
  783. @multitable @columnfractions .2 .8
  784. @item @code{C-f} @tab Move forward a character
  785. @item @code{C-b} @tab Move backward a character
  786. @item @code{M-f} @tab Move forward a word
  787. @item @code{M-b} @tab Move backward a word
  788. @item @code{C-a} @tab Move to the beginning of line
  789. @item @code{C-e} @tab Move to the end of line
  790. @end multitable
  791. @item buffer
  792. Any text you see in an Emacs window is always part of some buffer. For
  793. example, each file you are editing with Emacs is stored inside a buffer,
  794. but also @sc{Singular} is running inside an Emacs buffer. Each buffer
  795. has a name: for example, the buffer of a file you edit usually has the
  796. same name as the file, @sc{Singular} is running in a buffer which has
  797. the name @code{*singular*} (or, @code{*singular<2>*},
  798. @code{*singular<3>*}, etc., if you have multiple @sc{Singular}
  799. sessions within the same Emacs).
  800. When you are asked for input to an Emacs command, the cursor
  801. moves to the bottom line of Emacs, i.e., to a special buffer, called the
  802. "minibuffer". Typing @key{RETURN} within the minibuffer, ends the
  803. input, typing @key{SPACE} within the minibuffer, lists all possible
  804. input values to the interactive Emacs command.
  805. The most important buffer commands are
  806. @multitable @columnfractions .2 .8
  807. @item @code{C-x b} @tab Switch buffer
  808. @item @code{C-x k} @tab Kill current buffer
  809. @end multitable
  810. Alternatively, you can switch to or kill buffers using the @code{Buffer}
  811. menu.
  812. @item Executing commands
  813. Emacs commands are executed by typing @code{M-x <command-name>}
  814. (remember that @key{SPACE} completes partial
  815. command names). Important and frequently used commands have short-cuts
  816. for their execution: Key bindings or even menu entries. For example, a
  817. file can be loaded with @code{M-x load-file}, or @code{C-x C-f}, or with
  818. the @code{File->Open} menu.
  819. @item How to exit
  820. To end the Emacs (and, @sc{Singular}) session,
  821. type @code{C-x C-c} (two characters), or use the @code{File -> Exit}
  822. menu.
  823. @item When Emacs is hung
  824. If Emacs stops responding to your commands, you can stop it safely by
  825. typing @code{C-g}, or, if this fails, by typing @code{C-]}.
  826. @item More help
  827. Nearly all aspects of Emacs are very well documented: type
  828. @code{C-h} and then a character saying what kind of help you want.
  829. For example, typing @code{C-h i} enters the @code{Info} documentation
  830. browser.
  831. @item Using the mouse
  832. Emacs is fully integrated with the mouse. In particular, clicking the
  833. right mouse button brings up a pop-up menu which usually contains a few
  834. commonly used commands.
  835. @end table
  836. @c --------------------------------------------------------------------------
  837. @node Running SINGULAR under Emacs, Demo mode, A quick guide to Emacs, Emacs user interface
  838. @subsection Running SINGULAR under Emacs
  839. @cindex Emacs, running Singular under
  840. @cindex Singular, running within Emacs
  841. @cindex Running SINGULAR under Emacs
  842. There are two ways to start the @sc{Singular} Emacs interface: Typing
  843. @code{ESingular} instead of @code{Singular} on the command shell
  844. launches a new Emacs process, initializes the interface and runs
  845. @sc{Singular} within Emacs. The other way is to start the interface in
  846. an already running Emacs, by typing @code{M-x singular} inside
  847. Emacs. This initializes the interface and runs @sc{Singular} within
  848. Emacs. Both ways are described in more detail below.
  849. Note: To properly run the Emacs interface, several files are needed
  850. which usually reside in the @code{emacs} subdirectory of your
  851. @sc{Singular} distribution. This directory is called
  852. singular-emacs-home-directory in the following.
  853. @subheading Starting the interface using ESingular
  854. As mentioned above, @code{ESingular} is an "out-of-the-box" solution:
  855. You don't have to add special things to your @code{.emacs} startup file
  856. to initialize the interface; everything is done for you in a special
  857. file called @code{.emacs-singular} (which comes along with the
  858. @sc{Singular} distribution and resides in the
  859. singular-emacs-home-directory) which is automatically loaded on Emacs
  860. startup (and the loading of the @code{.emacs} file is automatically
  861. suppressed).
  862. The customizable variables of the @sc{Singular} Emacs interface are set
  863. to defaults which give the novice user a very shell like
  864. feeling of the interface. Nevertheless, these default settings can be
  865. changed, see @ref{Customization of the Emacs interface}. Besides other
  866. Emacs initializations, such as fontification or blinking parentheses, a
  867. new menu item called @code{Singular} is added to the main menu,
  868. providing menu items for starting @sc{Singular}. On XEmacs, a button
  869. starting @sc{Singular} is added to the main toolbar.
  870. The @sc{Singular} interface is started automatically; once you see a
  871. buffer called @code{*singular*} and the @sc{Singular} prompt you are
  872. ready to start your @sc{Singular} session.
  873. @code{ESingular} inherits all @code{Singular} options. For a description
  874. off all these options, see @ref{Command line options}. Additionally
  875. there are the following options which are special to @code{ESingular}:
  876. @multitable @columnfractions .3 .7
  877. @item command-line option /
  878. @*environment variable
  879. @tab functionality
  880. @item @code{--emacs=EMACS}
  881. @*@code{ESINGULAR_EMACS}
  882. @tab Use @code{EMACS} as Emacs program to run the @sc{Singular} Emacs
  883. interface, where @code{EMACS} may e.g. be emacs or xemacs.
  884. @item @code{--emacs-dir=DIR}
  885. @*@code{ESINGULAR_EMACS_DIR}
  886. @tab Set the singular-emacs-home-directory, which is the directory where
  887. singular.el can be found, to @code{DIR}.
  888. @item @code{--emacs-load=FILE}
  889. @*@code{ESINGULAR_EMACS_LOAD}
  890. @tab Load @code{FILE} on Emacs start-up, instead of the default load file.
  891. @item @code{--singular=PROG}
  892. @*@code{ESINGULAR_SINGULAR}
  893. @tab Start @code{PROG} as @sc{Singular} program within Emacs
  894. @end multitable
  895. Notice that values of these options can also be given by setting the
  896. above mentioned environment variables (where values given as
  897. command-line arguments take priority over values given by environment
  898. variables).
  899. @subheading Starting the interface within a running Emacs
  900. If you are a more experienced Emacs user and you already have your own
  901. local @code{.emacs} startup file, you might want to start the interface
  902. out of your running Emacs without using @code{ESingular}. For this, you
  903. should add the following lisp code to your @code{.emacs} file:
  904. @smallexample
  905. (setq load-path (cons "<singular-emacs-home-directory>" load-path))
  906. (autoload 'singular "singular"
  907. "Start Singular using default values." t)
  908. (autoload 'singular-other "singular"
  909. "Ask for arguments and start Singular." t)
  910. @end smallexample
  911. Then typing @code{M-x singular} in a running Emacs session initializes
  912. the interface in a new buffer and launches a @sc{Singular} process. The
  913. @sc{Singular} prompt comes up and you are ready to start your
  914. @sc{Singular} session.
  915. It is a good idea to take a look at the (well documented) file
  916. @code{.emacs-singular} in the singular-emacs-home-directory, which comes
  917. along with the distribution. In it you find some useful initializations
  918. of the @sc{Singular} interface as well as some lisp code, which, for
  919. example, adds a button to the XEmacs toolbar. Some of this code might be
  920. useful for your @code{.emacs} file, too. And if you are a Emacs wizard,
  921. it is of course a good idea to take a look at @code{singular.el} in the
  922. singular-emacs-home-directory.
  923. @subheading Starting, interrupting and stopping SINGULAR
  924. There are the following commands to start and stop @sc{Singular}:
  925. @itemize @bullet
  926. @item @code{singular-other} (or menu @code{Singular}, item
  927. @code{Start...})
  928. Starts a @sc{Singular} process and asks for the following four
  929. parameters in the minibuffer area:
  930. @enumerate
  931. @item
  932. The Singular executable. This can either be a file name with complete
  933. path, e.g., @code{/local/bin/Singular}. Then exactly this executable is
  934. started. The path may contain the character @code{~} denoting your home
  935. directory. Or it can be the name of a command without path, e.g.,
  936. @code{Singular}. Then the executable is searched for in your
  937. @code{$PATH} environment variable.
  938. @item
  939. The default working directory. This is the path to an existing
  940. directory, e.g., @code{~/work}. The current directory is set to this
  941. directory before @sc{Singular} is started.
  942. @item
  943. Command line options. You can set any @sc{Singular} command line
  944. option (see @ref{Command line options}).
  945. @item
  946. The buffer name. You can specify the name of the buffer the interface is
  947. running in.
  948. @end enumerate
  949. @item @code{singular} (or menu @code{Singular}, item @code{Start
  950. default})
  951. Starts @sc{Singular} with default settings for the executable, the
  952. working directory, command line switches, and the buffer name. You can
  953. customize this default settings, see
  954. @ref{Customization of the Emacs interface}.
  955. @item @code{singular-exit-singular} (bound to @code{C-c $} or menu
  956. @code{Singular}, item @code{Exit})
  957. Kills the running @sc{Singular} process of the current
  958. buffer (but does not kill the buffer). Once you have killed a
  959. @sc{Singular} process you can start a new one in the same buffer with
  960. the command @code{singular} (or select the item @code{Start default} of
  961. the @code{Singular} menu).
  962. @item @code{singular-restart} (bound to @code{C-c C-r} or menu
  963. @code{Singular}, item @code{Restart})
  964. Kills the running @sc{Singular} process of the current buffer and starts
  965. a new process in the same buffer with exactly the same command line
  966. arguments as before.
  967. @item @code{singular-control-c} (bound to @code{C-c C-c} or menu @code{Singular}, item @code{Interrupt})
  968. Interrupt the Singular process running in the current buffer. Asks
  969. whether to (@code{a})bort the current @sc{Singular} command,
  970. (@code{q})uit or (@code{r})estart the current @sc{Singular} process, or
  971. (@code{c})ontinue without doing anything (default).
  972. @end itemize
  973. Whenever a @sc{Singular} process is started within the Emacs interface,
  974. the contents of a special startup file (by default
  975. @code{~/.emacs-singularrc}) is pasted as input to @sc{Singular} at the
  976. very end of the usual startup sequence (see @ref{Startup sequence}). The
  977. name of the startup file can be changed, see
  978. @ref{Customization of the Emacs interface}.
  979. @c --------------------------------------------------------------------------
  980. @node Demo mode, Customization of the Emacs interface, Running SINGULAR under Emacs, Emacs user interface
  981. @subsection Demo mode
  982. @cindex Emacs, Singular demo mode
  983. @cindex Singular, demo mode
  984. @cindex Demo mode
  985. The Emacs interface can be used to run interactive @sc{Singular}
  986. demonstrations. A demonstration is started by loading a so-called
  987. @sc{Singular} demo file with the Emacs command
  988. @code{singular-demo-load}, bound to
  989. @code{C-c C-d}, or with the menu @code{Commands->Load Demo}.
  990. A @sc{Singular} demo file should consist of @sc{Singular} commands
  991. separated by blank lines. When running a demo, the input up to the next
  992. blank line is echoed to the screen. Hitting @key{RETURN} executes the
  993. echoed commands and shows their output. Hitting @key{RETURN} again,
  994. echos the next commands to the screen, and so on, until all commands of
  995. the demo file are executed. While running a demo, you can
  996. execute other commands on the @sc{Singular} prompt: the next input of
  997. from the demo file is then echoed again, if you hit @key{RETURN} on
  998. an empty input line.
  999. A @sc{Singular} demo can prematurely be exited by either starting
  1000. another demo, or by executing the Emacs command
  1001. @code{singular-demo-exit} (menu: @code{Commands->Exit Demo}).
  1002. Some aspects of running @sc{Singular} demos can be customized.
  1003. @xref{Customization of the Emacs interface}, for more info.
  1004. @c --------------------------------------------------------------------------
  1005. @node Customization of the Emacs interface, Editing SINGULAR input files with Emacs, Demo mode, Emacs user interface
  1006. @subsection Customization of the Emacs interface
  1007. @cindex Emacs, customization of Singular mode
  1008. @cindex Singular, customization of Emacs user interface
  1009. @cindex Customization of the Emacs interface
  1010. Emacs provides a convenient interface to customize the behavior of
  1011. Emacs and the SINGULAR Emacs interface for your own needs. You enter the
  1012. customize environment by either calling @code{M-x customize} (on XEmacs
  1013. you afterwards have to enter @code{emacs} in the minibuffer area) or by
  1014. selecting the menu item @code{Options->Customize->Emacs...} for XEmacs,
  1015. and the menu item @code{Help->Customize->Toplevel Customization Group}
  1016. for Emacs, resp. A brief introduction to the customization mode comes up
  1017. with the customization buffer. All customizable parameters are
  1018. hierarchically grouped and you can browse through all these groups and
  1019. change the values of the parameters using the mouse. At the end you can
  1020. safe the settings to a special file making your changes permanent.
  1021. To change the settings of the @sc{Singular} Emacs interface you can
  1022. either select the item @code{Preferences} of the @code{Singular} menu,
  1023. call @code{M-x customize-group} and give the argument
  1024. @code{singular-interactive} in the minibuffer area, or browse from the
  1025. top-level customization group through the path
  1026. @code{External->Singular->Singular interactive}.
  1027. The @sc{Singular} interface customization buffer is divided into four
  1028. groups:
  1029. @itemize @bullet
  1030. @item Singular Faces
  1031. Here you can specify various faces used if font-lock-mode is enabled
  1032. (which it is, by default).
  1033. @item Singular Sections And Foldings
  1034. Here you can specify special faces for @sc{Singular} input and output
  1035. and change the text used as replacement for folded sections.
  1036. For doing this, you also might
  1037. find handy the function @code{customize-face-at-point},
  1038. which let's you customize the face at the current position of
  1039. point. This function is automatically defined if you run
  1040. @code{ESingular}). Otherwise, you should add its definition (see below)
  1041. to your personal @code{.emacs} file.
  1042. @item Singular Interactive Miscellaneous
  1043. Here you can specify various different things such as the behavior of
  1044. the cursor keys, the name of the special @sc{Singular} startup file, the
  1045. appearance of the help window, or the default values for the
  1046. @code{singular} command.
  1047. @c Time: I find this sentence rather confusing
  1048. @c For a first look at customization of the
  1049. @c interface, this is probably the best group.
  1050. @item Singular Demo Mode
  1051. Here you can specify how chunks of the demo file are divided, or specify
  1052. a default directory for demo files.
  1053. @end itemize
  1054. When you run @code{ESingular}, the settings of customized variables are
  1055. saved in the file @code{$HOME/.emacs-singular-cust}. Otherwise, the
  1056. settings are appended to your @code{.emacs} file. Among others, this
  1057. means that the customized settings of @code{ESingular} are not
  1058. automatically taken over by a "normal" Emacs, and vice versa.
  1059. @c --------------------------------------------------------------------------
  1060. @node Editing SINGULAR input files with Emacs, Top 20 Emacs commands, Customization of the Emacs interface, Emacs user interface
  1061. @subsection Editing SINGULAR input files with Emacs
  1062. @cindex Emacs, editing Singular input files
  1063. @cindex Singular, editing input files with Emacs
  1064. @cindex Editing SINGULAR input files with Emacs
  1065. Since @sc{Singular}'s programming language is similar to C, you
  1066. should use the Emacs C/C++-mode to edit @sc{Singular} input files and
  1067. @sc{Singular} libraries. Among others, this Emacs mode provides
  1068. automatic indentation, line-breaking and keyword highlighting.
  1069. When running @code{ESingular}, the C/C++-mode is automatically turned on
  1070. whenever a file with the suffix @code{.sing}, or @code{.lib} is loaded.
  1071. For Emacs sessions which were not started by @code{ESingular}, you
  1072. should add the following to your @code{.emacs} file:
  1073. @smallexample
  1074. ;; turn on c++-mode for files ending in ".sing" and ".lib"
  1075. (setq auto-mode-alist (cons '("\\.sing\\'" . c++-mode) auto-mode-alist))
  1076. (setq auto-mode-alist (cons '("\\.lib\\'" . c++-mode) auto-mode-alist))
  1077. ;; turn-on fontification for c++-mode
  1078. (add-hook 'c++-mode-hook
  1079. (function (lambda () (font-lock-mode 1))))
  1080. ;; turn on aut-new line and hungry-delete
  1081. (add-hook 'c++-mode-hook
  1082. (function (lambda () (c-toggle-auto-hungry-state 1))))
  1083. ;; a handy function for customization
  1084. (defun customize-face-at-point ()
  1085. "Customize face which point is at."
  1086. (interactive)
  1087. (let ((face (get-text-property (point) 'face)))
  1088. (if face
  1089. (customize-face face)
  1090. (message "No face defined at point"))))
  1091. @end smallexample
  1092. Notice that you can change the default settings for source-code
  1093. highlighting (colors, fonts, etc.) by customizing the respective faces
  1094. using the @code{Customize} feature of Emacs. For doing this, you might
  1095. find handy the above given function @code{customize-face-at-point},
  1096. which lets you customize the face of the current position of point (this
  1097. function is automatically defined if you run @code{ESingular}).
  1098. @c --------------------------------------------------------------------------
  1099. @node Top 20 Emacs commands,,Editing SINGULAR input files with Emacs, Emacs user interface
  1100. @subsection Top 20 Emacs commands
  1101. @cindex Emacs, important commands
  1102. @cindex Singular, important commands of Emacs interface
  1103. @cindex Top 20 Emacs commands
  1104. Here is a list of the 20 probably most useful commands when using the
  1105. @sc{Singular} Emacs interface.
  1106. Starting and stopping of @sc{Singular}:
  1107. @itemize @bullet
  1108. @item @code{singular} (menu @code{Singular->Start Default...}): starts
  1109. @sc{Singular} using default arguments.
  1110. @item @code{singular-other} (menu @code{Singular->Start}): starts
  1111. @sc{Singular} asking for several arguments in the minibuffer area.
  1112. @item @code{singular-exit} (key @code{C-c $} or menu
  1113. @code{Singular->Exit}): kills the @sc{Singular} process running in the
  1114. current buffer (but does not kill the buffer).
  1115. @item @code{singular-restart} (key @code{C-c C-r} or menu
  1116. @code{Singular->Restart}): kills the @sc{Singular} process running in
  1117. the current buffer and starts a new @sc{Singular} process with exactly
  1118. the same arguments as before.
  1119. @end itemize
  1120. Editing input and output:
  1121. @itemize @bullet
  1122. @item @code{singular-beginning-of-line} (key @code{C-a}): moves point to
  1123. beginning of line, then skip past the @sc{Singular} prompt, if any.
  1124. @item @code{singular-toggle-truncate-lines} (key @code{C-c C-t} or menu
  1125. @code{Commands->Truncate lines}): toggles whether long lines should be
  1126. truncated or not. If lines are not truncated, the commands
  1127. @code{singular-scroll-left} and @code{singular-scroll-right} are useful
  1128. to scroll left and right, resp.
  1129. @item @code{singular-dynamic-complete} (key @code{TAB}): performs
  1130. context specific completion. If point is inside a string, file name
  1131. completion is done. If point is at the end of a help command (i.e.,
  1132. @code{help} or @code{?}), completion on @sc{Singular} help topics is
  1133. done. If point is at the end of an example command (i.e.,
  1134. @code{example}), completion is done on @sc{Singular} examples. In all
  1135. other cases, completion on @sc{Singular} commands is done.
  1136. @c note: add space between Fold/ Unfold to avoid overfull line
  1137. @item @code{singular-folding-toggle-fold-latest-output} (key @code{C-c
  1138. C-o} or menu @code{Commands->Fold/ Unfold Latest Output}): toggles
  1139. folding of the latest output section. If your last @sc{Singular} command
  1140. produced a huge output, simply type @code{C-c C-o} and it will be
  1141. replaced by a single line.
  1142. @item @code{singular-folding-toggle-fold-at-point} (key @code{C-c C-f}
  1143. or menu @code{Commands->Fold/Unfold At Point}): toggles folding of the
  1144. section the point currently is in.
  1145. @item @code{singular-folding-fold-all-output} (menu @code{Commands->Fold
  1146. All Output}): folds all @sc{Singular} output, replacing each output
  1147. section by a single line.
  1148. @item @code{singular-folding-unfold-all-output} (menu
  1149. @code{Commands->Unfold All Output}): unfolds all @sc{Singular} output
  1150. sections showing their true contents.
  1151. @end itemize
  1152. Loading of files and @sc{Singular} demo mode:
  1153. @itemize @bullet
  1154. @item @code{singular-load-library} (key @code{C-c C-l} or menu
  1155. @code{Commands->Libraries->other...}): asks for a standard library name
  1156. or a library file in the minibuffer (hit @code{TAB} for completion) and
  1157. loads the library into @sc{Singular}. The submenu @code{Libraries} of
  1158. the @code{Commands} menu also provides a separate menu item for each
  1159. standard library.
  1160. @item @code{singular-load-file} (key @code{C-c <} or menu
  1161. @code{Commands->Load File...}): asks for a file name in the minibuffer
  1162. (which is expanded using @code{expand-file-name} if given a prefix
  1163. argument) and loads the file into @sc{Singular}.
  1164. @item @code{singular-demo-load} (key @code{C-c C-d} or menu
  1165. @code{Commands->Load Demo...}): asks for a file name of a @sc{Singular}
  1166. demo file in the minibuffer area (hit @code{SPACE} for completion) and
  1167. enters the @sc{Singular} demo mode showing the first chunk of the demo.
  1168. @item @code{singular-demo-exit} (menu @code{Commands->Exit Demo}):
  1169. exits from @sc{Singular} demo mode and cleans up everything that is
  1170. left from the demo.
  1171. @end itemize
  1172. Help and Customization:
  1173. @itemize @bullet
  1174. @item @code{singular-help} (key @code{C-h C-s} or menu
  1175. @code{Singular->Singular Help}): asks for a @sc{Singular} help topic in
  1176. the minibuffer (hit @code{TAB} for completion) and shows the help text
  1177. in a separate buffer.
  1178. @item @code{singular-example} (key @code{C-c C-e} or menu
  1179. @code{Singular->Singular Example}): asks for a @sc{Singular} command in
  1180. the minibuffer (hit @code{TAB} for completion) and executes the example
  1181. of this command in the current @sc{Singular} buffer.
  1182. @item @code{customize-group} (menu @code{Singular->Preferences}): enters
  1183. the customization group of the @sc{Singular} Emacs interface. (If called
  1184. via @code{M-x customize-group} give argument @code{singular-interactive}
  1185. in the minibuffer area.)
  1186. @end itemize
  1187. @c ---------------------------------------------------------------------------
  1188. @c ---------------------------------------------------------------------------
  1189. @node Rings and orderings, Implemented algorithms, Emacs user interface, General concepts
  1190. @section Rings and orderings
  1191. @cindex Rings and orderings
  1192. All non-trivial algorithms in @sc{Singular} require the prior definition of
  1193. a ring. Such a ring can be
  1194. @enumerate
  1195. @item
  1196. a polynomial ring over a field,
  1197. @item
  1198. a localization of a polynomial ring,
  1199. @item
  1200. a quotient ring by an ideal of one of 1.@: or 2.,
  1201. @item
  1202. a tensor product of one of 1.@: or 2.
  1203. @end enumerate
  1204. Except for quotient rings, all of these rings are realized by choosing a
  1205. coefficient field, ring variables, and an appropriate global or local
  1206. monomial ordering on the ring variables. @xref{Term orderings},
  1207. @ref{Mathematical background}.
  1208. The coefficient field of the rings may be
  1209. @cindex real
  1210. @cindex complex
  1211. @enumerate
  1212. @item
  1213. the field of rational numbers
  1214. @ifinfo
  1215. @math{Q}
  1216. @end ifinfo
  1217. @tex
  1218. $Q$
  1219. @end tex
  1220. ,
  1221. @item
  1222. @tex
  1223. finite fields $Z/p$, $p$ a prime $\le 2147483629$,
  1224. @end tex
  1225. @ifinfo
  1226. finite fields Z/p, p a prime <= 2147483629,
  1227. @end ifinfo
  1228. @item
  1229. @tex
  1230. finite fields $\hbox{GF}(p^n)$ with $p^n$ elements, $p$ a prime, $p^n \le 2^{15}$,
  1231. @end tex
  1232. @ifinfo
  1233. finite fields GF(p^n) with p^n elements, p a prime, p^n <= 2^15,
  1234. @end ifinfo
  1235. @item
  1236. transcendental extension of
  1237. @ifinfo
  1238. @math{Q}
  1239. @end ifinfo
  1240. @tex
  1241. $Q$
  1242. @end tex
  1243. or
  1244. @ifinfo
  1245. @math{Z/p}
  1246. @end ifinfo
  1247. @tex
  1248. $Z/p$
  1249. @end tex
  1250. ,
  1251. @item
  1252. simple algebraic extension of
  1253. @ifinfo
  1254. @math{Q}
  1255. @end ifinfo
  1256. @tex
  1257. $Q$
  1258. @end tex
  1259. or
  1260. @ifinfo
  1261. @math{Z/p}
  1262. @end ifinfo
  1263. @tex
  1264. $Z/p$
  1265. @end tex
  1266. ,
  1267. @item
  1268. the field of real numbers represented by floating point
  1269. numbers of a user defined precision.
  1270. @item
  1271. the field of complex numbers represented by (pairs of) floating point
  1272. numbers of a user defined precision.
  1273. @end enumerate
  1274. Throughout this manual, the current active ring in @sc{Singular} is
  1275. called basering. The reserved name @code{basering} in @sc{Singular} is
  1276. an alias for the current active ring. The basering can be set by
  1277. declaring a new ring as described in the following subsections or with
  1278. the commands @code{setring} and @code{keepring}. @xref{keepring},
  1279. @ref{setring}.
  1280. Objects of ring dependent types are local to a ring. To access them
  1281. after a change of the basering they have to be mapped using @code{map} or by
  1282. the functions @code{imap} or @code{fetch}. @xref{Objects}, @ref{fetch},
  1283. @ref{imap}, @ref{map}.
  1284. All changes of the basering in a procedure are local to this procedure
  1285. unless a @code{keepring} command is used as the last statement of the
  1286. procedure. @xref{Procedures}, @ref{keepring}.
  1287. @menu
  1288. * Examples of ring declarations::
  1289. * General syntax of a ring declaration::
  1290. * Term orderings::
  1291. @end menu
  1292. @c --------------------------------------
  1293. @node Examples of ring declarations, General syntax of a ring declaration, Rings and orderings, Rings and orderings
  1294. @subsection Examples of ring declarations
  1295. @cindex Examples of ring declarations
  1296. The exact syntax of a ring declaration is given in the next two
  1297. subsections; this subsection lists some examples first. Note that the
  1298. ordering has to be chosen such that the unit-elements of the
  1299. ring are precisely those elements with leading monomial 1. For more
  1300. information, see @ref{Monomial orderings}.
  1301. Every floating point number in a ring consists of two parts, which may be
  1302. chosen from the user. The leading part represents the number and the rest
  1303. is for the numerical stability. Two numbers with a difference only in the
  1304. rest are equal.
  1305. @itemize @bullet
  1306. @item
  1307. the ring
  1308. @ifinfo
  1309. @math{Z/32003[x,y,z]}
  1310. @end ifinfo
  1311. @tex
  1312. $Z/32003[x,y,z]$
  1313. @end tex
  1314. with degree reverse lexicographical
  1315. ordering. The exact ring declaration may be omitted in the first
  1316. example since this is the default ring:
  1317. @smallexample
  1318. ring r;
  1319. ring r = 32003,(x,y,z),dp;
  1320. @end smallexample
  1321. @item
  1322. the ring
  1323. @ifinfo
  1324. @math{Q[a,b,c,d]}
  1325. @end ifinfo
  1326. @tex
  1327. $Q[a,b,c,d]$
  1328. @end tex
  1329. with lexicographical ordering:
  1330. @smallexample
  1331. ring r = 0,(a,b,c,d),lp;
  1332. @end smallexample
  1333. @item
  1334. the ring
  1335. @ifinfo
  1336. @math{Z/7[x,y,z]}
  1337. @end ifinfo
  1338. @tex
  1339. $Z/7[x,y,z]$
  1340. @end tex
  1341. with local degree reverse lexicographical
  1342. ordering. The non-prime 10 is converted to the next lower prime in the
  1343. second example:
  1344. @smallexample
  1345. ring r = 7,(x,y,z),ds;
  1346. ring r = 10,(x,y,z),ds;
  1347. @end smallexample
  1348. @item
  1349. the ring
  1350. @tex
  1351. $Z/7[x_1,\ldots,x_6]$
  1352. @end tex
  1353. @ifinfo
  1354. Z/7[x1,@dots{},x6]
  1355. @end ifinfo
  1356. with lexicographical ordering for
  1357. @tex
  1358. $x_1,x_2,x_3$
  1359. @end tex
  1360. @ifinfo
  1361. x1,x2,x3
  1362. @end ifinfo
  1363. and degree reverse lexicographical ordering for
  1364. @tex
  1365. $x_4,x_5,x_6$:
  1366. @end tex
  1367. @ifinfo
  1368. x4,x5,x6:
  1369. @end ifinfo
  1370. @smallexample
  1371. ring r = 7,(x(1..6)),(lp(3),dp);
  1372. @end smallexample
  1373. @item
  1374. the localization of
  1375. @ifinfo
  1376. @math{(Q[a,b,c])[x,y,z]}
  1377. @end ifinfo
  1378. @tex
  1379. $(Q[a,b,c])[x,y,z]$
  1380. @end tex
  1381. at the maximal ideal
  1382. @ifinfo
  1383. @math{(x,y,z)}
  1384. @end ifinfo
  1385. @tex
  1386. $(x,y,z)$
  1387. @end tex
  1388. :
  1389. @smallexample
  1390. ring r = 0,(x,y,z,a,b,c),(ds(3), dp(3));
  1391. @end smallexample
  1392. @item
  1393. the ring
  1394. @ifinfo
  1395. @math{Q[x,y,z]}
  1396. @end ifinfo
  1397. @tex
  1398. $Q[x,y,z]$
  1399. @end tex
  1400. with weighted reverse lexicographical ordering.
  1401. The variables
  1402. @ifinfo
  1403. @math{x}
  1404. @end ifinfo
  1405. @tex
  1406. $x$
  1407. @end tex
  1408. ,
  1409. @ifinfo
  1410. @math{y}
  1411. @end ifinfo
  1412. @tex
  1413. $y$
  1414. @end tex
  1415. , and
  1416. @ifinfo
  1417. @math{z}
  1418. @end ifinfo
  1419. @tex
  1420. $z$
  1421. @end tex
  1422. have the weights 2, 1,
  1423. and 3, respectively, and vectors are first ordered by components (in
  1424. descending order) and then by monomials:
  1425. @smallexample
  1426. ring r = 0,(x,y,z),(c,wp(2,1,3));
  1427. @end smallexample
  1428. For ascending component order, the component ordering @code{C} has to be
  1429. used.
  1430. @item
  1431. the ring
  1432. @ifinfo
  1433. @math{K[x,y,z]}
  1434. @end ifinfo
  1435. @tex
  1436. $K[x,y,z]$
  1437. @end tex
  1438. , where
  1439. @ifinfo
  1440. @math{K=Z/7(a,b,c)}
  1441. @end ifinfo
  1442. @tex
  1443. $K=Z/7(a,b,c)$
  1444. @end tex
  1445. denotes the transcendental
  1446. extension of
  1447. @ifinfo
  1448. @math{Z/7}
  1449. @end ifinfo
  1450. @tex
  1451. $Z/7$
  1452. @end tex
  1453. by
  1454. @ifinfo
  1455. @math{a}
  1456. @end ifinfo
  1457. @tex
  1458. $a$
  1459. @end tex
  1460. ,
  1461. @ifinfo
  1462. @math{b}
  1463. @end ifinfo
  1464. @tex
  1465. $b$
  1466. @end tex
  1467. and
  1468. @ifinfo
  1469. @math{c}
  1470. @end ifinfo
  1471. @tex
  1472. $c$
  1473. @end tex
  1474. with degree
  1475. lexicographical ordering:
  1476. @smallexample
  1477. ring r = (7,a,b,c),(x,y,z),Dp;
  1478. @end smallexample
  1479. @item
  1480. the ring
  1481. @ifinfo
  1482. @math{K[x,y,z]}
  1483. @end ifinfo
  1484. @tex
  1485. $K[x,y,z]$
  1486. @end tex
  1487. , where
  1488. @ifinfo
  1489. @math{K=Z/7[a]}
  1490. @end ifinfo
  1491. @tex
  1492. $K=Z/7[a]$
  1493. @end tex
  1494. denotes the algebraic extension of
  1495. degree 2 of
  1496. @ifinfo
  1497. @math{Z/7}
  1498. @end ifinfo
  1499. @tex
  1500. $Z/7$
  1501. @end tex
  1502. by
  1503. @ifinfo
  1504. @math{a.}
  1505. @end ifinfo
  1506. @tex
  1507. $a.$
  1508. @end tex
  1509. In other words,
  1510. @ifinfo
  1511. @math{K}
  1512. @end ifinfo
  1513. @tex
  1514. $K$
  1515. @end tex
  1516. is the finite field with
  1517. 49 elements. In the first case,
  1518. @ifinfo
  1519. @math{a}
  1520. @end ifinfo
  1521. @tex
  1522. $a$
  1523. @end tex
  1524. denotes an algebraic
  1525. element over
  1526. @ifinfo
  1527. @math{Z/7}
  1528. @end ifinfo
  1529. @tex
  1530. $Z/7$
  1531. @end tex
  1532. with minimal polynomial
  1533. @tex
  1534. $\mu_a=a^2+a+3$,
  1535. @end tex
  1536. @ifinfo
  1537. mu_a=a^2+a+3,
  1538. @end ifinfo
  1539. in the second case,
  1540. @ifinfo
  1541. @math{a}
  1542. @end ifinfo
  1543. @tex
  1544. $a$
  1545. @end tex
  1546. refers to some generator of the cyclic group of units of
  1547. @ifinfo
  1548. @math{K}
  1549. @end ifinfo
  1550. @tex
  1551. $K$
  1552. @end tex
  1553. :
  1554. @smallexample
  1555. ring r = (7,a),(x,y,z),dp; minpoly = a^2+a+3;
  1556. ring r = (7^2,a),(x,y,z),dp;
  1557. @end smallexample
  1558. @item
  1559. the ring
  1560. @ifinfo
  1561. @math{R[x,y,z]}
  1562. @end ifinfo
  1563. @tex
  1564. $R[x,y,z]$
  1565. @end tex
  1566. , where
  1567. @ifinfo
  1568. @math{R}
  1569. @end ifinfo
  1570. @tex
  1571. $R$
  1572. @end tex
  1573. denotes the field of real
  1574. numbers represented by simple precision floating point numbers. This is
  1575. a special case:
  1576. @smallexample
  1577. ring r = real,(x,y,z),dp;
  1578. @end smallexample
  1579. @item
  1580. the ring
  1581. @ifinfo
  1582. @math{R[x,y,z]}
  1583. @end ifinfo
  1584. @tex
  1585. $R[x,y,z]$
  1586. @end tex
  1587. , where
  1588. @ifinfo
  1589. @math{R}
  1590. @end ifinfo
  1591. @tex
  1592. $R$
  1593. @end tex
  1594. denotes the field of real
  1595. numbers represented by floating point numbers of 50 valid decimal digits
  1596. and the same number of digits for the rest:
  1597. @smallexample
  1598. ring r = (real,50),(x,y,z),dp;
  1599. @end smallexample
  1600. @item
  1601. the ring
  1602. @ifinfo
  1603. @math{R[x,y,z]}
  1604. @end ifinfo
  1605. @tex
  1606. $R[x,y,z]$
  1607. @end tex
  1608. , where
  1609. @ifinfo
  1610. @math{R}
  1611. @end ifinfo
  1612. @tex
  1613. $R$
  1614. @end tex
  1615. denotes the field of real
  1616. numbers represented by floating point numbers of 10 valid decimal digits
  1617. and with 50 digits for the rest:
  1618. @smallexample
  1619. ring r = (real,10,50),(x,y,z),dp;
  1620. @end smallexample
  1621. @item
  1622. the ring
  1623. @ifinfo
  1624. @math{R(j)[x,y,z]}
  1625. @end ifinfo
  1626. @tex
  1627. $R(j)[x,y,z]$
  1628. @end tex
  1629. , where
  1630. @ifinfo
  1631. @math{R}
  1632. @end ifinfo
  1633. @tex
  1634. $R$
  1635. @end tex
  1636. denotes the field of real
  1637. numbers represented by floating point numbers of 30 valid decimal digits
  1638. and the same number for the rest.
  1639. @ifinfo
  1640. @math{j}
  1641. @end ifinfo
  1642. @tex
  1643. $j$
  1644. @end tex
  1645. denotes the imaginary unit.
  1646. @smallexample
  1647. ring r = (complex,30,j),(x,y,z),dp;
  1648. @end smallexample
  1649. @item
  1650. the ring
  1651. @ifinfo
  1652. @math{R(i)[x,y,z]}
  1653. @end ifinfo
  1654. @tex
  1655. $R(i)[x,y,z]$
  1656. @end tex
  1657. , where
  1658. @ifinfo
  1659. @math{R}
  1660. @end ifinfo
  1661. @tex
  1662. $R$
  1663. @end tex
  1664. denotes the field of real
  1665. numbers represented by floating point numbers of 6 valid decimal digits
  1666. and the same number for the rest.
  1667. @ifinfo
  1668. @math{i}
  1669. @end ifinfo
  1670. @tex
  1671. $i$
  1672. @end tex
  1673. is the default for the imaginary unit.
  1674. @smallexample
  1675. ring r = complex,(x,y,z),dp;
  1676. @end smallexample
  1677. @item
  1678. the quotient ring
  1679. @ifinfo
  1680. @math{Z/7[x,y,z]}
  1681. @end ifinfo
  1682. @tex
  1683. $Z/7[x,y,z]$
  1684. @end tex
  1685. modulo the square of the maximal
  1686. ideal
  1687. @ifinfo
  1688. @math{(x,y,z)}
  1689. @end ifinfo
  1690. @tex
  1691. $(x,y,z)$
  1692. @end tex
  1693. :
  1694. @smallexample
  1695. ring R = 7,(x,y,z), dp;
  1696. qring r = std(maxideal(2));
  1697. @end smallexample
  1698. @end itemize
  1699. @c ---------------------------------------------------------------------------
  1700. @node General syntax of a ring declaration, Term orderings, Examples of ring declarations, Rings and orderings
  1701. @subsection General syntax of a ring declaration
  1702. @cindex General syntax of a ring declaration
  1703. @subsubheading Rings
  1704. @c ------------------------------------------------------------
  1705. @c This piece of text (partially) exists also in the
  1706. @c file types.doc, chapter "ring declarations".
  1707. @c If you change something here, change it there, too!
  1708. @c ------------------------------------------------------------
  1709. @table @strong
  1710. @item Syntax:
  1711. @code{ring} name @code{=} @code{(}coefficient_field@code{),}
  1712. @code{(} names_of_ring_variables @code{),}
  1713. @code{(} ordering @code{);}
  1714. @item Default:
  1715. @code{32003,(x,y,z),(dp,C);}
  1716. @item Purpose:
  1717. declares a ring and sets it as the current basering.
  1718. @end table
  1719. The coefficient_field is given by one of the following:
  1720. @enumerate
  1721. @item
  1722. a non-negative int_expression less or equal 32003.
  1723. @* The int_expression should either be 0, specifying the field of
  1724. rational numbers Q, or a prime number p, specifying the finite field
  1725. with p elements. If it is not a prime number, int_expression is
  1726. converted to the next lower prime number.
  1727. @item
  1728. an expression_list of an int_expression and one or more names.
  1729. @* The int_expression specifies the characteristic of the coefficient
  1730. field as described above. The names are used as parameters in
  1731. transcendental or algebraic extensions of the coefficient
  1732. field. Algebraic extensions are implemented for one parameter only. In
  1733. this case, a minimal polynomial has to be defined by assignment to
  1734. @code{minpoly}. @xref{minpoly}.
  1735. @item
  1736. an expression_list of an int_expression and a name.
  1737. @* The int_expression has to be a prime number p to the power of a
  1738. positive integer n. This defines the Galois field
  1739. @tex
  1740. $\hbox{GF}(p^n)$ with $p^n$ elements, where $p^n$ has to be smaller or equal $2^{15}$.
  1741. @end tex
  1742. @ifinfo
  1743. GF(p^n) with p^n elements, where p^n has to be smaller or equal 2^15.
  1744. @end ifinfo
  1745. The given name refers to a primitive element of
  1746. @tex
  1747. $\hbox{GF}(p^n)$
  1748. @end tex
  1749. @ifinfo
  1750. GF(p^n)
  1751. @end ifinfo
  1752. generating the multiplicative group. Due to a different internal
  1753. representation, the arithmetic operations in these coefficient fields
  1754. are faster than arithmetic operations in algebraic extensions as
  1755. described above.
  1756. @item
  1757. an expression_list of the name @code{real} and two optional int_expression
  1758. giving the precision in decimal digits and
  1759. the size for the stabilizing rest. The default for the rest is the same size
  1760. as for the representation.
  1761. An exception is the name @code{real} without any integers.
  1762. These numbers are implemented as machine floating point numbers
  1763. of single precision.
  1764. Note that computations over all these fields are not exact.
  1765. @item
  1766. an expression_list of the name @code{complex},
  1767. two optional int_expression and a name.
  1768. This specifies the field of complex numbers represented with floating point
  1769. numbers with a precision similar to @code{real}. An expression_list
  1770. without int_expression defines a precision and rest with length 6.
  1771. The name of the imaginary unit is given by the last parameter.
  1772. Note that computations over these fields are not exact.
  1773. @end enumerate
  1774. 'names_of_ring_variables' is a list of names or indexed names.
  1775. 'ordering' is a list of block orderings where each block ordering is either
  1776. @enumerate
  1777. @item
  1778. @code{lp}, @code{dp}, @code{Dp}, @code{ls}, @code{ds}, or @code{Ds}
  1779. optionally followed by a size parameter in parentheses.
  1780. @item
  1781. @code{wp}, @code{Wp}, @code{ws}, @code{Ws}, or @code{a} followed by a
  1782. weight vector given as an intvec_expression in parentheses.
  1783. @item
  1784. @code{M} followed by an intmat_expression in parentheses.
  1785. @item
  1786. @code{c} or @code{C}.
  1787. @end enumerate
  1788. For the definition of the orderings, see @ref{Monomial orderings}.
  1789. If one of coefficient_field, names_of_ring_variables, and ordering
  1790. consists of only one entry, the parentheses around this entry may be
  1791. omitted.
  1792. @c ------------------------------------------------------------
  1793. @c End of duplicate piece of text.
  1794. @c ------------------------------------------------------------
  1795. @subsubheading Quotient rings
  1796. @c ------------------------------------------------------------
  1797. @c This piece of text (partially) exists also in the
  1798. @c file types.doc, chapter "qring declarations", and in
  1799. @c singular.doc, chapter "Miscellaneous oddities".
  1800. @c If you change something here, change it there, too!
  1801. @c ------------------------------------------------------------
  1802. @table @strong
  1803. @item Syntax:
  1804. @code{qring} name @code{=} ideal_expression @code{;}
  1805. @item Default:
  1806. none
  1807. @item Purpose:
  1808. declares a quotient ring as the basering modulo ideal_expression. Sets
  1809. it as current basering.
  1810. @end table
  1811. ideal_expression has to be represented by a standard basis.
  1812. The most convenient way to map objects from a ring to its quotient ring
  1813. and vice versa is to use the @code{fetch} function (@pxref{fetch}).
  1814. @sc{Singular} computes in a quotient ring as long as possible with the
  1815. given representative of a polynomial, say, @code{f}. I.e., it usually
  1816. does not reduce @code{f} w.r.t. the quotient ideal. This is only done
  1817. when necessary
  1818. during standard bases computations or by an explicit reduction using
  1819. the command @code{reduce(f, std(0))} (@pxref{reduce}).
  1820. @strong{Example:}
  1821. @smallexample
  1822. @c computed example Quotient_rings general.doc:1784
  1823. ring r=32003,(x,y),dp;
  1824. poly f=x3+yx2+3y+4;
  1825. qring q=std(maxideal(2));
  1826. basering;
  1827. @expansion{} // characteristic : 32003
  1828. @expansion{} // number of vars : 2
  1829. @expansion{} // block 1 : ordering dp
  1830. @expansion{} // : names x y
  1831. @expansion{} // block 2 : ordering C
  1832. @expansion{} // quotient ring from ideal
  1833. @expansion{} _[1]=y2
  1834. @expansion{} _[2]=xy
  1835. @expansion{} _[3]=x2
  1836. poly g=fetch(r, f);
  1837. g;
  1838. @expansion{} x3+x2y+3y+4
  1839. reduce(g,std(0));
  1840. @expansion{} 3y+4
  1841. @c end example Quotient_rings general.doc:1784
  1842. @end smallexample
  1843. @c ------------------------------------------------------------
  1844. @c End of duplicate piece of text.
  1845. @c ------------------------------------------------------------
  1846. @c ---------------------------------------------------------------------------
  1847. @node Term orderings, , General syntax of a ring declaration, Rings and orderings
  1848. @subsection Term orderings
  1849. @cindex Monomial orderings, Term orderings
  1850. Any polynomial (resp.@: vector) in @sc{Singular} is ordered w.r.t. a
  1851. term ordering (or, monomial ordering), which has to be specified
  1852. together with the declaration of a ring. @sc{Singular} stores and
  1853. displays a polynomial (resp.@: vector) w.r.t. this ordering, i.e., the
  1854. greatest monomial (also called the leading monomial) is the first one
  1855. appearing in the output polynomial, and the smallest monomial is the last one.
  1856. @strong{Remark:} The novice user should generally use the ordering
  1857. @code{dp} for computations in the polynomial ring
  1858. @tex
  1859. $K[x_1,\ldots,x_n]$,
  1860. @end tex
  1861. @ifinfo
  1862. K[x1,...,xn],
  1863. @end ifinfo
  1864. resp.@: @code{ds} for computations in the localization
  1865. @tex
  1866. $\hbox{Loc}_{(x)}K[x_1,\ldots,x_n])$.
  1867. @end tex
  1868. @ifinfo
  1869. Loc_(x)K[x1,...,xn]).
  1870. @end ifinfo
  1871. For more details, see @ref{Polynomial data}.
  1872. In a ring declaration, @sc{Singular} offers the following orderings:
  1873. @enumerate
  1874. @item Global orderings
  1875. @table @asis
  1876. @item @code{lp}
  1877. lexicographical ordering
  1878. @item @code{dp}
  1879. degree reverse lexicographical ordering
  1880. @item @code{Dp}
  1881. degree lexicographical ordering
  1882. @item @code{wp(} intvec_expression @code{)}
  1883. weighted reverse lexicographical ordering; the weight vector may
  1884. consist of positive integers only.
  1885. @item @code{Wp(} intvec_expression @code{)}
  1886. weighted lexicographical ordering; the weight vector may consist of
  1887. positive integers only.
  1888. @end table
  1889. Global orderings are well-orderings, i.e.,
  1890. @ifinfo
  1891. @math{1 < x}
  1892. @end ifinfo
  1893. @tex
  1894. $1 < x$
  1895. @end tex
  1896. for each ring
  1897. variable
  1898. @ifinfo
  1899. @math{x}
  1900. @end ifinfo
  1901. @tex
  1902. $x$
  1903. @end tex
  1904. . They are denoted by a @code{p} as the second
  1905. character in their name.
  1906. @item Local orderings
  1907. @table @asis
  1908. @item @code{ls}
  1909. negative lexicographical ordering
  1910. @item @code{ds}
  1911. negative degree reverse lexicographical ordering
  1912. @item @code{Ds}
  1913. negative degree lexicographical ordering
  1914. @item @code{ws(} intvec_expression @code{)}
  1915. (general) weighted reverse lexicographical ordering; the first element
  1916. of the weight vector has to be non-zero.
  1917. @item @code{Ws(} intvec_expression @code{)}
  1918. (general) weighted lexicographical ordering; the first element
  1919. of the weight vector has to be non-zero.
  1920. @end table
  1921. Local orderings are not well-orderings. They are denoted by an @code{s}
  1922. as the second character in their name.
  1923. @item Matrix orderings
  1924. @table @asis
  1925. @item @code{M(} intmat_expression @code{)}
  1926. intmat_expression has to be an invertible square matrix
  1927. @end table
  1928. Using matrix orderings, @sc{Singular} can compute standard bases
  1929. w.r.t.@: any monomial ordering that is compatible with the natural
  1930. semi-group structure on the monomials. In practice, the predefined global
  1931. and local orderings together with the block orderings should be
  1932. sufficient in most cases. These orderings are faster than their
  1933. corresponding matrix orderings since evaluation of a matrix ordering is
  1934. time consuming.
  1935. @item Extra weight vector
  1936. @table @asis
  1937. @item @code{a(} intvec_expression @code{)}
  1938. an extra weight vector @code{a(} intvec_expression @code{)} may precede
  1939. any monomial ordering
  1940. @end table
  1941. @item Product ordering
  1942. @table @asis
  1943. @item @code{(} ordering [ @code{(} int_expression @code{)} ]@code{,} @dots{} @code{)}
  1944. any of the above orderings and the extra weight vector may be combined
  1945. to yield product or block orderings
  1946. @end table
  1947. The orderings @code{lp}, @code{dp}, @code{Dp}, @code{ls}, @code{ds}, and
  1948. @code{Ds} may be followed by an int_expression in parentheses giving the
  1949. size of the block. For the last block the size is calculated
  1950. automatically. For the weighted orderings the size of the block is given
  1951. by the size of the weight vector. The same holds analogously for matrix
  1952. orderings.
  1953. @item Module orderings
  1954. @table @asis
  1955. @itemx @code{(} ordering@code{,} @dots{}@code{, C )}
  1956. @item @code{(} ordering@code{,} @dots{}@code{, c )}
  1957. sort polynomial vectors by the monomial ordering first, then by
  1958. components
  1959. @itemx @code{( C,} ordering@code{,} @dots{} @code{)}
  1960. @item @code{( c,} ordering@code{,} @dots{} @code{)}
  1961. sort polynomial vectors by components first, then by the monomial
  1962. ordering
  1963. @end table
  1964. Here a capital @code{C} sorts generators in ascending order, i.e.,
  1965. @code{gen(1)} < @code{gen(2)} < @enddots{} A small @code{c} sorts in
  1966. descending order, i.e., @code{gen(1)} > @code{gen(2)} > @enddots{} It is
  1967. not necessary to specify the module ordering explicitly since @code{(}
  1968. ordering@code{,} @dots{}@code{, C )} is the default.
  1969. In fact, @code{c} or @code{C} may be specified anywhere in a product
  1970. ordering specification, not only at its beginning or end. All monomial
  1971. block orderings preceding the component ordering have higher precedence,
  1972. all monomial block orderings following after it have lower precedence.
  1973. @end enumerate
  1974. For a mathematical description of these orderings, see
  1975. @ref{Polynomial data}.
  1976. @c ---------------------------------------------------------------------------
  1977. @node Implemented algorithms, The SINGULAR language, Rings and orderings, General concepts
  1978. @section Implemented algorithms
  1979. @cindex Implemented algorithms
  1980. The basic algorithm in @sc{Singular} is a general standard basis algorithm for
  1981. any monomial ordering which is compatible with the natural semi-group
  1982. structure of the exponents. This includes well-orderings
  1983. (Buchberger algorithm to compute a Groebner basis)
  1984. and tangent cone orderings (Mora algorithm) as special cases.
  1985. Nonetheless, there are a lot of other important algorithms:
  1986. @itemize @bullet
  1987. @item
  1988. Algorithms to compute the standard operations on ideals and modules:
  1989. intersection, ideal quotient, elimination, etc.
  1990. @item
  1991. Different Syzygy algorithms and algorithms to compute free resolutions
  1992. of modules.
  1993. @item
  1994. Combinatorial algorithms to compute dimensions, Hilbert series,
  1995. multiplicities, etc.
  1996. @item
  1997. Algorithms for univariate and multivariate polynomial factorization,
  1998. resultant and gcd computations.
  1999. @end itemize
  2000. @c ----------------------------------------------------------------------
  2001. @subheading Commands to compute standard bases
  2002. @table @code
  2003. @item facstd
  2004. @ref{facstd}
  2005. @*computes a list of Groebner bases via the Factorizing Groebner Basis
  2006. Algorithm, i.e., their intersection has the same radical as the original ideal. It need not
  2007. be a Groebner basis of the given ideal.
  2008. The intersection of the zero-sets is the zero-set of the given ideal.
  2009. @item fglm
  2010. @ref{fglm}
  2011. @*computes a Groebner basis provided that a reduced Groebner basis
  2012. w.r.t.@: another ordering is given.
  2013. Implements the so-called FGLM (Faugere, Gianni, Lazard, Mora) algorithm.
  2014. The given ideal must be zero-dimensional.
  2015. @item groebner
  2016. @ref{groebner}@*
  2017. computes a standard resp.@: Groebner bases using a heuristically chosen
  2018. method.
  2019. This is the preferred method to compute a standard resp.@: Groebner
  2020. bases.
  2021. @item mstd
  2022. @ref{mstd}
  2023. @*computes a standard basis and a minimal set of generators.
  2024. @item std
  2025. @ref{std}
  2026. @*computes a standard resp.@: Groebner basis.
  2027. @item stdfglm
  2028. @ref{stdfglm}
  2029. @*computes a Groebner basis in a ring with a ``difficult'' ordering
  2030. (e.g., lexicographical) via @code{std} w.r.t.@: a ``simple'' ordering and
  2031. @code{fglm}.
  2032. The given ideal must be zero-dimensional.
  2033. @item stdhilb
  2034. @ref{stdhilb}@*
  2035. computes a Groebner basis in a ring with a ``difficult'' ordering
  2036. (e.g., lexicographical) via @code{std} w.r.t.@: a ``simple'' ordering
  2037. and a @code{std} computation guided by the Hilbert series.
  2038. @end table
  2039. @c ----------------------------------------------------------------------
  2040. @subheading Further processing of standard bases
  2041. The next commands require the input to be a standard basis.
  2042. @table @code
  2043. @item degree
  2044. @ref{degree}
  2045. @*computes the (Krull) dimension, codimension and the multiplicity.
  2046. The result is only displayed on the screen.
  2047. @item dim
  2048. @ref{dim}@*
  2049. computes the dimension of the ideal resp.@: module.
  2050. @item highcorner
  2051. @ref{highcorner}@*
  2052. computes the smallest monomial not contained in the ideal resp.@: module.
  2053. The ideal resp.@: module has to be finite dimensional as a vector space
  2054. over the ground field.
  2055. @item hilb
  2056. @ref{hilb}@*
  2057. computes the first, and resp.@: or, second Hilbert series of an ideal
  2058. resp.@: module.
  2059. @item kbase
  2060. @ref{kbase}@* computes a vector space basis (consisting of monomials) of
  2061. the quotient of a ring by an ideal resp.@: of a free module by a
  2062. submodule.
  2063. The ideal resp.@: module has to be finite dimensional as a vector space
  2064. over the ground field and has to be represented by a standard basis w.r.t.@:
  2065. the ring ordering.
  2066. @item mult
  2067. @ref{mult}@*
  2068. computes the degree of the monomial ideal resp.@: module generated by
  2069. the leading monomials of the input.
  2070. @item reduce
  2071. @ref{reduce}@*
  2072. reduces a polynomial, vector, ideal or module to its normal form with
  2073. respect to an ideal or module represented by a standard basis.
  2074. @item vdim
  2075. @ref{vdim}@*
  2076. computes the vector space dimension of a ring (resp.@: free module)
  2077. modulo an ideal (resp.@: module).
  2078. @end table
  2079. @c ----------------------------------------------------------------------
  2080. @subheading Commands to compute resolutions
  2081. @table @code
  2082. @item res
  2083. @ref{res}@*
  2084. computes a free resolution of an ideal or module using a heuristically
  2085. chosen method.
  2086. This is the preferred method to compute free resolutions of ideals or
  2087. modules.
  2088. @item lres
  2089. @ref{lres}@*
  2090. computes a free resolution of an ideal or module with La Scala's
  2091. method. The input needs to be homogeneous.
  2092. @item mres
  2093. @ref{mres}@*
  2094. computes a minimal free resolution of an ideal or module with the Syzygy
  2095. method.
  2096. @item sres
  2097. @ref{sres}@*
  2098. computes a free resolution of an ideal or module with Schreyer's
  2099. method. The input has to be a standard basis.
  2100. @item nres
  2101. @ref{nres}@*
  2102. computes a free resolution of an ideal or module with the standard basis
  2103. method.
  2104. @item syz
  2105. @ref{syz}@*
  2106. computes the first Syzygy (i.e., the module of relations of the
  2107. given generators).
  2108. @end table
  2109. @c ----------------------------------------------------------------------
  2110. @subheading Further processing of resolutions
  2111. @table @code
  2112. @item betti
  2113. @ref{betti}@*
  2114. computes the graded Betti numbers of a module from a free resolution.
  2115. @item minres
  2116. @ref{minres}@*
  2117. minimizes a free resolution of an ideal or module.
  2118. @item regularity
  2119. @ref{regularity}@*
  2120. computes the regularity of a homogeneous ideal resp.@: module from a given
  2121. minimal free resolution.
  2122. @end table
  2123. @c ----------------------------------------------------------------------
  2124. @subheading Processing of polynomials
  2125. @table @code
  2126. @item char_series
  2127. @ref{char_series}@*
  2128. computes characteristic sets of polynomial ideals.
  2129. @item extgcd
  2130. @ref{extgcd}@*
  2131. computes the extended gcd of two polynomials.
  2132. Implemented as extended Euclidean Algorithm. Applicable for univariate
  2133. polynomials only.
  2134. @item factorize
  2135. @ref{factorize}@*
  2136. computes factorization of univariate and multivariate polynomials into
  2137. irreducible factors.
  2138. The most basic algorithm is univariate factorization in prime
  2139. characteristic. The Cantor-Zassenhaus Algorithm is used in this case.
  2140. For characteristic 0, a univariate Hensel-lifting is done to lift from
  2141. prime characteristic to characteristic 0. For multivariate
  2142. factorization in any characteristic, the problem is reduced to the
  2143. univariate case first, then a multivariate Hensel-lifting is used to
  2144. lift the univariate factorization.
  2145. Note that there is no factorization of polynomials over algebraic
  2146. extensions of Q.
  2147. @item gcd
  2148. @ref{gcd}@*
  2149. computes greatest common divisors of univariate and multivariate polynomials.
  2150. For prime characteristic, a subresultant gcd is used. In characteristic 0, a
  2151. modular algorithm is used for the univariate case. For the multivariate case,
  2152. the EZGCD is used.
  2153. Note that there is no gcd calculation for polynomials over algebraic
  2154. extensions of Q.
  2155. @item resultant
  2156. @ref{resultant}@*
  2157. computes the resultant of two univariate polynomials using the subresultant
  2158. algorithm.
  2159. Multivariate polynomials are considered as univariate polynomials in the
  2160. main variable (which has to be specified by the user).
  2161. @item vandermonde
  2162. @ref{vandermonde}@*
  2163. interpolates a polynomial from its values at several points
  2164. @end table
  2165. @c ----------------------------------------------------------------------
  2166. @subheading Matrix computations
  2167. @table @code
  2168. @item bareiss
  2169. @ref{bareiss}@*
  2170. implements sparse Gauss-Bareiss method for elimination (matrix
  2171. triangularization) in arbitrary integral domains.
  2172. @item det
  2173. @ref{det}@*
  2174. computes the determinant of a square matrix.
  2175. For matrices with integer entries a modular algorithm is used. For
  2176. other domains the Gauss-Bareiss method is used.
  2177. @item minor
  2178. @ref{minor}@*
  2179. computes all minors (=subdeterminants) of a given size for a matrix.
  2180. @end table
  2181. @c ----------------------------------------------------------------------
  2182. @subheading Numeric computations
  2183. @table @code
  2184. @item laguerre
  2185. @ref{laguerre}@*
  2186. computes all (complex) roots of a univariate polynomial
  2187. @item uressolve
  2188. @ref{uressolve}@*
  2189. find all roots of 0-dimensional ideal i with multivariate resultants
  2190. @end table
  2191. @c ----------------------------------------------------------------------
  2192. @subheading Controlling computations
  2193. @table @code
  2194. @item option
  2195. @ref{option}@*
  2196. allows setting of options for manipulating the behavior of computations
  2197. (such as reduction strategies) and for showing protocol information indicating
  2198. the progress of a computation.
  2199. @end table
  2200. @c ---------------------------------------------------------------------------
  2201. @node The SINGULAR language, Input and output, Implemented algorithms, General concepts
  2202. @section The SINGULAR language
  2203. @cindex The SINGULAR language
  2204. @sc{Singular} interprets commands given interactively on the command
  2205. line as well as given in the context of user-defined procedures. In
  2206. fact, @sc{Singular} makes no distinction between these two cases.
  2207. Thus, @sc{Singular} offers a powerful programming language as well as
  2208. an easy-to-use command line interface without differences in syntax or
  2209. semantics.
  2210. In the following, the basic language concepts such as commands,
  2211. expressions, names, objects, etc., are discussed. @xref{Procedures},
  2212. and @ref{Libraries},
  2213. for the concepts of procedures
  2214. and libraries.
  2215. In many aspects, the @sc{Singular} language is similar to the C
  2216. programming language. For a description of some of the subtle
  2217. differences, see @ref{Major differences to the C programming language}.
  2218. @subsubheading Elements of the language
  2219. The major building blocks of the @sc{Singular} language are
  2220. expressions, commands, and control structures. The notion of expressions
  2221. in the @sc{Singular} and the C programming language are identical,
  2222. whereas the notion of commands and control structures only roughly
  2223. corresponds to the C statements.
  2224. @itemize @bullet
  2225. @item
  2226. An ``expression'' is a sequence of operators, functions, and operands
  2227. that specifies a computation. An expression always results in a
  2228. value of a specific type. @xref{Data types}, and its subsections (e.g.,
  2229. @ref{poly expressions}), for information on how to build expressions.
  2230. @item
  2231. A ``command'' is either a declaration, an assignment, a call to a
  2232. function without return value, or a print command. For detailed
  2233. information, see @ref{General command syntax}.
  2234. @item
  2235. ``Control structures'' determine the execution sequence of commands.
  2236. @sc{Singular} provides control structures for conditional execution
  2237. (@code{if} @dots{} @code{else}) and iteration (@code{for} and
  2238. @code{while}). Commands may be grouped in pairs of @code{@{} @code{@}}
  2239. (curly brackets) to form blocks. @xref{Control structures}, for
  2240. more information.
  2241. @end itemize
  2242. @subsubheading Other notational conventions
  2243. For user-defined functions, the notion of ``procedure'' and
  2244. ``function'' are synonymous.
  2245. As already mentioned above, functions without return values are called
  2246. commands. Furthermore, whenever convenient, the term ``command'' is
  2247. used for a function, even if it does return a value.
  2248. @menu
  2249. * General command syntax::
  2250. * Special characters::
  2251. * Names::
  2252. * Objects::
  2253. * Type conversion and casting::
  2254. * Flow control::
  2255. @end menu
  2256. @c ---------------------------------------------------------------------------
  2257. @node General command syntax, Special characters, The SINGULAR language, The SINGULAR language
  2258. @subsection General command syntax
  2259. @cindex General command syntax
  2260. In @sc{Singular} a command is either a declaration, an assignment, a
  2261. call to a function without return value, or a print command. The general
  2262. form of a command is described in the following subsections.
  2263. @subsubheading Declaration
  2264. @enumerate
  2265. @item type name @code{=} expression @code{;}
  2266. @* declares a variable with the given name of the given type and assigns
  2267. the expression as initial value to it. Expression is an expression of
  2268. the specified type or one that can be converted to that type.
  2269. @xref{Type conversion and casting}.
  2270. @item type name_list @code{=} expression_list @code{;}
  2271. @* declares variables with the given names and assigns successively each
  2272. expression of expression_list to the corresponding name of
  2273. name_list. Both lists must be of the same length. Each expression in
  2274. expression_list is an expression of the specified type or one that can
  2275. be converted to that type. @xref{Type conversion and casting}.
  2276. @item type name @code{;}
  2277. @* declares a variable with the given name of the given type and assigns
  2278. the default value of the specific type to it.
  2279. @end enumerate
  2280. @xref{Names}, for more information on declarations. @xref{Data types},
  2281. for a description of all data types known to @sc{Singular}.
  2282. @smallexample
  2283. ring r; // the default ring
  2284. poly f,g = x^2+y^3,xy+z2; // the polynomials f=x^2+y^3 and g=x*y+z^2
  2285. ideal I = f,g; // the ideal generated by f and g
  2286. matrix m[3][3]; // a 3 x 3 zero matrix
  2287. int i=2; // the integer i=2
  2288. @end smallexample
  2289. @subsubheading Assignment
  2290. @enumerate 4
  2291. @item
  2292. name @code{=} expression @code{;}
  2293. @* assigns expression to name.
  2294. @item
  2295. name_list @code{=} expression_list @code{;}
  2296. @* assigns successively each expression of expression_list to the
  2297. corresponding name of name_list. Both lists must be of the same
  2298. length. This is not a simultaneous assignment. Thus, @code{f, g = g, f;} does
  2299. not swap the values of @code{f} and @code{g}, but rather assigns
  2300. @code{g} to both @code{f} and @code{g}.
  2301. @end enumerate
  2302. There must be a type conversion of the type of expression to the type of
  2303. name. @xref{Type conversion and casting}.
  2304. An assignment itself does not yield a value. Hence, compound assignments
  2305. like @code{i = j = k;} are not allowed and result in an error.
  2306. @smallexample
  2307. f = x^2 + y^2 ; // overwrites the old value of f
  2308. I = jacob(f);
  2309. f,g = I[1],x^2+y^2 ; // overwrites the old values of f and g
  2310. @end smallexample
  2311. @subsubheading Function without return value
  2312. @enumerate 6
  2313. @item
  2314. function_name [ @code{(} argument_list @code{)} ] @code{;}
  2315. @* calls function function_name with arguments argument_list.
  2316. @end enumerate
  2317. The function may have output (not to be confused with a return value of
  2318. type string). @xref{Functions}. Functions without a return value are
  2319. specified there to have a return type 'none'.
  2320. Some of these functions have to be called without parentheses, e.g.,
  2321. @code{help}, @code{LIB}.
  2322. @smallexample
  2323. @c computed example Function_without_return_value general.doc:2344
  2324. ring r;
  2325. ideal i=x2+y2,x;
  2326. i=std(i);
  2327. degree(i); // degree has no return value but prints output
  2328. @expansion{} 2
  2329. @c end example Function_without_return_value general.doc:2344
  2330. @end smallexample
  2331. @subsubheading Print command
  2332. @enumerate 7
  2333. @item
  2334. expression @code{;}
  2335. @* prints the value of an expression, for example, of a variable.
  2336. @end enumerate
  2337. Use the function @code{print} (or the procedure show from inout.lib)
  2338. to get a pretty output of various data
  2339. types, e.g., matrix or intmat. @xref{print}.
  2340. @smallexample
  2341. @c computed example Print_command general.doc:2364
  2342. int i=2;
  2343. i;
  2344. @expansion{} 2
  2345. intmat m[2][2]=1,7,10,0;
  2346. print(m);
  2347. @expansion{} 1 7
  2348. @expansion{} 10 0
  2349. @c end example Print_command general.doc:2364
  2350. @end smallexample
  2351. @c ------------------------------------------------------------
  2352. @node Special characters, Names, General command syntax, The SINGULAR language
  2353. @subsection Special characters
  2354. @cindex Special characters
  2355. The following characters and operators have special meaning:
  2356. @table @asis
  2357. @item @code{=}
  2358. @cindex =
  2359. assignment
  2360. @item @code{(}, @code{)}
  2361. @cindex (
  2362. @cindex )
  2363. @cindex indexed names
  2364. in expressions, for indexed names and for argument lists
  2365. @item @code{[}, @code{]}
  2366. @cindex [
  2367. @cindex ]
  2368. access operator for strings, integer vectors, ideals, matrices,
  2369. polynomials, resolutions, and lists. Used to build vectors of
  2370. polynomials. Example: @code{s[3]}, @code{m[1,3]}, @code{i[1..3]},
  2371. @code{[f,g+x,0,0,1]}.
  2372. @item @code{+}
  2373. @cindex +
  2374. addition operator
  2375. @item @code{-}
  2376. @cindex -
  2377. subtraction operator
  2378. @item @code{*}
  2379. @cindex *
  2380. multiplication operator
  2381. @item @code{/}
  2382. @cindex /
  2383. division operator. @xref{Miscellaneous oddities}, for the difference
  2384. between the division operators @code{/} and @code{div}.
  2385. @item @code{%}
  2386. @cindex %
  2387. modulo operator
  2388. @item @code{^} or @code{**}
  2389. @cindex ^
  2390. @cindex **
  2391. exponentiation operator
  2392. @item @code{==}
  2393. @cindex ==
  2394. comparison operator equal
  2395. @item @code{!=} or @code{<>}
  2396. @cindex !=
  2397. @cindex <>
  2398. comparison operator not equal
  2399. @item @code{>=}
  2400. @cindex >=
  2401. comparison operator bigger or equal
  2402. @item @code{>}
  2403. @cindex >
  2404. comparison operator bigger
  2405. @item @code{<=}
  2406. @cindex <=
  2407. comparison operator smaller or equal
  2408. @item @code{<}
  2409. @cindex <
  2410. comparison operator smaller. Also used for file input. @xref{filecmd}.
  2411. @item @code{!}
  2412. @cindex !
  2413. boolean operator not
  2414. @item @code{&&}
  2415. @cindex &&
  2416. boolean operator and
  2417. @item @code{||}
  2418. @cindex ||
  2419. boolean operator or
  2420. @item @code{"}
  2421. @cindex "
  2422. delimiter for string constants
  2423. @item @code{`}
  2424. @cindex `
  2425. delimiter for name substitution
  2426. @item @code{?}
  2427. @cindex ?
  2428. synonym for @code{help}
  2429. @item @code{//}
  2430. @cindex //
  2431. comment delimiter. Comment extends to end of line.
  2432. @item @code{/*}
  2433. @cindex //
  2434. comment delimiter. Starts a comment which ends with @code{*/}.
  2435. @item @code{*/}
  2436. @cindex //
  2437. comment delimiter. Ends a comment which starts with @code{/*}.
  2438. @item @code{;}
  2439. @cindex ;
  2440. statement separator
  2441. @item @code{,}
  2442. separator for expression lists and function arguments
  2443. @item @code{\}
  2444. @cindex \
  2445. escape character for @code{"} and @code{\} within strings
  2446. @item @code{..}
  2447. @cindex ..
  2448. interval specifier returning intvec.
  2449. E.g., @code{1..3} which is equivalent to the intvec @code{1, 2, 3}.
  2450. @item @code{_}
  2451. @cindex _
  2452. value of expression last displayed
  2453. @item @code{~}
  2454. @cindex ~
  2455. breakpoint in procedures
  2456. @item @code{#}
  2457. @cindex #
  2458. list of parameters in procedures without explicit parameter list
  2459. @item @code{$}
  2460. @cindex $
  2461. terminates @sc{Singular}
  2462. @end table
  2463. @c ------------------------------------------------------------
  2464. @node Names, Objects, Special characters, The SINGULAR language
  2465. @subsection Names
  2466. @cindex Names
  2467. @cindex Identifiers, syntax of
  2468. @sc{Singular} is a strongly typed language. This means that all names
  2469. (= identifiers) have to be declared prior to their use. For the general
  2470. syntax of a declaration, see the description of declaration commands
  2471. (@pxref{General command syntax}).
  2472. @xref{Data types}, for a description of @sc{Singular}'s data types.
  2473. @xref{typeof}, for a short overview of possible types. To get information
  2474. on a name and the object named by it, the @code{type} command may be
  2475. used (@pxref{type}).
  2476. It is possible to redefine an already existing name if doing so does not
  2477. change its type. A redefinition first sets the variable to the default
  2478. value and then computes the expression. The difference between
  2479. redefining and overwriting a variable is shown in the following example:
  2480. @smallexample
  2481. @c computed example Names general.doc:2507
  2482. int i=3;
  2483. i=i+1; // overwriting
  2484. i;
  2485. @expansion{} 4
  2486. int i=i+1; // redefinition
  2487. @expansion{} // ** redefining i **
  2488. i;
  2489. @expansion{} 1
  2490. @c end example Names general.doc:2507
  2491. @end smallexample
  2492. User defined names should start with a letter and consist of letters and
  2493. digits only. As an exception to this rule, the characters @code{@@},
  2494. and @code{_} may
  2495. be used as part of a name, too. Capital and small letters are
  2496. distinguished. Indexed names are built as a name followed by an
  2497. int_expression in parentheses. A list of indexed names can be built as
  2498. a name followed by an intvec_expression in parentheses.
  2499. @smallexample
  2500. @c computed example Names_1 general.doc:2525
  2501. ring R;
  2502. int n=3;
  2503. ideal j(3);
  2504. ideal j(n); // is equivalent to the above
  2505. @expansion{} // ** redefining j(3) **
  2506. ideal j(2)=x;
  2507. j(2..3);
  2508. @expansion{} j(2)[1]=x j(3)[1]=0
  2509. @c end example Names_1 general.doc:2525
  2510. @end smallexample
  2511. Names may not coincide with reserved names (keywords). Type
  2512. @code{reservedName();} to get a list of the reserved names.
  2513. @xref{reservedName}. Names should not interfere with names of ring
  2514. variables or, more generally, with monomials. @xref{Identifier
  2515. resolution}.
  2516. @* The command @code{listvar} provides a list of the names in use
  2517. (@pxref{listvar}).
  2518. The most recently printed expression is available
  2519. under the special name @code{_}, e.g.,
  2520. @smallexample
  2521. @c computed example Names_2 general.doc:2546
  2522. ring r;
  2523. ideal i=x2+y3,y3+z4;
  2524. std(i);
  2525. @expansion{} _[1]=y3+x2
  2526. @expansion{} _[2]=z4-x2
  2527. ideal k=_;
  2528. k*k+x;
  2529. @expansion{} _[1]=y6+2x2y3+x4
  2530. @expansion{} _[2]=y3z4+x2z4-x2y3-x4
  2531. @expansion{} _[3]=z8-2x2z4+x4
  2532. @expansion{} _[4]=x
  2533. size(_[3]);
  2534. @expansion{} 3
  2535. @c end example Names_2 general.doc:2546
  2536. @end smallexample
  2537. A string_expression enclosed in @code{`}@dots{}@code{`} (back ticks)
  2538. evaluates to the value of the variable named by the string_expression.
  2539. This feature is referred to as name substitution.
  2540. @smallexample
  2541. @c computed example Names_3 general.doc:2561
  2542. int foo(1)=42;
  2543. string bar="foo";
  2544. `bar+"(1)"`;
  2545. @expansion{} 42
  2546. @c end example Names_3 general.doc:2561
  2547. @end smallexample
  2548. @c ------------------------------------------------------------
  2549. @node Objects, Type conversion and casting, Names, The SINGULAR language
  2550. @subsection Objects
  2551. @cindex Objects
  2552. Every object in @sc{Singular} has a type and a value. In most cases it
  2553. has also a name and in some cases an attribute list. The value of an
  2554. object may be examined simply by printing it with a print command:
  2555. object@code{;}. The type of an object may be determined by means of the
  2556. @code{typeof} function, the attributes by means of the @code{attrib}
  2557. function (@ref{typeof}, @ref{attrib}):
  2558. @smallexample
  2559. @c computed example Objects general.doc:2581
  2560. ring r=0,x,dp;
  2561. typeof(10);
  2562. @expansion{} int
  2563. typeof(10000000000000000);
  2564. @expansion{} number
  2565. typeof(r);
  2566. @expansion{} ring
  2567. attrib(x);
  2568. @expansion{} no attributes
  2569. attrib(std(ideal(x)));
  2570. @expansion{} attr:isSB, type int
  2571. @c end example Objects general.doc:2581
  2572. @end smallexample
  2573. Each object of type
  2574. @code{poly},
  2575. @code{ideal},
  2576. @code{vector},
  2577. @code{module},
  2578. @code{map},
  2579. @code{matrix},
  2580. @code{number}, or
  2581. @code{resolution}
  2582. belongs to a specific ring. Also @code{list}, if at least one of the
  2583. objects contained in the list belongs to a ring. These objects are local
  2584. to the ring. Their names can be used for other objects in other rings.
  2585. Objects from one ring can be mapped to another ring using maps or with the
  2586. commands @code{fetch} or @code{imap}. @xref{map}, @ref{fetch}, @ref{imap}.
  2587. All other types do not belong to a ring and can be accessed within every
  2588. ring and across rings. They can be declared even if there is no active
  2589. basering.
  2590. @c ------------------------------------------------------------
  2591. @node Type conversion and casting, Flow control, Objects, The SINGULAR language
  2592. @subsection Type conversion and casting
  2593. @subsubheading Type conversion
  2594. @cindex Type conversion
  2595. Assignments convert the type of the right-hand side to the type of the
  2596. left-hand side of the assignment, if possible. Operators and functions
  2597. which require certain types of operands can also implicitly convert the
  2598. type of an expression. It is, for example, possible to multiply a
  2599. polynomial by an integer because the integer is automatically converted to
  2600. a polynomial. Type conversions do not act transitively. Possible
  2601. conversions are:
  2602. @c ------------------------------------------------
  2603. @c Do not delete the leading `@ ' for indentation of the whole table. The
  2604. @c table is indented since regular @tables are indented by a small amount,
  2605. @c too.
  2606. @c ------------------------------------------------
  2607. @multitable @columnfractions .05 .18 .81
  2608. @item
  2609. @ 1. @tab @code{int} @tab @expansion{} @code{ideal}
  2610. @item
  2611. @ 2. @tab @code{poly} @tab @expansion{} @code{ideal}
  2612. @item
  2613. @ 3. @tab @code{intvec} @tab @expansion{} @code{intmat}
  2614. @item
  2615. @ 4. @tab @code{int} @tab @expansion{} @code{intvec}
  2616. @item
  2617. @ 5. @tab @code{int} @tab @expansion{} @code{intmat}
  2618. @item
  2619. @ 6. @tab @code{string} @tab @expansion{} @code{link}
  2620. @item
  2621. @ 7. @tab @code{resolution} @tab @expansion{} @code{list}
  2622. @item
  2623. @ 8. @tab @code{ideal} @tab @expansion{} @code{matrix}
  2624. @item
  2625. @ 9. @tab @code{int} @tab @expansion{} @code{matrix}
  2626. @item
  2627. @ 10. @tab @code{intmat} @tab @expansion{} @code{matrix}
  2628. @item
  2629. @ 11. @tab @code{intvec} @tab @expansion{} @code{matrix}
  2630. @item
  2631. @ 12. @tab @code{module} @tab @expansion{} @code{matrix}
  2632. @item
  2633. @ 13. @tab @code{number} @tab @expansion{} @code{matrix}
  2634. @item
  2635. @ 14. @tab @code{poly} @tab @expansion{} @code{matrix}
  2636. @item
  2637. @ 15. @tab @code{vector} @tab @expansion{} @code{matrix}
  2638. @item
  2639. @ 16. @tab @code{ideal} @tab @expansion{} @code{module}
  2640. @item
  2641. @ 17. @tab @code{matrix} @tab @expansion{} @code{module}
  2642. @item
  2643. @ 18. @tab @code{vector} @tab @expansion{} @code{module}
  2644. @item
  2645. @ 19. @tab @code{int} @tab @expansion{} @code{number}
  2646. @item
  2647. @ 20. @tab @code{int} @tab @expansion{} @code{poly}
  2648. @item
  2649. @ 21. @tab @code{number} @tab @expansion{} @code{poly}
  2650. @item
  2651. @ 22. @tab @code{string} @tab @expansion{} @code{proc}
  2652. @item
  2653. @ 23. @tab @code{list} @tab @expansion{} @code{resolution}
  2654. @item
  2655. @ 24. @tab @code{int} @tab @expansion{} @code{vector}
  2656. (i @expansion{} i*@code{gen(1)})
  2657. @item
  2658. @ 25. @tab @code{poly} @tab @expansion{} @code{vector}
  2659. (p @expansion{} p*@code{gen(1)})
  2660. @end multitable
  2661. @subsubheading Type casting
  2662. @cindex Type casting
  2663. An expression can be casted to another type by using a type cast
  2664. expression:
  2665. @* type @code{(} expression @code{)}.
  2666. Possible type casts are:
  2667. @c ------------------------------------------------
  2668. @c Do not delete the leading `@ ' for indentation of the whole table. The
  2669. @c table is indented since regular @tables are indented by a small amount,
  2670. @c too.
  2671. @c ------------------------------------------------
  2672. @multitable @columnfractions .05 .15 .83
  2673. @item
  2674. @ @tab to @tab from
  2675. @item
  2676. @ @tab @code{ideal} @tab expression lists of @code{int}, @code{number}, @code{poly}
  2677. @item
  2678. @ @tab @code{ideal} @tab @code{int}, @code{matrix}, @code{module}, @code{number}, @code{poly}, @code{vector}
  2679. @item
  2680. @ @tab @code{int} @tab @code{number}, @code{poly}
  2681. @item
  2682. @ @tab @code{intvec} @tab expression lists of @code{int}, @code{intmat}
  2683. @item
  2684. @ @tab @code{intmat} @tab @code{intvec} (@pxref{intmat type cast})
  2685. @item
  2686. @ @tab @code{list} @tab expression lists of any type
  2687. @item
  2688. @ @tab @code{matrix} @tab @code{module}, @code{ideal},
  2689. @code{vector}, @code{matrix}.
  2690. @* There are two forms to convert something to a matrix: if @code{matrix(}
  2691. expression @code{)} is used then the size of the matrix is determined
  2692. by the size of expression.
  2693. @* But @code{matrix(} expression @code{,} m @code{,} n @code{)} may also be
  2694. used - the result is a
  2695. @tex
  2696. $ m \times n $
  2697. @end tex
  2698. @ifinfo
  2699. m x n
  2700. @end ifinfo
  2701. matrix (@pxref{matrix type cast})
  2702. @item
  2703. @ @tab @code{module} @tab expression lists of @code{int}, @code{number},
  2704. @code{poly}, @code{vector}
  2705. @item
  2706. @ @tab @code{module} @tab @code{ideal}, @code{matrix}, @code{vector}
  2707. @item
  2708. @ @tab @code{number} @tab @code{poly}
  2709. @item
  2710. @ @tab @code{poly} @tab @code{int}, @code{number}
  2711. @item
  2712. @ @tab @code{string} @tab any type (@pxref{string type cast})
  2713. @end multitable
  2714. @strong{Example:}
  2715. @smallexample
  2716. @c computed example Type_casting general.doc:2743
  2717. ring r=0,x,(c,dp);
  2718. number(3x);
  2719. @expansion{} 0
  2720. number(poly(3));
  2721. @expansion{} 3
  2722. ideal i=1,2,3,4,5,6;
  2723. print(matrix(i));
  2724. @expansion{} 1,2,3,4,5,6
  2725. print(matrix(i,3,2));
  2726. @expansion{} 1,2,
  2727. @expansion{} 3,4,
  2728. @expansion{} 5,6
  2729. vector v=[1,2];
  2730. print(matrix(v));
  2731. @expansion{} 1,
  2732. @expansion{} 2
  2733. module(matrix(i,3,2));
  2734. @expansion{} _[1]=[1,3,5]
  2735. @expansion{} _[2]=[2,4,6]
  2736. @c end example Type_casting general.doc:2743
  2737. @end smallexample
  2738. @c ------------------------------------------------------------
  2739. @node Flow control, ,Type conversion and casting, The SINGULAR language
  2740. @subsection Flow control
  2741. @cindex Flow control
  2742. @cindex block
  2743. A block is a sequence of commands surrounded by @{ and @}.
  2744. @smallexample
  2745. @{
  2746. command;
  2747. @dots{}
  2748. @}
  2749. @end smallexample
  2750. Blocks are used whenever @sc{Singular} is used as a structured programming
  2751. language. The @code{if} and @code{else} structures allow conditional
  2752. execution of blocks (see @ref{if}, @ref{else}). @code{for} and @code{while}
  2753. loops are available for repeated execution of blocks (see @ref{for},
  2754. @ref{while}).
  2755. In procedure definitions the main part and the example section are blocks
  2756. as well(see @ref{proc}).
  2757. @menu
  2758. * break::
  2759. * quit::
  2760. * keepring::
  2761. * export::
  2762. * if::
  2763. * else::
  2764. * for::
  2765. * while::
  2766. * proc::
  2767. * return::
  2768. * continue::
  2769. @end menu
  2770. @c ----------------------------------------------------------------------
  2771. @c ----------------------------------------------------------------------
  2772. @node Input and output, Procedures, The SINGULAR language, General concepts
  2773. @section Input and output
  2774. @cindex input
  2775. @cindex output
  2776. @sc{Singular}'s input and output (short, I/O) is realized using links.
  2777. Links are the communication channels of @sc{Singular}, i.e., something
  2778. @sc{Singular} can write to and read from. In this section, a short
  2779. overview of the usage of links and of the different link types is given.
  2780. For loading of libraries, see @ref{LIB}. For executing program scripts,
  2781. see @ref{filecmd}.
  2782. @subheading Monitoring
  2783. A special form of I/O is monitoring. When monitoring is enabled,
  2784. @sc{Singular} makes a typescript of everything printed on your terminal
  2785. to a file. This is
  2786. useful to create a protocol of a @sc{Singular} session. The
  2787. @code{monitor} command enables and disables this feature
  2788. (@pxref{monitor}).
  2789. @subheading How to use links
  2790. Recall that links are the communication channels of @sc{Singular}, i.e.,
  2791. something @sc{Singular} can write to and read from using the functions
  2792. @code{write} and @code{read}. There are furthermore
  2793. the functions @code{dump} and @code{getdump} which store resp.@:
  2794. retrieve the content of an entire @sc{Singular} session to, resp.@: from,
  2795. a link. The @code{dump} and @code{getdump} commands are not available
  2796. for DBM links.
  2797. For more information, see @ref{write}, @ref{read}, @ref{dump},
  2798. @ref{getdump}.
  2799. @strong{Example:}
  2800. @smallexample
  2801. @c computed example How_to_use_links general.doc:2830
  2802. ring r; poly p = x+y;
  2803. dump("MPfile:w test.mp"); // dump the session to the file test.mp
  2804. kill r; // kill the basering
  2805. listvar();
  2806. @expansion{} // LIB [0] string standard.lib
  2807. getdump("MPfile:r test.mp");// read the dump from the file
  2808. listvar();
  2809. @expansion{} // r [0] *ring
  2810. @expansion{} // p [0] poly
  2811. @expansion{} // LIB [0] string standard.lib
  2812. @c end example How_to_use_links general.doc:2830
  2813. @end smallexample
  2814. Specifying a link can be as easy as specifying a filename as a string.
  2815. Except for MPtcp links, links even do not need to be explicitly opened
  2816. or closed before, resp.@: after, they are used. To explicitly open or
  2817. close a link, the @code{open}, resp.@: @code{close}, commands may be
  2818. used (see @ref{open}, @ref{close}).
  2819. Links have various properties which can be queried using the
  2820. @code{status} function (@pxref{status}).
  2821. @strong{Example:}
  2822. @smallexample
  2823. @c computed example How_to_use_links_1 general.doc:2851
  2824. link l = "MPtcp:fork";
  2825. l;
  2826. @expansion{} // type : MPtcp
  2827. @expansion{} // mode : fork
  2828. @expansion{} // name :
  2829. @expansion{} // open : no
  2830. @expansion{} // read : not ready
  2831. @expansion{} // write: not ready
  2832. open(l);
  2833. status(l, "open");
  2834. @expansion{} yes
  2835. close(l);
  2836. status(l, "open");
  2837. @expansion{} no
  2838. @c end example How_to_use_links_1 general.doc:2851
  2839. @end smallexample
  2840. @subheading ASCII links
  2841. Data that can be converted to a string that can be written into files for
  2842. storage or communication with other programs. The data are written in
  2843. plain ASCII format. Reading from an ASCII link returns a string ---
  2844. conversion into other data is up to the user. This can be done, for
  2845. example, using the command @code{execute} (@pxref{execute}).
  2846. ASCII links should primarily be used for storing small amounts of data,
  2847. especially if it might become necessary to manually inspect or
  2848. manipulate the data.
  2849. @xref{ASCII links}, for more information.
  2850. @strong{Example:}
  2851. @smallexample
  2852. @c computed example ASCII_links general.doc:2876
  2853. // (over)write file test.ascii, link is specified as string
  2854. write(":w test.ascii", "int i =", 3, ";");
  2855. // reading simply returns the string
  2856. read("test.ascii");
  2857. @expansion{} int i =
  2858. @expansion{} 3
  2859. @expansion{} ;
  2860. @expansion{}
  2861. // but now test.ascii is "executed"
  2862. execute(read("test.ascii"));
  2863. i;
  2864. @expansion{} 3
  2865. @c end example ASCII_links general.doc:2876
  2866. @end smallexample
  2867. @subheading MPfile links
  2868. Data is stored in the binary MP format. Read and write access is very
  2869. fast compared to ASCII links. All data (including such data that cannot
  2870. be converted to a string) can be written to an MPfile link. Reading
  2871. from an MPfile link returns the written expressions (i.e., not a string,
  2872. in general).
  2873. MPfile links should primarily be used for storing large amounts of data
  2874. (like dumps of the content of an entire @sc{Singular} session), and if
  2875. the data to be stored cannot be easily converted from or to a string
  2876. (like rings, or maps).
  2877. MPfile links are implemented on Unix-like operating systems only.
  2878. @xref{MPfile links}, for more information.
  2879. @strong{Example:}
  2880. @smallexample
  2881. @c computed example MPfile_links general.doc:2905
  2882. ring r;
  2883. // (over)write MPfile test.mp, link is specified as string
  2884. write("MPfile:w test.mp", x+y);
  2885. kill r;
  2886. def p = read("MPfile:r test.mp");
  2887. typeof(p); p;
  2888. @expansion{} poly
  2889. @expansion{} x+y
  2890. @c end example MPfile_links general.doc:2905
  2891. @end smallexample
  2892. @subheading MPtcp links
  2893. Data is communicated with other processes (e.g., @sc{Singular}
  2894. processes) which may run on the same computer or on different ones. Data
  2895. exchange is accomplished using TCP/IP links in the binary MP format.
  2896. Reading from an MPtcp link returns the written expressions (i.e., not a
  2897. string, in general).
  2898. MPtcp links should primarily be used for communications with other
  2899. programs or for parallel computations (see, for example,
  2900. @ref{Parallelization with MPtcp links}).
  2901. MPtcp links are implemented on Unix-like operating systems only.
  2902. @xref{MPtcp links}, for more information.
  2903. @strong{Example:}
  2904. @smallexample
  2905. @c computed example MPtcp_links general.doc:2932
  2906. ring r;
  2907. link l = "MPtcp:launch"; // declare a link explicitly
  2908. open(l); // needs an open, launches another SINGULAR as a server
  2909. write(l, x+y);
  2910. kill r;
  2911. def p = read(l);
  2912. typeof(p); p;
  2913. @expansion{} poly
  2914. @expansion{} x+y
  2915. close(l); // shuts down SINGULAR server
  2916. @c end example MPtcp_links general.doc:2932
  2917. @end smallexample
  2918. @subheading DBM links
  2919. Data is stored in and accessed from a data base. Writing is
  2920. accomplished by a key and a value and associates the value with the key
  2921. in the specified data base. Reading is accomplished w.r.t.@: a key,
  2922. the value associated to it is returned. Both the key and the value have to
  2923. be specified as strings. Hence, DBM links may be used only for data
  2924. which may be converted to or from strings.
  2925. DBM links should primarily be used when data needs to be accessed not in a
  2926. sequential way (like with files) but in an associative way (like with
  2927. data bases).
  2928. @xref{DBM links}, for more information.
  2929. @strong{Example:}
  2930. @smallexample
  2931. @c computed example DBM_links general.doc:2960
  2932. ring r;
  2933. // associate "x+y" with "mykey"
  2934. write("DBM:w test.dbm", "mykey", string(x+y));
  2935. // get from data base what is stored under "mykey"
  2936. execute(read("DBM: test.dbm", "mykey"));
  2937. @expansion{} x+y
  2938. @c end example DBM_links general.doc:2960
  2939. @end smallexample
  2940. @c ---------------------------------------------------------------------------
  2941. @node Procedures, Libraries, Input and output, General concepts
  2942. @section Procedures
  2943. @cindex Procedures
  2944. Procedures contain sequences of commands of the @sc{Singular} language.
  2945. They are used to extend
  2946. the set of commands with user defined commands. Procedures are defined
  2947. by either typing them on the command line or by loading them from a
  2948. so-called library file with the LIB command, see @ref{LIB}. Procedures are
  2949. invoked like normal built-in commands, i.e., by typing their name
  2950. followed by the list of arguments in parentheses. The invocation then
  2951. executes the sequence of commands stored in the specified procedure. All
  2952. defined procedures can be displayed by the command @code{listvar(proc);}.
  2953. @menu
  2954. * Procedure definition::
  2955. * Names in procedures::
  2956. * Parameter list::
  2957. * Procedure commands::
  2958. @end menu
  2959. @c -------------------------------------------------
  2960. @node Procedure definition, Names in procedures, Procedures, Procedures
  2961. @subsection Procedure definition
  2962. @cindex Procedure definition
  2963. @cindex procedures, static
  2964. @cindex static procedures
  2965. @c ------------------------------------------------------------
  2966. @c This piece of text exists also in the file types.doc,
  2967. @c chapter "proc declaration".
  2968. @c If you change something here, change it there, too!
  2969. @c ------------------------------------------------------------
  2970. @table @strong
  2971. @item Syntax:
  2972. [@code{static}] @code{proc} proc_name [parameter_list]
  2973. @*["help_text"]
  2974. @*@code{@{}
  2975. @*
  2976. @tex
  2977. \quad
  2978. @end tex
  2979. procedure_body
  2980. @*@code{@}}
  2981. @*[@code{example}
  2982. @*@code{@{}
  2983. @*
  2984. @tex
  2985. \quad
  2986. @end tex
  2987. sequence_of_commands;
  2988. @*@code{@}}]
  2989. @item Purpose:
  2990. defines a new function, the @code{proc} proc_name, with the additional
  2991. information help_text, which is copied to the screen by
  2992. @code{help proc_name;} and the @code{example} section
  2993. which is executed by @code{example proc_name;}.
  2994. @* The help_text, the parameter_list, and the example section are optional.
  2995. The default for a parameter_list is @code{(list #)}, see @ref{Parameter list}.
  2996. The help and example sections are ignored if the procedure is defined
  2997. @ifset namespaces
  2998. interactively, i.e., if it was not loaded from a file by a @ref{load} command.
  2999. @end ifset
  3000. @ifclear namespaces
  3001. interactively, i.e., if it was not loaded from a file by a LIB command
  3002. (@ref{LIB}).
  3003. @end ifclear
  3004. @* Specifying @code{static} in front of the proc-definition (in a library file)
  3005. makes this procedure local to the library, i.e., accessible only for the other
  3006. procedures in the same library, but not for the users. So there is no
  3007. reason anymore to define a procedure within another one (it just makes
  3008. debugging harder).
  3009. @end table
  3010. @subsubheading Example of an interactive procedure definition
  3011. @smallexample
  3012. @c computed example Example_of_an_interactive_procedure_definition general.doc:3045
  3013. proc milnor_number (poly p)
  3014. @{
  3015. ideal i= std(jacob(p));
  3016. int m_nr=vdim(i);
  3017. if (m_nr<0)
  3018. @{
  3019. "// not an isolated singularity";
  3020. @}
  3021. return(m_nr); // the value of m_nr is returned
  3022. @}
  3023. ring r1=0,(x,y,z),ds;
  3024. poly p=x^2+y^2+z^5;
  3025. milnor_number(p);
  3026. @expansion{} 4
  3027. @c end example Example_of_an_interactive_procedure_definition general.doc:3045
  3028. @end smallexample
  3029. @subsubheading Example of a procedure definition in a library
  3030. First, the library definition:
  3031. @smallexample
  3032. @c begin included file sample.lib from general.doc:3065
  3033. // Example of a user accessible procedure
  3034. proc tab (int n)
  3035. "USAGE: tab(n); (n integer)
  3036. RETURNS: string of n space tabs
  3037. EXAMPLE: example tab; shows an example"
  3038. @{ return(internal_tab(n)); @}
  3039. example
  3040. @{
  3041. "EXAMPLE:"; echo=2;
  3042. for(int n=0; n<=4; n=n+1)
  3043. @{ tab(4-n)+"*"+tab(n)+"+"+tab(n)+"*"; @}
  3044. @}
  3045. // Example of a static procedure
  3046. static proc internal_tab (int n)
  3047. @{ return(" "[1,n]); @}
  3048. @c end included file from general.doc:3065
  3049. @end smallexample
  3050. Now, we load the library and execute the procedures defined there:
  3051. @smallexample
  3052. @c computed example Example_of_a_procedure_definition_in_a_library general.doc:3070
  3053. LIB "sample.lib"; // load the library sample.lib
  3054. example tab; // show an example
  3055. @expansion{} // proc tab from lib sample.lib
  3056. @expansion{} EXAMPLE:
  3057. @expansion{} for(int n=0; n<=4; n=n+1)
  3058. @expansion{} @{ tab(4-n)+"*"+tab(n)+"+"+tab(n)+"*"; @}
  3059. @expansion{} *+*
  3060. @expansion{} * + *
  3061. @expansion{} * + *
  3062. @expansion{} * + *
  3063. @expansion{} * + *
  3064. @expansion{}
  3065. "*"+tab(3)+"*"; // use the procedure tab
  3066. @expansion{} * *
  3067. // the static procedure internal_tab is not accessible
  3068. "*"+internal_tab(3)+"*";
  3069. @expansion{} ? 'sample.lib::internal_tab()' is a local procedure and cannot be acce\
  3070. ssed by an user.
  3071. @expansion{} ? error occurred in line 5: ` "*"+internal_tab(3)+"*";`
  3072. // show the help section for tab
  3073. help tab;
  3074. @expansion{} // ** Could not get IdxFile.
  3075. @expansion{} // ** Either set environment variable SINGULAR_IDX_FILE to IdxFile,
  3076. @expansion{} // ** or make sure that IdxFile is at /home/hannes/singular/2-0/doc/singu\
  3077. lar.idx
  3078. @expansion{} // proc tab from lib sample.lib
  3079. @expansion{} proc tab (int n)
  3080. @expansion{} USAGE: tab(n); (n integer)
  3081. @expansion{} RETURNS: string of n space tabs
  3082. @expansion{} EXAMPLE: example tab; shows an example
  3083. @c end example Example_of_a_procedure_definition_in_a_library general.doc:3070
  3084. @end smallexample
  3085. @subsubheading Guidelines for the help text of a procedure
  3086. There are no enforced rules on the format of the help section of a
  3087. procedure.
  3088. Nevertheless, we recommend that the help text of a procedure should
  3089. contain information about the usage,
  3090. purpose, return values and generated objects. Particular assumptions or
  3091. limitations should be listed. It should also be mentioned if global
  3092. objects are generated or manipulated.
  3093. The help text of procedures contained in libraries of the
  3094. @sc{Singular} distribution
  3095. should furthermore comply with certain rules as explained in
  3096. @ref{The help string of procedures}.
  3097. @c ---------------------------------------
  3098. @node Names in procedures, Parameter list, Procedure definition, Procedures
  3099. @subsection Names in procedures
  3100. @cindex Names in procedures
  3101. @cindex local names
  3102. All variables are local to the procedure they are defined in.
  3103. Locally defined variables cannot interfere with names in other
  3104. procedures and are automatically deleted after leaving
  3105. the procedure.
  3106. Internally, local variables are stored using the nesting level. A variable
  3107. is said to have nesting level 1, if it is local to a procedure that was
  3108. called interactively, nesting level 2, if it is local to a procedure that
  3109. was called by a procedure of nesting level 1 etc. @code{listvar()} also
  3110. displays the nesting level, nesting level 0 is used for global objects
  3111. (see @ref{listvar}). A ring may be 'moved up' by one nesting level
  3112. with @code{keepring} (see @ref{keepring}). All variables living in that
  3113. ring are moved together with that ring.
  3114. To keep local variables after leaving the procedure, they have to be
  3115. exported (i.e. made known) to some higher level by the @code{export}
  3116. command (@pxref{export}).
  3117. @strong{Example:}
  3118. @smallexample
  3119. @c computed example Names_in_procedures general.doc:3122
  3120. proc xxx
  3121. @{
  3122. int k=4; //defines a local variable k
  3123. int result=k+2;
  3124. export(result); //defines the global variable "result".
  3125. @}
  3126. xxx();
  3127. listvar(all);
  3128. @expansion{} // result [0] int 6
  3129. @expansion{} // LIB [0] string standard.lib
  3130. @c end example Names_in_procedures general.doc:3122
  3131. @end smallexample
  3132. Note that the variable @code{result} became a global variable after the
  3133. execution of @code{xxx}.
  3134. @c ---------------------------------------
  3135. @node Parameter list, Procedure commands, Names in procedures, Procedures
  3136. @subsection Parameter list
  3137. @cindex Parameter list
  3138. @table @code
  3139. @item @strong{Syntax:}
  3140. @code{( )}
  3141. @*@code{(} parameter_definition @code{)}
  3142. @item @strong{Purpose:}
  3143. defines the number, type and names of the
  3144. arguments to a @code{proc}.
  3145. @*The parameter_list is optional.
  3146. The default for a parameter_list is @code{(list #)}
  3147. which means the arguments are referenced by @code{#[1], #[2]}, etc.
  3148. @item @strong{Example:}
  3149. @smallexample
  3150. proc x0
  3151. @{
  3152. // can be called with
  3153. ... // any number of arguments of any type: #[1], #[2],...
  3154. // number of arguments: size(#)
  3155. @}
  3156. proc x1 ()
  3157. @{
  3158. ... // can only be called without arguments
  3159. @}
  3160. proc x2 (ideal i, int j)
  3161. @{
  3162. ... // can only be called with 2 arguments,
  3163. // which can be converted to ideal resp. int
  3164. @}
  3165. proc x3 (i,j)
  3166. @{
  3167. ... // can only be called with 2 arguments
  3168. // of any type
  3169. // (i,j) is the same as (def i,def j)
  3170. @}
  3171. proc x5 (i,list #)
  3172. @{
  3173. ... // can only be called with at least 1 argument
  3174. // number of arguments: size(#)+1
  3175. @}
  3176. @end smallexample
  3177. @item @strong{Note:}
  3178. @* The parameter_list may stretch across multiple lines.
  3179. @* A parameter may have any type (including the types @code{proc}
  3180. and @code{ring}). If a parameter is of type ring, then it
  3181. can only be specified by name, but not with a type, e.g.
  3182. @smallexample
  3183. proc x6 (r)
  3184. @{
  3185. ... // this is correct even if the parameter is a ring
  3186. @}
  3187. proc x7 (ring r)
  3188. @{
  3189. ... // this is NOT CORRECT
  3190. @}
  3191. @end smallexample
  3192. @end table
  3193. @c --------------------------------------- ----------
  3194. @node Procedure commands, , Parameter list, Procedures
  3195. @subsection Procedure commands
  3196. @cindex Procedure commands
  3197. Some commands only make sense inside a procedure, since they make
  3198. objects known to the nesting level from which the procedure was called
  3199. or to all nesting levels.
  3200. @c inserted refs from general.doc:3211
  3201. @ifinfo
  3202. @menu
  3203. See
  3204. * export::
  3205. * keepring::
  3206. * return::
  3207. @end menu
  3208. @end ifinfo
  3209. @iftex
  3210. See
  3211. @ref{export};
  3212. @ref{keepring};
  3213. @ref{return}.
  3214. @end iftex
  3215. @c end inserted refs from general.doc:3211
  3216. @c ----------------------------------------------------------------------
  3217. @node Libraries, Guidelines for writing a library, Procedures, General concepts
  3218. @section Libraries
  3219. @cindex Libraries
  3220. A library is a collection of @sc{Singular}
  3221. procedures in a file.
  3222. @*@sc{Singular} reads a library with the command
  3223. @code{LIB}. General information about the library is displayed by the command
  3224. @code{help libname_lib}. After loading the library, its procedures can be used
  3225. like the built-in @sc{Singular} functions.
  3226. To have the full functionality of a built-in function libraries have to
  3227. comply with the few syntax rules described below.
  3228. Furthermore, libraries which are to be included in the @sc{Singular}
  3229. distribution, have to comply with certain rules as explained in
  3230. @ref{Guidelines for writing a library}.
  3231. @menu
  3232. * Loading of a library::
  3233. * Format of a library::
  3234. @end menu
  3235. @c ---------------------------------------
  3236. @node Loading of a library, Format of a library,, Libraries
  3237. @subsection Loading of a library
  3238. @cindex Loading of a library
  3239. @cindex path
  3240. @cindex SearchPath
  3241. @cindex RootDir
  3242. @cindex BinDir
  3243. @cindex DefaultDir
  3244. @cindex SINGULARPATH
  3245. Libraries can be loaded with the @code{LIB} command:
  3246. @c ------------------------------------------------------------
  3247. @c This piece of text exists also in the file reference.doc,
  3248. @c chapter "LIB".
  3249. @c chapter "load".
  3250. @c If you change something here, change it there, too!
  3251. @c ------------------------------------------------------------
  3252. @table @code
  3253. @item @strong{Syntax:}
  3254. @code{LIB} string_expression @code{;}
  3255. @item @strong{Type:}
  3256. none
  3257. @item @strong{Purpose:}
  3258. reads a library of procedures from a file. If the given filename does
  3259. not start with @kbd{.} or @kbd{/} and can not be located in the current
  3260. directory, each directory contained in the library
  3261. @code{SearchPath} is searched for file of this name.
  3262. @item @strong{Note on SearchPath:}
  3263. The the library @code{SearchPath} is constructed at @sc{Singular}
  3264. start-up time as follows:
  3265. @enumerate
  3266. @item
  3267. the directories contained in the environment variable
  3268. @code{SINGULARPATH} are appended
  3269. @item
  3270. the directories @code{$BinDir/LIB}, @code{$RootDir/LIB},
  3271. @code{$RootDir/../LIB}, @code{$DefaultDir/LIB}, @code{$DefaultDir/../LIB}
  3272. are appended, where
  3273. @itemize @bullet
  3274. @item @code{$BinDir}
  3275. is the value of the environment variable
  3276. @code{SINGULAR_BIN_DIR}, if set, or, if not set, the directory in which the
  3277. @sc{Singular} program
  3278. resides
  3279. @item @code{$RootDir}
  3280. is the value of the environment variable
  3281. @code{SINGULAR_ROOT_DIR}, if set, or, if not set, @code{$BinDir/../}.
  3282. @item @code{$DefaultDir}
  3283. is the value of the environment variable
  3284. @code{SINGULAR_DEFAULT_DIR}, if set, or @code{/usr/local/Singular/} on a
  3285. Unix platform, @code{\Singular\} on a Windows 95/98/NT platform, and
  3286. @code{::Singular:} on a Macintosh.
  3287. @end itemize
  3288. @item
  3289. all directories which do not exist are removed from the @code{SearchPath}.
  3290. @end enumerate
  3291. For setting environment variables see @ref{system}, or consult the manual of
  3292. your shell.
  3293. The library @code{SearchPath} can be examined by starting up
  3294. @sc{Singular} with the option @code{-v}, or by issuing the command
  3295. @code{system("--version");}.
  3296. @item @strong{Note on standard.lib:}
  3297. Unless @sc{Singular} is started with the @code{--no-stdlib} option, the
  3298. library @code{standard.lib} is automatically loaded at start-up time.
  3299. @end table
  3300. Only the names of the procedures in the library are loaded, the body of
  3301. the procedures is read during the first call of this procedure. This minimizes
  3302. memory consumption by unused procedures. When @sc{Singular} is started
  3303. with the @code{-q} or @code{--quiet} option, no message about the
  3304. loading of a library is displayed. More precisely, option @code{-q} (and
  3305. likewise @code{--quiet}) unsets option @code{loadLib} to inhibit
  3306. monitoring of library loading (@pxref{option}).
  3307. All loaded libraries are displayed by the @code{LIB;}
  3308. command:
  3309. @smallexample
  3310. @c computed example Loading_of_a_library general.doc:3327
  3311. option(loadLib); // show loading of libraries;
  3312. // standard.lib is loaded
  3313. LIB;
  3314. @expansion{} standard.lib
  3315. // the names of the procedures of inout.lib
  3316. LIB "inout.lib"; // are now known to Singular
  3317. @expansion{} // ** loaded inout.lib (1.21.2.5,2002/06/12)
  3318. LIB;
  3319. @expansion{} standard.lib,inout.lib
  3320. @c end example Loading_of_a_library general.doc:3327
  3321. @end smallexample
  3322. @c inserted refs from general.doc:3337
  3323. @ifinfo
  3324. @menu
  3325. See
  3326. * Command line options::
  3327. * LIB::
  3328. * Procedures and libraries::
  3329. * SINGULAR libraries::
  3330. * proc::
  3331. * standard_lib::
  3332. * string::
  3333. * system::
  3334. @end menu
  3335. @end ifinfo
  3336. @iftex
  3337. See
  3338. @ref{Command line options};
  3339. @ref{LIB};
  3340. @ref{Procedures and libraries};
  3341. @ref{SINGULAR libraries};
  3342. @ref{proc};
  3343. @ref{standard_lib};
  3344. @ref{string};
  3345. @ref{system}.
  3346. @end iftex
  3347. @c end inserted refs from general.doc:3337
  3348. @c ---------------------------------------
  3349. @node Format of a library,, Loading of a library, Libraries
  3350. @subsection Format of a library
  3351. @cindex Format of a library
  3352. A library file can contain comments, a category-, info- and version-string
  3353. definition, @code{LIB} commands, @code{proc} commands
  3354. and @code{proc} commands with @code{example} and @code{help} sections,
  3355. i.e., the following keywords are allowed:
  3356. @code{category},
  3357. @code{info},
  3358. @code{version},
  3359. @code{LIB},
  3360. @code{/* ... */},
  3361. @code{//},
  3362. @code{[static] proc}.
  3363. Anything else is not recognized by the parser of @sc{Singular} and leads
  3364. to an error message while loading the library.
  3365. If an error occurs, loading is aborted and an error message is displayed,
  3366. specifying the type of error and the line where it was detected.
  3367. The category-, info- and version-string are defined as follows:
  3368. @cindex info in a library
  3369. @table @code
  3370. @item @strong{Syntax:}
  3371. @code{info} = string_constant @code{;}
  3372. @item @strong{Purpose:}
  3373. defines the general help for the library. This text is displayed on
  3374. @code{help libname_lib;}.
  3375. @item @strong{Example:}
  3376. @smallexample
  3377. info="
  3378. This could be the general help of a library.
  3379. Quotes must be escaped with a \ such as \"
  3380. ";
  3381. @end smallexample
  3382. @item @strong{Note:}
  3383. In the info-string the characters \ and " must be preceded by a \ (escaped).
  3384. It is recommended that the info string is placed on the top of a
  3385. library file and contains general information about the library as well
  3386. as a listing of all procedures available to the users (with a one line
  3387. description of each procedure).
  3388. Although there is no enforced format of the info string of a library, we
  3389. recommend that you follow certain rules as explained in
  3390. @ref{The help string of a library}.
  3391. @end table
  3392. @cindex version in a library
  3393. @table @code
  3394. @item @strong{Syntax:}
  3395. @code{version} = string_constant @code{;}
  3396. @item @strong{Purpose:}
  3397. defines the version number for the library. It is displayed when the
  3398. library is loaded.
  3399. @item @strong{Example:}
  3400. @smallexample
  3401. version="$ I@i{}@comment
  3402. @comment !! Do not erase the @comment at the end of the previous line !!
  3403. @comment !! It prevents cvs to substitute the id string !!
  3404. d: sample.lib,v 1.2 1998/05/07 singular Exp $";
  3405. version="some version string";
  3406. @end smallexample
  3407. @item @strong{Note:}
  3408. It is common practice to simply define the version string to be
  3409. @code{"$ I}@comment
  3410. @comment !! Do not erase the @comment at the end of the previous line !!
  3411. @comment !! It prevents cvs to substitute the id string !!
  3412. @code{d:$"} and let a version control system expand it.
  3413. @end table
  3414. @cindex category in a library
  3415. @table @code
  3416. @item @strong{Syntax:}
  3417. @code{category} = string_constant @code{;}
  3418. @item @strong{Purpose:}
  3419. defines the category for the library.
  3420. @item @strong{Example:}
  3421. @smallexample
  3422. category="Utilities";
  3423. @end smallexample
  3424. @item @strong{Note:}
  3425. reserved for sorting the libraries into categories.
  3426. @end table
  3427. @c ---------------------------------------
  3428. @node Guidelines for writing a library, Debugging tools, Libraries, General concepts
  3429. @section Guidelines for writing a library
  3430. @cindex Guidelines for writing a library
  3431. @cindex library, Guidelines for writing
  3432. Although there are very few enforced rules on how libraries are written
  3433. (see @ref{Libraries}), it is recommended that the libraries comply with
  3434. the guidelines explained in this section, so that debugging and
  3435. understanding are made easier.
  3436. @strong{Note:} For libraries which are to be included in the @sc{Singular}
  3437. distribution, the following guidelines are mandatory.
  3438. @menu
  3439. * Procedures in a library::
  3440. * Documentation of a library::
  3441. * Typesetting of help strings::
  3442. * The help string of a library::
  3443. * The help string of procedures::
  3444. * template_lib::
  3445. @end menu
  3446. @c ---------------------------------------
  3447. @node Procedures in a library, Documentation of a library,,Guidelines for writing a library
  3448. @subsection Procedures in a library
  3449. @cindex Procedures in a library
  3450. @cindex library, procedures
  3451. In this section we list miscellaneous recommendations on how procedures
  3452. contained in a library should be implemented.
  3453. @enumerate
  3454. @item
  3455. The info- and version-string should appear at the beginning of the
  3456. library, before procedure definitions.
  3457. @item
  3458. The info-string should have the format as explained in @ref{The help
  3459. string of a library}.
  3460. @item
  3461. Each procedure which should not be accessible by users should be
  3462. declared @code{static}.
  3463. @item
  3464. Each procedure which is not declared @code{static} should have a
  3465. help and example section as explained in @ref{Procedure definition}.
  3466. @*Such procedures should furthermore carefully check any assumptions
  3467. made about their input (like the type of list elements), and, if
  3468. necessary, omit an error using the function @ref{ERROR}.
  3469. @item
  3470. No procedures should be defined within the body of another procedure.
  3471. @item
  3472. If the value of
  3473. the reserved variable @code{printlevel} (@pxref{printlevel}) is greater
  3474. than 0 then interactive user-input, i.e., the usage of functions like
  3475. @code{pause("..")} or @code{read("");} (@pxref{read}), may be requested.
  3476. @item
  3477. If the value of
  3478. the reserved variable @code{printlevel} (@pxref{printlevel}) is 0
  3479. then interactive user-input, i.e., the usage of functions like
  3480. @code{pause("..")} or @code{read("");} (@pxref{read}), may @strong{not} be
  3481. requested. Instead, an error (using the function
  3482. @ref{ERROR}) should be reported together with the recommendation on
  3483. increasing the value of the reserved variable @code{printlevel}.
  3484. @item
  3485. It is often useful for a procedure to print out comments, either to
  3486. explain results or to display intermediate computations. However,
  3487. if this procedure is called by another procedure, such comments are
  3488. confusing and disturbing in most cases.
  3489. @sc{Singular} offers an elegant solution, which requires the usage of
  3490. the @sc{Singular} function @ref{dbprint} and the reserved variables
  3491. @ref{printlevel}, and @ref{voice} (@code{voice} counts the nesting of
  3492. procedures; It has the value 1 on the top level, 2 inside the first
  3493. procedure etc.; @code{printlevel} has the value 0 by default, but can be
  3494. set to any integer value by the user).
  3495. For example, if the following procedure @code{Test} is called
  3496. directly from the top level then @samp{comment1} is displayed (i.e.,
  3497. printed out) but not
  3498. @samp{comment2}; and nothing is displayed if @code{Test} is called
  3499. from within any other procedure.
  3500. However, if @code{printlevel} is set to a value k with k>0, then
  3501. @samp{comment1} (resp.@: @samp{comment2}) is displayed provided that
  3502. @code{Test} is called from other procedures, with a nesting level up to
  3503. k (resp.@: k-1).
  3504. Note furthermore, that the example part of a procedure
  3505. behaves in this respect like a procedure (i.e., the value of @code{voice}
  3506. is 1). Therefore, the command @code{printlevel=1;} is necessary for
  3507. @samp{comment1} to be displayed on @code{ example Test;}. However,
  3508. since printlevel is a global variable, it should be reset to the old
  3509. value at the end of the example part.
  3510. @smallexample
  3511. proc Test
  3512. "USAGE: ...
  3513. ...
  3514. EXAMPLE: example Test; shows an example
  3515. "
  3516. @{ ...
  3517. int p = printlevel - voice + 3;
  3518. ...
  3519. dbprint(p,"comment1");
  3520. dbprint(p-1,"comment2");
  3521. // dbprint prints only if p > 0
  3522. ...
  3523. @}
  3524. example
  3525. @{ "EXAMPLE:"; echo = 2;
  3526. int p = printlevel; //store old value of printlevel
  3527. printlevel = 1; //assign new value to printlevel
  3528. ...
  3529. Test();
  3530. printlevel = p; //reset printlevel to old value
  3531. @}
  3532. @end smallexample
  3533. @end enumerate
  3534. @c @end table
  3535. @c ---------------------------------------
  3536. @node Documentation of a library, Typesetting of help strings, Procedures in a library, Guidelines for writing a library
  3537. @subsection Documentation of a library
  3538. @cindex Documentation of a library
  3539. @cindex library, documentation
  3540. The typesetting language in which the @sc{Singular} documentation is
  3541. written is @code{texinfo}. Based on various tools, @code{info, dvi, ps,} and
  3542. @code{html} versions of the @code{texinfo} documentation are generated.
  3543. Starting with @sc{Singular} version 1-3, the @code{texinfo}
  3544. documentation of all libraries of the @sc{Singular} distribution is
  3545. generated automatically from their source code.
  3546. More precisely, for each library,
  3547. @itemize @minus
  3548. @item
  3549. the info string of the library is parsed and typeset
  3550. as explained in @ref{Typesetting of help strings}.
  3551. @item
  3552. the help string of each procedure listed in the @code{PROCEDURE:}
  3553. section of the library info string is parsed
  3554. and typeset as explained in @ref{Typesetting of help strings}.
  3555. @item
  3556. the example of each procedure listed in the @code{PROCEDURE:} section of
  3557. the library info string is computed and its output is
  3558. included into the documentation.
  3559. @end itemize
  3560. For a uniform look-and-feel of the library documentation, library
  3561. developers should
  3562. @itemize @minus
  3563. @item
  3564. follow the recommendation of
  3565. @ref{The help string of a library} and @ref{The help string of
  3566. procedures}.
  3567. @item
  3568. consult the source code of libraries like
  3569. @code{template.lib} (@pxref{template_lib})
  3570. for examples on how library documentations are
  3571. written.
  3572. @item
  3573. make sure that each procedure listed in the @code{PROCEDURE:}
  3574. section of the library info string has a help string and an example
  3575. section.
  3576. @item
  3577. not use interactive functions like
  3578. @code{pause("..")} or @code{read("");} (@pxref{read}) and should limit the
  3579. length of input lines to 60 characters in the example section of
  3580. procedures.
  3581. @item
  3582. carefully check the generated
  3583. documentation of their libraries in its various formats using the
  3584. @code{lib2doc} (@pxref{lib2doc}) utility.
  3585. @end itemize
  3586. @menu
  3587. * lib2doc::
  3588. @end menu
  3589. @node lib2doc,,,Documentation of a library
  3590. @subsubsection lib2doc
  3591. @cindex lib2doc
  3592. @include lib2doc.texi
  3593. @c ----------------------------------------
  3594. @node Typesetting of help strings, The help string of a library, Documentation of a library, Guidelines for writing a library
  3595. @subsection Typesetting of help strings
  3596. @cindex Typesetting of help strings
  3597. @cindex library, typesetting of help strings
  3598. The help strings of procedures and info strings of libraries which are
  3599. included in the
  3600. distribution of @sc{Singular} are parsed and automatically converted
  3601. into the texinfo format (the typesetting language in which the
  3602. documentation of @sc{Singular} is written).
  3603. For optimal typesetting results, the guidelines for writing libraries
  3604. and procedures should be followed, and the following points should be
  3605. kept in mind:
  3606. @itemize @bullet
  3607. @item
  3608. If a help string starts with an @code{@@} sign, then no parsing is done,
  3609. and the help string is assumed to be already in the texinfo format.
  3610. @item
  3611. help strings are typeset within a @code{@@table @@asis} environment
  3612. (which is similar to a latex @code{description} environment).
  3613. @item
  3614. If a line starts with only uppercase words and contains a colon, then
  3615. the text up
  3616. to the colon is taken to be the description-string of an item and the
  3617. text following the colon is taken to be the content of the item.
  3618. @item
  3619. If the description-string of an item matches
  3620. @table @asis
  3621. @item @code{EXAMPLE}
  3622. then this item and its content is ignored.
  3623. @item @code{SEE ALSO}
  3624. then the
  3625. content of the item is assumed to be comma-separated words which are
  3626. valid references to other texinfo nodes of the manual. (e.g., all
  3627. procedure and command names are also texinfo nodes).
  3628. @item @code{KEYWORDS} (or, @code{KEYPHRASES})
  3629. then the content of the item is assumed to be a
  3630. semicolon-separated list of phrases which are taken as keys for the
  3631. index of the manual (N.B. the name of a procedure/library is
  3632. automatically added to the index keys).
  3633. @item @code{PROCEDURES}
  3634. then the
  3635. content of the item is assumed to be a summary description of the
  3636. procedures contained in the library. Separate texinfo nodes (subsections
  3637. in printed documents) are
  3638. @strong{only} created out of the help strings of such procedures which
  3639. appear in the summary description of a library.
  3640. @item @code{LIBRARY}
  3641. then the content of the item is assumed to be a one-line description of
  3642. a library. If this one-line description consist of only uppercase
  3643. characters, then it is typeset in all lowercase characters in the
  3644. manual (otherwise it is left as is).
  3645. @end table
  3646. @item
  3647. For the content of an item, the following texinfo markup elements
  3648. are recognized (and, their content not further manipulated):
  3649. @table @asis
  3650. @item @code{@@*}
  3651. to enforce a line-break.
  3652. @table @asis
  3653. @item Example:
  3654. @code{old line @@* new line}
  3655. @* @expansion{}
  3656. @* old line @* new line
  3657. @end table
  3658. @item @code{@@ref@{...@}}
  3659. References to other parts of the @sc{Singular} manual can be set using
  3660. one of the following @code{@@ref@{node@}} constructs. Notice that
  3661. @code{node} must be the name of a section of the @sc{Singular}
  3662. manual. In particular, it may be a name of a function, library or library
  3663. procedure.
  3664. @table @asis
  3665. @item @code{@@xref@{node@}}
  3666. for a reference to the node @code{node} at the beginning of a sentence.
  3667. @item @code{@@ref@{node@}}
  3668. for a reference to the node @code{node} at the end of a sentence.
  3669. @item @code{@@pxref@{node@}}
  3670. for a reference to the node @code{node} within parenthesis.
  3671. @item Example:
  3672. @code{@@xref@{Tropical Storms@}, for more info.}
  3673. @*@expansion{}*Note Hurricanes::, for more info.
  3674. @*@expansion{}See Section 3.1 [Hurricanes], page 24, for more info.
  3675. @code{For more information, see @@ref@{Hurricanes@}.}
  3676. @*@expansion{}For more information, see *Note Hurricanes::.
  3677. @*@expansion{}For more information, see Section 3.1 [Hurricanes], page 24.
  3678. @code{... storms cause flooding (@@pxref@{Hurricanes@}) ...}
  3679. @*@expansion{}... storms cause flooding (*Note Hurricanes::) ...
  3680. @*@expansion{}... storms cause flooding (see Section 3.1 [Hurricanes],
  3681. page 24)
  3682. @end table
  3683. @item @code{@@math@{..@}}
  3684. for typesetting of small (i.e., which do not go over
  3685. multiple lines) mathematical expressions in LaTeX math-mode
  3686. syntax.
  3687. @table @asis
  3688. @item Example:
  3689. @code{@@math@{\alpha@}}
  3690. @*@expansion{}
  3691. @*
  3692. @ifinfo
  3693. @math{\alpha}
  3694. @end ifinfo
  3695. @tex
  3696. $\alpha$
  3697. @end tex
  3698. @item Note:
  3699. Mathematical expressions inside @code{@@math@{..@}} may
  3700. not contain curly parenthesis and the "at" sign, i.e., may not contain
  3701. @code{@{,@},@@}.
  3702. @end table
  3703. @item @code{@@code@{..@}}
  3704. for typesetting of small (i.e., which do not go over
  3705. multiple lines) strings in typewriter font.
  3706. @table @asis
  3707. @item Example:
  3708. @code{@@code@{typewriter font@}}
  3709. @*@expansion{}
  3710. @*@code{typewriter font}
  3711. @item Note:
  3712. The string inside @code{@@code@{..@}} may
  3713. not contain curly parenthesis and the "at" sign, i.e., may not contain
  3714. @code{@{,@},@@}.
  3715. @end table
  3716. @item @code{@@example}
  3717. @code{...}
  3718. @item @code{@@end example}
  3719. for pre-formatted text which is indented and typeset in typewriter
  3720. font.
  3721. @table @asis
  3722. @item Example:
  3723. @example
  3724. before example
  3725. @@example
  3726. in example
  3727. notice extra identation and
  3728. escape of special characters like @@@{,@@@},@@@@
  3729. @@end example
  3730. after example
  3731. @end example
  3732. @expansion{}
  3733. @*before example
  3734. @example
  3735. in example
  3736. notice extra identation and
  3737. escape of special characters like @{,@},@@
  3738. @end example
  3739. after example
  3740. @item Note:
  3741. The characters @{,@},@@ have to be escaped by an @@ sign inside an
  3742. @@example environment.
  3743. @end table
  3744. @item @code{@@format}
  3745. @code{...}
  3746. @item @code{@@end format}
  3747. for pre-formatted text which is not indented and typeset in normal
  3748. font.
  3749. @table @asis
  3750. @item Example:
  3751. @example
  3752. before format
  3753. @@format
  3754. in format
  3755. no extra identation but still
  3756. escape of special characters like @@@{,@@@},@@@@
  3757. @@end format
  3758. after format
  3759. @end example
  3760. @expansion{}
  3761. @*before format
  3762. @format
  3763. in format
  3764. no extra identation but still
  3765. escape of special characters like @{,@},@@
  3766. @end format
  3767. after format
  3768. @item Note:
  3769. The characters @{,@},@@ have to be escaped by an @@ sign inside an
  3770. @@example environment.
  3771. @end table
  3772. @item @code{@@texinfo}
  3773. @code{...}
  3774. @item @code{@@end texinfo}
  3775. for text which is written in pure texinfo.
  3776. @table @asis
  3777. @item Example:
  3778. @example
  3779. @@texinfo
  3780. Among others, within a texinfo environment
  3781. one can use the tex environment to typeset
  3782. more complex mathematical like
  3783. @@tex
  3784. $i_@{1,1@} $
  3785. @@tex
  3786. @@end texinfo
  3787. @end example
  3788. @*@expansion{}
  3789. @*Among others, within a texinfo environment one can use the tex environment
  3790. to typeset more complex mathematical like
  3791. @tex
  3792. $ i_{1,1} $
  3793. @end tex
  3794. @end table
  3795. @end table
  3796. Furthermore, a line-break is inserted in front of each line
  3797. whose previous line is shorter than 60
  3798. characters and does not contain any of the above described recognized
  3799. texinfo markup elements.
  3800. @end itemize
  3801. See also @ref{template_lib} for an examples of the typesetting rules
  3802. explained here.
  3803. @c ----------------------------------------
  3804. @node The help string of a library, The help string of procedures, Typesetting of help strings, Guidelines for writing a library
  3805. @subsection The help string of a library
  3806. @cindex help string of a library
  3807. @cindex library, help string
  3808. @cindex library, info string
  3809. @cindex info string of a library
  3810. The help (or, info) string of a library should have the following format:
  3811. @smallexample
  3812. info="
  3813. LIBRARY: <library_name> <one line description of the content>
  3814. AUTHOR: <name, and email address of author>
  3815. [SEE ALSO: <comma-separated words of cross references>]
  3816. [KEYWORDS: <semicolon-separated phrases of index keys>]
  3817. PROCEDURES:
  3818. <procedure1>; <one line description of the purpose>
  3819. .
  3820. .
  3821. <procedureN>; <one line description of the purpose>
  3822. ";
  3823. @end smallexample
  3824. Only such procedures should be listed in the @code{PROCEDURE} section
  3825. which are not @code{static} and which
  3826. have a help and example section.
  3827. The purpose of the one line procedure descriptions is not to give a short help
  3828. for the procedure, but to help the user decide what procedure might be
  3829. the right one for the job. Details can then be found in the help section
  3830. of each procedure. Therefore parameters may be omitted or abbreviated if
  3831. necessary. If this description consists of only upper-case characters,
  3832. then it will be typeset in all lowercase characters in the manual.
  3833. For more information, see @ref{Typesetting of help strings}. For an
  3834. example, see @ref{template_lib}.
  3835. @c ----------------------------------------
  3836. @node The help string of procedures, template_lib, The help string of a library, Guidelines for writing a library
  3837. @subsection The help string of procedures
  3838. @cindex help string of a procedure
  3839. @cindex procedures, help string
  3840. The help string of a procedure should have the following format:
  3841. @smallexample
  3842. USAGE: <proc_name>(<parameters>); <explanation of parameters>
  3843. [CREATE: <description of created objects which are not returned>]
  3844. RETURN: <description of the purpose and return value>
  3845. [NOTE: <particular assumptions or limitations, details>]
  3846. [SEE ALSO: <comma-separated names of related procedures/cross references>]
  3847. [KEYWORDS: <semicolon-separated phrases of index keys>]
  3848. EXAMPLE: example <proc_name>; shows an example
  3849. @end smallexample
  3850. Further arbitrary items (like @code{THEORY:}, or @code{BACKGROUND:}) are
  3851. recognized, as well, but should be used diligently.
  3852. Remember that help strings are formatted as explained in
  3853. @ref{Typesetting of help strings}. In particular, descriptions may
  3854. contain the texinfo markup elements @code{@@*, @@math@{..@},
  3855. @@code@{..@}, @@example, @@format, @@texinfo} to better control their
  3856. typesetting. See @ref{msum}, @ref{mdouble}, @ref{mtripple} for examples.
  3857. @c ----------------------------------------
  3858. @node template_lib,, The help string of procedures, Guidelines for writing a library
  3859. @subsection template_lib
  3860. @cindex template_lib
  3861. @cindex Template for writing a library
  3862. @cindex library, template
  3863. First, we show the source-code of a template library:
  3864. @smallexample
  3865. @c begin included file template.lib from general.doc:3933
  3866. ////////////////////////////////////////////////////////////////////
  3867. // version string automatically expanded by CVS
  3868. version="Id: general.tex,v 1.1 2003/08/08 14:27:06 pertusus Exp $";
  3869. category="Miscellaneous";
  3870. // summary description of the library
  3871. info="
  3872. LIBRARY: template.lib A Template for a Singular Library
  3873. AUTHOR: Olaf Bachmann, email: obachman@@mathematik.uni-kl.de
  3874. SEE ALSO: standard_lib, Guidelines for writing a library,
  3875. Typesetting of help strings
  3876. KEYWORDS: library, template.lib; template.lib; library, info string
  3877. PROCEDURES:
  3878. mdouble(int) return double of int argument
  3879. mtripple(int) return three times int argument
  3880. msum([int,..,int]) sum of int arguments
  3881. ";
  3882. ////////////////////////////////////////////////////////////////////
  3883. proc mdouble(int i)
  3884. "USAGE: mdouble(i); i int
  3885. RETURN: int: i+i
  3886. NOTE: Help string is in pure ASCII
  3887. this line starts on a new line since previous line is short
  3888. mdouble(i): no new line
  3889. SEE ALSO: msum, mtripple, Typesetting of help strings
  3890. KEYWORDS: procedure, ASCII help
  3891. EXAMPLE: example mdouble; shows an example"
  3892. @{
  3893. return (i + i);
  3894. @}
  3895. example
  3896. @{ "EXAMPLE:"; echo = 2;
  3897. mdouble(0);
  3898. mdouble(-1);
  3899. @}
  3900. ////////////////////////////////////////////////////////////////////
  3901. proc mtripple(int i)
  3902. "@@c we do texinfo here
  3903. @@table @@asis
  3904. @@item @@strong@{Usage:@}
  3905. @@code@{mtripple(i)@}; @@code@{i@} int
  3906. @@item @@strong@{Return:@}
  3907. int: @@math@{i+i+i@}
  3908. @@item @@strong@{Note:@}
  3909. Help is in pure Texinfo
  3910. @@*This help string is written in texinfo, which enables you to use,
  3911. among others, the @@@@math command for mathematical typesetting (like
  3912. @@math@{\alpha, \beta@}).
  3913. @@*It also gives more control over the layout, but is, admittingly,
  3914. more cumbersome to write.
  3915. @@end table
  3916. @@c use @@c ref contstuct for references
  3917. @@cindex procedure, texinfo help
  3918. @@c ref
  3919. @@strong@{See also:@}
  3920. @@ref@{mdouble@}, @@ref@{msum@}, @@ref@{Typesetting of help strings@}
  3921. @@c ref
  3922. "
  3923. @{
  3924. return (i + i + i);
  3925. @}
  3926. example
  3927. @{ "EXAMPLE:"; echo = 2;
  3928. mtripple(0);
  3929. mtripple(-1);
  3930. @}
  3931. ////////////////////////////////////////////////////////////////////
  3932. proc msum(list #)
  3933. "USAGE: msum([i_1,..,i_n]); @@code@{i_1,..,i_n@} def
  3934. RETURN: Sum of int arguments
  3935. NOTE: This help string is written in a mixture of ASCII and texinfo
  3936. @@* Use a @@ref constructs for references (like @@pxref@{mtripple@})
  3937. @@* Use @@code for typewriter font (like @@code@{i_1@})
  3938. @@* Use @@math for simple math mode typesetting (like @@math@{i_1@}).
  3939. @@* Note: No parenthesis like @} are allowed inside @@math and @@code
  3940. @@* Use @@example for indented preformatted text typeset in typewriter
  3941. font like
  3942. @@example
  3943. this --> that
  3944. @@end example
  3945. Use @@format for preformatted text typeset in normal font
  3946. @@format
  3947. this --> that
  3948. @@end format
  3949. Use @@texinfo for text in pure texinfo
  3950. @@texinfo
  3951. @@expansion@{@}
  3952. @@tex
  3953. $i_@{1,1@}$
  3954. @@end tex
  3955. @@end texinfo
  3956. Notice that
  3957. automatic linebreaking is still in affect (like on this line).
  3958. SEE ALSO: mdouble, mtripple, Typesetting of help strings
  3959. KEYWORDS: procedure, ASCII/Texinfo help
  3960. EXAMPLE: example msum; shows an example"
  3961. @{
  3962. if (size(#) == 0) @{ return (0);@}
  3963. if (size(#) == 1) @{ return (#[1]);@}
  3964. int i;
  3965. def s = #[1];
  3966. for (i=2; i<=size(#); i++)
  3967. @{
  3968. s = s + #[i];
  3969. @}
  3970. return (s);
  3971. @}
  3972. example
  3973. @{ "EXAMPLE:"; echo = 2;
  3974. msum();
  3975. msum(4);
  3976. msum(1,2,3,4);
  3977. @}
  3978. @c end included file from general.doc:3933
  3979. @end smallexample
  3980. After typesetting, the library appears in the document as follows (with
  3981. one subsection for each procedure):
  3982. @c include of docu for template.lib
  3983. @include d2t_singular/template_lib.tex
  3984. @c ----------------------------------------------------------------------
  3985. @node Debugging tools, , Guidelines for writing a library, General concepts
  3986. @section Debugging tools
  3987. @cindex Debugging tools
  3988. If @sc{Singular} does not come back to the prompt while calling a user
  3989. defined procedure, probably a bracket or a @code{"} is missing. The
  3990. easiest way to leave the procedure is to type some brackets or @code{"}
  3991. and then @key{RETURN} .
  3992. @menu
  3993. * Tracing of procedures::
  3994. * Source code debugger::
  3995. * Break points::
  3996. * Printing of data::
  3997. * libparse::
  3998. @end menu
  3999. @c ---------------------------------------
  4000. @node Tracing of procedures,Source code debugger,Debugging tools,Debugging tools
  4001. @subsection Tracing of procedures
  4002. Setting the @code{TRACE} variable to 1 (resp.@: 3) results in a listing of
  4003. the called procedures (resp.@: together with line numbers).
  4004. If @code{TRACE} is set to 4, @code{Singular}
  4005. displays each line before its interpretation and waits for the @key{RETURN}
  4006. key being pressed.
  4007. @menu
  4008. * TRACE var::
  4009. @end menu
  4010. @iftex
  4011. See @ref{TRACE var}.
  4012. @end iftex
  4013. @strong{Example:}
  4014. @smallexample
  4015. @c computed example Tracing_of_procedures general.doc:3976
  4016. proc t1
  4017. @{
  4018. int i=2;
  4019. while (i>0)
  4020. @{ i=i-1; @}
  4021. @}
  4022. TRACE=3;
  4023. t1();
  4024. @expansion{}
  4025. @expansion{} entering t1 (level 0)
  4026. @expansion{} @{1@}@{2@}@{3@}@{4@}@{5@}@{4@}@{5@}@{6@}@{7@}@{4@}@{5@}@{6@}@{7@}@{4@}@{6@}@{7@}@{8@}
  4027. @expansion{} leaving t1 (level 0)
  4028. @c end example Tracing_of_procedures general.doc:3976
  4029. @end smallexample
  4030. @c ---------------------------------------
  4031. @node Source code debugger, Break points, Tracing of procedures, Debugging tools
  4032. @subsection Source code debugger
  4033. @cindex debugging library code
  4034. @cindex source code debugger, sdb
  4035. @cindex debugger
  4036. @cindex sdb, source code debugger
  4037. The source code debugger (sdb) is an experimental feature, it's
  4038. interface may change in future versions of Singular. @*To enable the
  4039. use of the source code debugger @sc{Singular} has to be started with the
  4040. option @code{-d} or @code{--sdb} (see @ref{Command line options}).
  4041. @subsubheading sdb commands
  4042. Each sdb command consist of one character which may be followed by
  4043. a parameter.
  4044. @table @asis
  4045. @item @code{b}
  4046. print backtrace of calling stack
  4047. @item @code{c}
  4048. continue
  4049. @item @code{e}
  4050. edit the current procedure and reload it (current call will be aborted)
  4051. @* only available on UNIX systems
  4052. @item @code{h},@code{?}
  4053. display help screen
  4054. @item @code{n}
  4055. execute current line, sdb break at next line
  4056. @item @code{p} <identifier>
  4057. display type and value of the variable given by <identifier>
  4058. @item @code{Q}
  4059. quit this Singular session
  4060. @item @code{q} <flags>
  4061. quit debugger, set debugger flags(0,1,2)
  4062. @* 0: continue, disable the debugger
  4063. @* 1: continue
  4064. @* 2: throw an error, return to toplevel
  4065. @end table
  4066. @subsubheading Syntactical errors in procedures
  4067. If @sc{Singular} was started with the command line option @code{-d} or
  4068. @code{--sdb} a syntactical error in a procedure will start the
  4069. source code debugger instead of returning to the top level with an
  4070. error message. The commands @code{q 1} and @code{q 2} are equivalent in this
  4071. case.
  4072. @subsubheading SDB breakpoints in procedures
  4073. @cindex SDB breakpoint
  4074. @cindex SDB debugger
  4075. Up to seven SDB breakpoints can be set.
  4076. To set a breakpoint at a procedure use
  4077. @code{breakpoint}. (See @ref{breakpoint}).
  4078. @*These breakpoints can be cleared with the command @code{d breakpoint_no}
  4079. from within the debugger or with
  4080. @code{breakpoint(} proc_name @code{,-1);}.
  4081. @c ---------------------------------------
  4082. @node Break points, Printing of data, Source code debugger, Debugging tools
  4083. @subsection Break points
  4084. A break point can be put into a proc by inserting the command @code{~}.
  4085. If @code{Singular} reaches a break point it asks for lines of commands
  4086. (line-length must be less than 80 characters)
  4087. from the user. It returns to normal execution if given an empty line.
  4088. See @ref{~}.
  4089. @strong{Example:}
  4090. @smallexample
  4091. proc t
  4092. @{
  4093. int i=2;
  4094. ~;
  4095. return(i+1);
  4096. @}
  4097. t();
  4098. @expansion{} -- break point in t --
  4099. @expansion{} -- 0: called from STDIN --
  4100. i; // here local variables of the procedure can be accessed
  4101. @expansion{} 2
  4102. @expansion{} -- break point in t --
  4103. @expansion{} 3
  4104. @end smallexample
  4105. @sp 2
  4106. @c ---------------------------------------
  4107. @node Printing of data,libparse,Break points,Debugging tools
  4108. @subsection Printing of data
  4109. The procedure @code{dbprint} is useful for optional output of data:
  4110. it takes 2 arguments and prints the second argument, if the first
  4111. argument is positive; it does nothing otherwise.
  4112. @menu
  4113. * dbprint::
  4114. * voice::
  4115. @end menu
  4116. @ifnothtml
  4117. @iftex
  4118. See @ref{dbprint}; @ref{voice}.
  4119. @end iftex
  4120. @end ifnothtml
  4121. @c ---------------------------------------
  4122. @node libparse,,Printing of data,Debugging tools
  4123. @subsection libparse
  4124. @cindex libparse
  4125. @code{libparse} is a stand-alone program contained in the @sc{Singular}
  4126. distribution (at the place where the @sc{Singular} executable program
  4127. resides), which cannot be called inside of @sc{Singular}. It is a
  4128. debugging tool for libraries which performs exactly the same checks as
  4129. @ifset namespaces
  4130. the @code{load} command in @sc{Singular}, but generates more output during
  4131. @end ifset
  4132. @ifclear namespaces
  4133. the @code{LIB} command in @sc{Singular}, but generates more output during
  4134. @end ifclear
  4135. parsing. @code{libparse} is useful if an error
  4136. occurs while loading the library, but the whole block around the line
  4137. specified seems to be correct. In these situations the real error might
  4138. be hundreds of lines earlier in the library.
  4139. @strong{Usage:}
  4140. @*@code{libparse [options] singular-library}
  4141. @*@strong{Options:}
  4142. @table @asis
  4143. @item @code{-d} Debuglevel
  4144. increases the amount of output during parsing, where Debuglevel is an integer
  4145. between 0 and 4. Default is 0.
  4146. @item @code{-s}
  4147. turns on reporting about violations of unenforced syntax rules
  4148. @end table
  4149. The following syntax checks are performed in any case:
  4150. @itemize @bullet
  4151. @item counting of pairs of brackets @{,@} , [,] and (,)
  4152. (number of @{ has to match number of @}, same for [,] and (,) ).
  4153. @item counting of "
  4154. ( number of " must be even ).
  4155. @item general library syntax
  4156. ( only LIB, static, proc (with parameters, help, body and example)
  4157. and comments, i.e // and @code{/* ... */}, are allowed).
  4158. @end itemize
  4159. Its output lists all procedures that have been parsed successfully:
  4160. @smallexample
  4161. $ libparse sample.lib
  4162. Checking library 'sample.lib'
  4163. Library function line,start-eod line,body-eob line,example-eoe
  4164. Version:0.0.0;
  4165. g Sample tab line 9, 149-165 13, 271-298 14, 300-402
  4166. l Sample internal_tab line 24, 450-475 25, 476-496 0, 0-496
  4167. @end smallexample
  4168. where the following abbreviations are used:
  4169. @itemize @bullet
  4170. @item g: global procedure (default)
  4171. @item l: static procedure, i.e., local to the library.
  4172. @end itemize
  4173. each of the following is the position of the byte in the library.
  4174. @itemize @bullet
  4175. @item start: begin of 'proc'
  4176. @item eod: end of parameters
  4177. @item body: start of procedure body '@{'
  4178. @item eob: end of procedure body '@}'
  4179. @item example: position of 'example'
  4180. @item eoe: end of example '@}'
  4181. @end itemize
  4182. Hence in the above example, the first procedure of the library
  4183. sample.lib is user-accessible and its name is tab. The procedure
  4184. starts in line 9, at character 149. The head of the procedure
  4185. ends at character 165, the body starts in line 13 at character 271
  4186. and ends at character 298. The example section extends from line 14
  4187. character 300 to character 402.
  4188. The following example shows the result of a missing close-bracket @} in
  4189. line 26 of the library @code{sample.lib}.
  4190. @smallexample
  4191. LIB "sample.lib";
  4192. @expansion{} ? Library sample.lib: ERROR occurred: in line 26, 497.
  4193. @expansion{} ? missing close bracket '@}' at end of library in line 26.
  4194. @expansion{} ? Cannot load library,... aborting.
  4195. @expansion{} ? error occurred in STDIN line 1: `LIB "sample.lib";`
  4196. @end smallexample