calc-lang.el 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528
  1. ;;; calc-lang.el --- calc language functions
  2. ;; Copyright (C) 1990-1993, 2001-2015 Free Software Foundation, Inc.
  3. ;; Author: David Gillespie <daveg@synaptics.com>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;; Code:
  17. ;; This file is autoloaded from calc-ext.el.
  18. (require 'calc-ext)
  19. (require 'calc-macs)
  20. ;; Declare functions which are defined elsewhere.
  21. (declare-function math-compose-vector "calccomp" (a sep prec))
  22. (declare-function math-compose-var "calccomp" (a))
  23. (declare-function math-tex-expr-is-flat "calccomp" (a))
  24. (declare-function math-read-factor "calc-aent" ())
  25. (declare-function math-read-expr-level "calc-aent" (exp-prec &optional exp-term))
  26. ;; Declare variables which are defined elsewhere.
  27. (defvar calc-lang-slash-idiv)
  28. (defvar calc-lang-allow-underscores)
  29. (defvar calc-lang-allow-percentsigns)
  30. (defvar math-comp-left-bracket)
  31. (defvar math-comp-right-bracket)
  32. (defvar math-comp-comma)
  33. (defvar math-comp-vector-prec)
  34. ;;; Alternate entry/display languages.
  35. (defun calc-set-language (lang &optional option no-refresh)
  36. (setq math-expr-opers (or (get lang 'math-oper-table) (math-standard-ops))
  37. math-expr-function-mapping (get lang 'math-function-table)
  38. math-expr-variable-mapping (get lang 'math-variable-table)
  39. calc-language-input-filter (get lang 'math-input-filter)
  40. calc-language-output-filter (get lang 'math-output-filter)
  41. calc-vector-brackets (or (get lang 'math-vector-brackets) "[]")
  42. calc-complex-format (get lang 'math-complex-format)
  43. calc-radix-formatter (get lang 'math-radix-formatter)
  44. calc-function-open (or (get lang 'math-function-open) "(")
  45. calc-function-close (or (get lang 'math-function-close) ")"))
  46. (if no-refresh
  47. (setq calc-language lang
  48. calc-language-option option)
  49. (calc-change-mode '(calc-language calc-language-option)
  50. (list lang option) t)))
  51. (defun calc-normal-language ()
  52. (interactive)
  53. (calc-wrapper
  54. (calc-set-language nil)
  55. (message "Normal language mode")))
  56. (defun calc-flat-language ()
  57. (interactive)
  58. (calc-wrapper
  59. (calc-set-language 'flat)
  60. (message "Flat language mode (all stack entries shown on one line)")))
  61. (defun calc-big-language ()
  62. (interactive)
  63. (calc-wrapper
  64. (calc-set-language 'big)
  65. (message "\"Big\" language mode")))
  66. (defun calc-unformatted-language ()
  67. (interactive)
  68. (calc-wrapper
  69. (calc-set-language 'unform)
  70. (message "Unformatted language mode")))
  71. (defun calc-c-language ()
  72. (interactive)
  73. (calc-wrapper
  74. (calc-set-language 'c)
  75. (message "C language mode")))
  76. (put 'c 'math-oper-table
  77. '( ( "u!" calcFunc-lnot -1 1000 )
  78. ( "~" calcFunc-not -1 1000 )
  79. ( "u+" ident -1 197 )
  80. ( "u-" neg -1 197 )
  81. ( "*" * 190 191 )
  82. ( "/" / 190 191 )
  83. ( "%" % 190 191 )
  84. ( "+" + 180 181 )
  85. ( "-" - 180 181 )
  86. ( "<<" calcFunc-lsh 170 171 )
  87. ( ">>" calcFunc-rsh 170 171 )
  88. ( "<" calcFunc-lt 160 161 )
  89. ( ">" calcFunc-gt 160 161 )
  90. ( "<=" calcFunc-leq 160 161 )
  91. ( ">=" calcFunc-geq 160 161 )
  92. ( "==" calcFunc-eq 150 151 )
  93. ( "!=" calcFunc-neq 150 151 )
  94. ( "&" calcFunc-and 140 141 )
  95. ( "^" calcFunc-xor 131 130 )
  96. ( "|" calcFunc-or 120 121 )
  97. ( "&&" calcFunc-land 110 111 )
  98. ( "||" calcFunc-lor 100 101 )
  99. ( "?" (math-read-if) 91 90 )
  100. ( "!!!" calcFunc-pnot -1 88 )
  101. ( "&&&" calcFunc-pand 85 86 )
  102. ( "|||" calcFunc-por 75 76 )
  103. ( "=" calcFunc-assign 51 50 )
  104. ( ":=" calcFunc-assign 51 50 )
  105. ( "::" calcFunc-condition 45 46 ))) ; should support full assignments
  106. (put 'c 'math-function-table
  107. '( ( acos . calcFunc-arccos )
  108. ( acosh . calcFunc-arccosh )
  109. ( asin . calcFunc-arcsin )
  110. ( asinh . calcFunc-arcsinh )
  111. ( atan . calcFunc-arctan )
  112. ( atan2 . calcFunc-arctan2 )
  113. ( atanh . calcFunc-arctanh )
  114. ( fma . (math-C-parse-fma))
  115. ( fmax . calcFunc-max )
  116. ( j0 . (math-C-parse-bess))
  117. ( jn . calcFunc-besJ )
  118. ( j1 . (math-C-parse-bess))
  119. ( yn . calcFunc-besY )
  120. ( y0 . (math-C-parse-bess))
  121. ( y1 . (math-C-parse-bess))
  122. ( tgamma . calcFunc-gamma )))
  123. (defun math-C-parse-bess (f val)
  124. "Parse C's j0, j1, y0, y1 functions."
  125. (let ((args (math-read-expr-list)))
  126. (math-read-token)
  127. (append
  128. (cond ((eq val 'j0) '(calcFunc-besJ 0))
  129. ((eq val 'j1) '(calcFunc-besJ 1))
  130. ((eq val 'y0) '(calcFunc-besY 0))
  131. ((eq val 'y1) '(calcFunc-besY 1)))
  132. args)))
  133. (defun math-C-parse-fma (f val)
  134. "Parse C's fma function fma(x,y,z) => (x * y + z)."
  135. (let ((args (math-read-expr-list)))
  136. (math-read-token)
  137. (list 'calcFunc-add
  138. (list 'calcFunc-mul
  139. (nth 0 args)
  140. (nth 1 args))
  141. (nth 2 args))))
  142. (put 'c 'math-variable-table
  143. '( ( M_PI . var-pi )
  144. ( M_E . var-e )))
  145. (put 'c 'math-vector-brackets "{}")
  146. (put 'c 'math-radix-formatter
  147. (function (lambda (r s)
  148. (if (= r 16) (format "0x%s" s)
  149. (if (= r 8) (format "0%s" s)
  150. (format "%d#%s" r s))))))
  151. (put 'c 'math-compose-subscr
  152. (function
  153. (lambda (a)
  154. (let ((args (cdr (cdr a))))
  155. (list 'horiz
  156. (math-compose-expr (nth 1 a) 1000)
  157. "["
  158. (math-compose-vector args ", " 0)
  159. "]")))))
  160. (add-to-list 'calc-lang-slash-idiv 'c)
  161. (add-to-list 'calc-lang-allow-underscores 'c)
  162. (add-to-list 'calc-lang-c-type-hex 'c)
  163. (add-to-list 'calc-lang-brackets-are-subscripts 'c)
  164. (defun calc-pascal-language (n)
  165. (interactive "P")
  166. (calc-wrapper
  167. (and n (setq n (prefix-numeric-value n)))
  168. (calc-set-language 'pascal n)
  169. (message (if (and n (/= n 0))
  170. (if (> n 0)
  171. "Pascal language mode (all uppercase)"
  172. "Pascal language mode (all lowercase)")
  173. "Pascal language mode"))))
  174. (put 'pascal 'math-oper-table
  175. '( ( "not" calcFunc-lnot -1 1000 )
  176. ( "*" * 190 191 )
  177. ( "/" / 190 191 )
  178. ( "and" calcFunc-and 190 191 )
  179. ( "div" calcFunc-idiv 190 191 )
  180. ( "mod" % 190 191 )
  181. ( "u+" ident -1 185 )
  182. ( "u-" neg -1 185 )
  183. ( "+" + 180 181 )
  184. ( "-" - 180 181 )
  185. ( "or" calcFunc-or 180 181 )
  186. ( "xor" calcFunc-xor 180 181 )
  187. ( "shl" calcFunc-lsh 180 181 )
  188. ( "shr" calcFunc-rsh 180 181 )
  189. ( "in" calcFunc-in 160 161 )
  190. ( "<" calcFunc-lt 160 161 )
  191. ( ">" calcFunc-gt 160 161 )
  192. ( "<=" calcFunc-leq 160 161 )
  193. ( ">=" calcFunc-geq 160 161 )
  194. ( "=" calcFunc-eq 160 161 )
  195. ( "<>" calcFunc-neq 160 161 )
  196. ( "!!!" calcFunc-pnot -1 85 )
  197. ( "&&&" calcFunc-pand 80 81 )
  198. ( "|||" calcFunc-por 75 76 )
  199. ( ":=" calcFunc-assign 51 50 )
  200. ( "::" calcFunc-condition 45 46 )))
  201. (put 'pascal 'math-input-filter 'calc-input-case-filter)
  202. (put 'pascal 'math-output-filter 'calc-output-case-filter)
  203. (put 'pascal 'math-radix-formatter
  204. (function (lambda (r s)
  205. (if (= r 16) (format "$%s" s)
  206. (format "%d#%s" r s)))))
  207. (put 'pascal 'math-lang-read-symbol
  208. '((?\$
  209. (eq (string-match
  210. "\\(\\$[0-9a-fA-F]+\\)\\($\\|[^0-9a-zA-Zα-ωΑ-Ω]\\)"
  211. math-exp-str math-exp-pos)
  212. math-exp-pos)
  213. (setq math-exp-token 'number
  214. math-expr-data (math-match-substring math-exp-str 1)
  215. math-exp-pos (match-end 1)))))
  216. (put 'pascal 'math-compose-subscr
  217. (function
  218. (lambda (a)
  219. (let ((args (cdr (cdr a))))
  220. (while (eq (car-safe (nth 1 a)) 'calcFunc-subscr)
  221. (setq args (append (cdr (cdr (nth 1 a))) args)
  222. a (nth 1 a)))
  223. (list 'horiz
  224. (math-compose-expr (nth 1 a) 1000)
  225. "["
  226. (math-compose-vector args ", " 0)
  227. "]")))))
  228. (add-to-list 'calc-lang-allow-underscores 'pascal)
  229. (add-to-list 'calc-lang-brackets-are-subscripts 'pascal)
  230. (defun calc-input-case-filter (str)
  231. (cond ((or (null calc-language-option) (= calc-language-option 0))
  232. str)
  233. (t
  234. (downcase str))))
  235. (defun calc-output-case-filter (str)
  236. (cond ((or (null calc-language-option) (= calc-language-option 0))
  237. str)
  238. ((> calc-language-option 0)
  239. (upcase str))
  240. (t
  241. (downcase str))))
  242. (defun calc-fortran-language (n)
  243. (interactive "P")
  244. (calc-wrapper
  245. (and n (setq n (prefix-numeric-value n)))
  246. (calc-set-language 'fortran n)
  247. (message (if (and n (/= n 0))
  248. (if (> n 0)
  249. "FORTRAN language mode (all uppercase)"
  250. "FORTRAN language mode (all lowercase)")
  251. "FORTRAN language mode"))))
  252. (put 'fortran 'math-oper-table
  253. '( ( "u/" (math-parse-fortran-vector) -1 1 )
  254. ( "/" (math-parse-fortran-vector-end) 1 -1 )
  255. ( "**" ^ 201 200 )
  256. ( "u+" ident -1 191 )
  257. ( "u-" neg -1 191 )
  258. ( "*" * 190 191 )
  259. ( "/" / 190 191 )
  260. ( "+" + 180 181 )
  261. ( "-" - 180 181 )
  262. ( ".LT." calcFunc-lt 160 161 )
  263. ( ".GT." calcFunc-gt 160 161 )
  264. ( ".LE." calcFunc-leq 160 161 )
  265. ( ".GE." calcFunc-geq 160 161 )
  266. ( ".EQ." calcFunc-eq 160 161 )
  267. ( ".NE." calcFunc-neq 160 161 )
  268. ( ".NOT." calcFunc-lnot -1 121 )
  269. ( ".AND." calcFunc-land 110 111 )
  270. ( ".OR." calcFunc-lor 100 101 )
  271. ( "!!!" calcFunc-pnot -1 85 )
  272. ( "&&&" calcFunc-pand 80 81 )
  273. ( "|||" calcFunc-por 75 76 )
  274. ( "=" calcFunc-assign 51 50 )
  275. ( ":=" calcFunc-assign 51 50 )
  276. ( "::" calcFunc-condition 45 46 )))
  277. (put 'fortran 'math-vector-brackets "//")
  278. (put 'fortran 'math-function-table
  279. '( ( acos . calcFunc-arccos )
  280. ( acosh . calcFunc-arccosh )
  281. ( aimag . calcFunc-im )
  282. ( aint . calcFunc-ftrunc )
  283. ( asin . calcFunc-arcsin )
  284. ( asinh . calcFunc-arcsinh )
  285. ( atan . calcFunc-arctan )
  286. ( atan2 . calcFunc-arctan2 )
  287. ( atanh . calcFunc-arctanh )
  288. ( conjg . calcFunc-conj )
  289. ( log . calcFunc-ln )
  290. ( nint . calcFunc-round )
  291. ( real . calcFunc-re )))
  292. (put 'fortran 'math-input-filter 'calc-input-case-filter)
  293. (put 'fortran 'math-output-filter 'calc-output-case-filter)
  294. (put 'fortran 'math-lang-read-symbol
  295. '((?\.
  296. (eq (string-match "\\.[a-zA-Zα-ωΑ-Ω][a-zA-Zα-ωΑ-Ω][a-zA-Zα-ωΑ-Ω]?\\."
  297. math-exp-str math-exp-pos) math-exp-pos)
  298. (setq math-exp-token 'punc
  299. math-expr-data (upcase (math-match-substring math-exp-str 0))
  300. math-exp-pos (match-end 0)))))
  301. (put 'fortran 'math-compose-subscr
  302. (function
  303. (lambda (a)
  304. (let ((args (cdr (cdr a))))
  305. (while (eq (car-safe (nth 1 a)) 'calcFunc-subscr)
  306. (setq args (append (cdr (cdr (nth 1 a))) args)
  307. a (nth 1 a)))
  308. (list 'horiz
  309. (math-compose-expr (nth 1 a) 1000)
  310. "("
  311. (math-compose-vector args ", " 0)
  312. ")")))))
  313. (add-to-list 'calc-lang-slash-idiv 'fortran)
  314. (add-to-list 'calc-lang-allow-underscores 'fortran)
  315. (add-to-list 'calc-lang-parens-are-subscripts 'fortran)
  316. ;; The next few variables are local to math-read-exprs in calc-aent.el
  317. ;; and math-read-expr in calc-ext.el, but are set in functions they call.
  318. (defvar math-exp-token)
  319. (defvar math-expr-data)
  320. (defvar math-exp-old-pos)
  321. (defvar math-parsing-fortran-vector nil)
  322. (defun math-parse-fortran-vector (op)
  323. (let ((math-parsing-fortran-vector '(end . "\000")))
  324. (prog1
  325. (math-read-brackets t "]")
  326. (setq math-exp-token (car math-parsing-fortran-vector)
  327. math-expr-data (cdr math-parsing-fortran-vector)))))
  328. (defun math-parse-fortran-vector-end (x op)
  329. (if math-parsing-fortran-vector
  330. (progn
  331. (setq math-parsing-fortran-vector (cons math-exp-token math-expr-data)
  332. math-exp-token 'end
  333. math-expr-data "\000")
  334. x)
  335. (throw 'syntax "Unmatched closing `/'")))
  336. (defun math-parse-fortran-subscr (sym args)
  337. (setq sym (math-build-var-name sym))
  338. (while args
  339. (setq sym (list 'calcFunc-subscr sym (car args))
  340. args (cdr args)))
  341. sym)
  342. (defun calc-tex-language (n)
  343. (interactive "P")
  344. (calc-wrapper
  345. (and n (setq n (prefix-numeric-value n)))
  346. (calc-set-language 'tex n)
  347. (cond ((not n)
  348. (message "TeX language mode"))
  349. ((= n 0)
  350. (message "TeX language mode with multiline matrices"))
  351. ((= n 1)
  352. (message "TeX language mode with \\hbox{func}(\\hbox{var})"))
  353. ((> n 1)
  354. (message
  355. "TeX language mode with \\hbox{func}(\\hbox{var}) and multiline matrices"))
  356. ((= n -1)
  357. (message "TeX language mode with \\func(\\hbox{var})"))
  358. ((< n -1)
  359. (message
  360. "TeX language mode with \\func(\\hbox{var}) and multiline matrices")))))
  361. (defun calc-latex-language (n)
  362. (interactive "P")
  363. (calc-wrapper
  364. (and n (setq n (prefix-numeric-value n)))
  365. (calc-set-language 'latex n)
  366. (cond ((not n)
  367. (message "LaTeX language mode"))
  368. ((= n 0)
  369. (message "LaTeX language mode with multiline matrices"))
  370. ((= n 1)
  371. (message "LaTeX language mode with \\text{func}(\\text{var})"))
  372. ((> n 1)
  373. (message
  374. "LaTeX language mode with \\text{func}(\\text{var}) and multiline matrices"))
  375. ((= n -1)
  376. (message "LaTeX language mode with \\func(\\text{var})"))
  377. ((< n -1)
  378. (message
  379. "LaTeX language mode with \\func(\\text{var}) and multiline matrices")))))
  380. (put 'tex 'math-lang-name "TeX")
  381. (put 'latex 'math-lang-name "LaTeX")
  382. (put 'tex 'math-oper-table
  383. '( ( "\\hat" calcFunc-hat -1 950 )
  384. ( "\\check" calcFunc-check -1 950 )
  385. ( "\\tilde" calcFunc-tilde -1 950 )
  386. ( "\\acute" calcFunc-acute -1 950 )
  387. ( "\\grave" calcFunc-grave -1 950 )
  388. ( "\\dot" calcFunc-dot -1 950 )
  389. ( "\\ddot" calcFunc-dotdot -1 950 )
  390. ( "\\breve" calcFunc-breve -1 950 )
  391. ( "\\bar" calcFunc-bar -1 950 )
  392. ( "\\vec" calcFunc-Vec -1 950 )
  393. ( "\\underline" calcFunc-under -1 950 )
  394. ( "u|" calcFunc-abs -1 0 )
  395. ( "|" closing 0 -1 )
  396. ( "\\lfloor" calcFunc-floor -1 0 )
  397. ( "\\rfloor" closing 0 -1 )
  398. ( "\\lceil" calcFunc-ceil -1 0 )
  399. ( "\\rceil" closing 0 -1 )
  400. ( "\\pm" sdev 300 300 )
  401. ( "!" calcFunc-fact 210 -1 )
  402. ( "^" ^ 201 200 )
  403. ( "_" calcFunc-subscr 201 200 )
  404. ( "u+" ident -1 197 )
  405. ( "u-" neg -1 197 )
  406. ( "\\times" * 191 190 )
  407. ( "*" * 191 190 )
  408. ( "2x" * 191 190 )
  409. ( "+" + 180 181 )
  410. ( "-" - 180 181 )
  411. ( "\\over" / 170 171 )
  412. ( "/" / 170 171 )
  413. ( "\\choose" calcFunc-choose 170 171 )
  414. ( "\\mod" % 170 171 )
  415. ( "<" calcFunc-lt 160 161 )
  416. ( ">" calcFunc-gt 160 161 )
  417. ( "\\leq" calcFunc-leq 160 161 )
  418. ( "\\geq" calcFunc-geq 160 161 )
  419. ( "=" calcFunc-eq 160 161 )
  420. ( "\\neq" calcFunc-neq 160 161 )
  421. ( "\\ne" calcFunc-neq 160 161 )
  422. ( "\\lnot" calcFunc-lnot -1 121 )
  423. ( "\\land" calcFunc-land 110 111 )
  424. ( "\\lor" calcFunc-lor 100 101 )
  425. ( "?" (math-read-if) 91 90 )
  426. ( "!!!" calcFunc-pnot -1 85 )
  427. ( "&&&" calcFunc-pand 80 81 )
  428. ( "|||" calcFunc-por 75 76 )
  429. ( "\\gets" calcFunc-assign 51 50 )
  430. ( ":=" calcFunc-assign 51 50 )
  431. ( "::" calcFunc-condition 45 46 )
  432. ( "\\to" calcFunc-evalto 40 41 )
  433. ( "\\to" calcFunc-evalto 40 -1 )
  434. ( "=>" calcFunc-evalto 40 41 )
  435. ( "=>" calcFunc-evalto 40 -1 )))
  436. (put 'tex 'math-function-table
  437. '( ( \\arccos . calcFunc-arccos )
  438. ( \\arcsin . calcFunc-arcsin )
  439. ( \\arctan . calcFunc-arctan )
  440. ( \\arg . calcFunc-arg )
  441. ( \\cos . calcFunc-cos )
  442. ( \\cosh . calcFunc-cosh )
  443. ( \\cot . calcFunc-cot )
  444. ( \\coth . calcFunc-coth )
  445. ( \\csc . calcFunc-csc )
  446. ( \\det . calcFunc-det )
  447. ( \\exp . calcFunc-exp )
  448. ( \\gcd . calcFunc-gcd )
  449. ( \\ln . calcFunc-ln )
  450. ( \\log . calcFunc-log10 )
  451. ( \\max . calcFunc-max )
  452. ( \\min . calcFunc-min )
  453. ( \\sec . calcFunc-sec )
  454. ( \\sin . calcFunc-sin )
  455. ( \\sinh . calcFunc-sinh )
  456. ( \\sqrt . calcFunc-sqrt )
  457. ( \\tan . calcFunc-tan )
  458. ( \\tanh . calcFunc-tanh )
  459. ( \\phi . calcFunc-totient )
  460. ( \\mu . calcFunc-moebius )))
  461. (put 'tex 'math-special-function-table
  462. '((calcFunc-sum . (math-compose-tex-sum "\\sum"))
  463. (calcFunc-prod . (math-compose-tex-sum "\\prod"))
  464. (calcFunc-sqrt . math-compose-tex-sqrt)
  465. (intv . math-compose-tex-intv)))
  466. (put 'tex 'math-variable-table
  467. '(
  468. ;; The Greek letters
  469. ( \\alpha . var-alpha )
  470. ( \\beta . var-beta )
  471. ( \\gamma . var-gamma )
  472. ( \\Gamma . var-Gamma )
  473. ( \\delta . var-delta )
  474. ( \\Delta . var-Delta )
  475. ( \\epsilon . var-epsilon )
  476. ( \\varepsilon . var-varepsilon)
  477. ( \\zeta . var-zeta )
  478. ( \\eta . var-eta )
  479. ( \\theta . var-theta )
  480. ( \\vartheta . var-vartheta )
  481. ( \\Theta . var-Theta )
  482. ( \\iota . var-iota )
  483. ( \\kappa . var-kappa )
  484. ( \\lambda . var-lambda )
  485. ( \\Lambda . var-Lambda )
  486. ( \\mu . var-mu )
  487. ( \\nu . var-nu )
  488. ( \\xi . var-xi )
  489. ( \\Xi . var-Xi )
  490. ( \\pi . var-pi )
  491. ( \\varpi . var-varpi )
  492. ( \\Pi . var-Pi )
  493. ( \\rho . var-rho )
  494. ( \\varrho . var-varrho )
  495. ( \\sigma . var-sigma )
  496. ( \\sigma . var-varsigma )
  497. ( \\Sigma . var-Sigma )
  498. ( \\tau . var-tau )
  499. ( \\upsilon . var-upsilon )
  500. ( \\Upsilon . var-Upsilon )
  501. ( \\phi . var-phi )
  502. ( \\varphi . var-varphi )
  503. ( \\Phi . var-Phi )
  504. ( \\chi . var-chi )
  505. ( \\psi . var-psi )
  506. ( \\Psi . var-Psi )
  507. ( \\omega . var-omega )
  508. ( \\Omega . var-Omega )
  509. ;; Units
  510. ( pt . var-texpt )
  511. ( pc . var-texpc )
  512. ( bp . var-texbp )
  513. ( dd . var-texdd )
  514. ( cc . var-texcc )
  515. ( sp . var-texsp )
  516. ( pint . var-pt )
  517. ( parsec . var-pc)
  518. ;; Others
  519. ( \\ell . var-ell )
  520. ( \\infty . var-inf )
  521. ( \\infty . var-uinf )
  522. ( \\sum . (math-parse-tex-sum calcFunc-sum) )
  523. ( \\prod . (math-parse-tex-sum calcFunc-prod) )))
  524. (put 'tex 'math-punc-table
  525. '((?\{ . ?\()
  526. (?\} . ?\))
  527. (?\& . ?\,)))
  528. (put 'tex 'math-complex-format 'i)
  529. (put 'tex 'math-input-filter 'math-tex-input-filter)
  530. (put 'tex 'math-matrix-formatter
  531. (function
  532. (lambda (a)
  533. (if (and (integerp calc-language-option)
  534. (or (= calc-language-option 0)
  535. (> calc-language-option 1)
  536. (< calc-language-option -1)))
  537. (append '(vleft 0 "\\matrix{")
  538. (math-compose-tex-matrix (cdr a))
  539. '("}"))
  540. (append '(horiz "\\matrix{ ")
  541. (math-compose-tex-matrix (cdr a))
  542. '(" }"))))))
  543. (put 'tex 'math-var-formatter 'math-compose-tex-var)
  544. (put 'tex 'math-func-formatter 'math-compose-tex-func)
  545. (put 'tex 'math-dots "\\ldots")
  546. (put 'tex 'math-big-parens '("\\left( " . " \\right)"))
  547. (put 'tex 'math-evalto '("\\evalto " . " \\to "))
  548. (defconst math-tex-ignore-words
  549. '( ("\\hbox") ("\\mbox") ("\\text") ("\\left") ("\\right")
  550. ("\\,") ("\\>") ("\\:") ("\\;") ("\\!") ("\\ ")
  551. ("\\quad") ("\\qquad") ("\\hfil") ("\\hfill")
  552. ("\\displaystyle") ("\\textstyle") ("\\dsize") ("\\tsize")
  553. ("\\scriptstyle") ("\\scriptscriptstyle") ("\\ssize") ("\\sssize")
  554. ("\\rm") ("\\bf") ("\\it") ("\\sl")
  555. ("\\roman") ("\\bold") ("\\italic") ("\\slanted")
  556. ("\\cal") ("\\mit") ("\\Cal") ("\\Bbb") ("\\frak") ("\\goth")
  557. ("\\evalto")
  558. ("\\matrix" mat) ("\\bmatrix" mat) ("\\pmatrix" mat)
  559. ("\\begin" begenv)
  560. ("\\cr" punc ";") ("\\\\" punc ";") ("\\*" punc "*")
  561. ("\\{" punc "[") ("\\}" punc "]")))
  562. (defconst math-latex-ignore-words
  563. (append math-tex-ignore-words
  564. '(("\\begin" begenv))))
  565. (put 'tex 'math-lang-read-symbol
  566. '((?\\
  567. (< math-exp-pos (1- (length math-exp-str)))
  568. (progn
  569. (or (string-match "\\\\hbox *{\\([a-zA-Zα-ωΑ-Ω0-9]+\\)}"
  570. math-exp-str math-exp-pos)
  571. (string-match "\\(\\\\\\([a-zA-Zα-ωΑ-Ω]+\\|[^a-zA-Zα-ωΑ-Ω]\\)\\)"
  572. math-exp-str math-exp-pos))
  573. (setq math-exp-token 'symbol
  574. math-exp-pos (match-end 0)
  575. math-expr-data (math-restore-dashes
  576. (math-match-substring math-exp-str 1)))
  577. (let ((code (assoc math-expr-data math-latex-ignore-words)))
  578. (cond ((null code))
  579. ((null (cdr code))
  580. (math-read-token))
  581. ((eq (nth 1 code) 'punc)
  582. (setq math-exp-token 'punc
  583. math-expr-data (nth 2 code)))
  584. ((and (eq (nth 1 code) 'mat)
  585. (string-match " *{" math-exp-str math-exp-pos))
  586. (setq math-exp-pos (match-end 0)
  587. math-exp-token 'punc
  588. math-expr-data "[")
  589. (let ((right (string-match "}" math-exp-str math-exp-pos)))
  590. (and right
  591. (setq math-exp-str (copy-sequence math-exp-str))
  592. (aset math-exp-str right ?\]))))))))))
  593. (defun math-compose-tex-matrix (a &optional ltx)
  594. (if (cdr a)
  595. (cons (append (math-compose-vector (cdr (car a)) " & " 0)
  596. (if ltx '(" \\\\ ") '(" \\cr ")))
  597. (math-compose-tex-matrix (cdr a) ltx))
  598. (list (math-compose-vector (cdr (car a)) " & " 0))))
  599. (defun math-compose-tex-sum (a fn)
  600. (cond
  601. ((nth 4 a)
  602. (list 'horiz (nth 1 fn)
  603. "_{" (math-compose-expr (nth 2 a) 0)
  604. "=" (math-compose-expr (nth 3 a) 0)
  605. "}^{" (math-compose-expr (nth 4 a) 0)
  606. "}{" (math-compose-expr (nth 1 a) 0) "}"))
  607. ((nth 3 a)
  608. (list 'horiz (nth 1 fn)
  609. "_{" (math-compose-expr (nth 2 a) 0)
  610. "=" (math-compose-expr (nth 3 a) 0)
  611. "}{" (math-compose-expr (nth 1 a) 0) "}"))
  612. (t
  613. (list 'horiz (nth 1 fn)
  614. "_{" (math-compose-expr (nth 2 a) 0)
  615. "}{" (math-compose-expr (nth 1 a) 0) "}"))))
  616. (defun math-parse-tex-sum (f val)
  617. (let (low high save)
  618. (or (equal math-expr-data "_") (throw 'syntax "Expected `_'"))
  619. (math-read-token)
  620. (setq save math-exp-old-pos)
  621. (setq low (math-read-factor))
  622. (or (eq (car-safe low) 'calcFunc-eq)
  623. (progn
  624. (setq math-exp-old-pos (1+ save))
  625. (throw 'syntax "Expected equation")))
  626. (or (equal math-expr-data "^") (throw 'syntax "Expected `^'"))
  627. (math-read-token)
  628. (setq high (math-read-factor))
  629. (list (nth 2 f) (math-read-factor) (nth 1 low) (nth 2 low) high)))
  630. (defun math-tex-input-filter (str) ; allow parsing of 123\,456\,789.
  631. (while (string-match "[0-9]\\\\,[0-9]" str)
  632. (setq str (concat (substring str 0 (1+ (match-beginning 0)))
  633. (substring str (1- (match-end 0))))))
  634. str)
  635. (defun math-compose-tex-sqrt (a)
  636. (list 'horiz
  637. "\\sqrt{"
  638. (math-compose-expr (nth 1 a) 0)
  639. "}"))
  640. (defun math-compose-tex-intv (a)
  641. (list 'horiz
  642. (if (memq (nth 1 a) '(0 1)) "(" "[")
  643. (math-compose-expr (nth 2 a) 0)
  644. " \\ldots "
  645. (math-compose-expr (nth 3 a) 0)
  646. (if (memq (nth 1 a) '(0 2)) ")" "]")))
  647. (defun math-compose-tex-var (a prec)
  648. (if (and calc-language-option
  649. (not (= calc-language-option 0))
  650. (string-match "\\`[a-zA-Zα-ωΑ-Ω][a-zA-Zα-ωΑ-Ω0-9]+\\'"
  651. (symbol-name (nth 1 a))))
  652. (if (eq calc-language 'latex)
  653. (format "\\text{%s}" (symbol-name (nth 1 a)))
  654. (format "\\hbox{%s}" (symbol-name (nth 1 a))))
  655. (math-compose-var a)))
  656. (defun math-compose-tex-func (func a)
  657. (let (left right)
  658. (if (and calc-language-option
  659. (not (= calc-language-option 0))
  660. (string-match "\\`[a-zA-Zα-ωΑ-Ω][a-zA-Zα-ωΑ-Ω0-9]+\\'" func))
  661. (if (< (prefix-numeric-value calc-language-option) 0)
  662. (setq func (format "\\%s" func))
  663. (setq func (if (eq calc-language 'latex)
  664. (format "\\text{%s}" func)
  665. (format "\\hbox{%s}" func)))))
  666. (cond ((or (> (length a) 2)
  667. (not (math-tex-expr-is-flat (nth 1 a))))
  668. (setq left "\\left( "
  669. right " \\right)"))
  670. ((and (eq (aref func 0) ?\\)
  671. (not (or
  672. (string-match "\\hbox{" func)
  673. (string-match "\\text{" func)))
  674. (= (length a) 2)
  675. (or (Math-realp (nth 1 a))
  676. (memq (car (nth 1 a)) '(var *))))
  677. (setq left "{" right "}"))
  678. (t (setq left calc-function-open
  679. right calc-function-close)))
  680. (list 'horiz func
  681. left
  682. (math-compose-vector (cdr a) ", " 0)
  683. right)))
  684. (put 'latex 'math-oper-table
  685. (append (get 'tex 'math-oper-table)
  686. '(( "\\Hat" calcFunc-Hat -1 950 )
  687. ( "\\Check" calcFunc-Check -1 950 )
  688. ( "\\Tilde" calcFunc-Tilde -1 950 )
  689. ( "\\Acute" calcFunc-Acute -1 950 )
  690. ( "\\Grave" calcFunc-Grave -1 950 )
  691. ( "\\Dot" calcFunc-Dot -1 950 )
  692. ( "\\Ddot" calcFunc-Dotdot -1 950 )
  693. ( "\\Breve" calcFunc-Breve -1 950 )
  694. ( "\\Bar" calcFunc-Bar -1 950 )
  695. ( "\\Vec" calcFunc-VEC -1 950 )
  696. ( "\\dddot" calcFunc-dddot -1 950 )
  697. ( "\\ddddot" calcFunc-ddddot -1 950 )
  698. ( "\\div" / 170 171 )
  699. ( "\\le" calcFunc-leq 160 161 )
  700. ( "\\leqq" calcFunc-leq 160 161 )
  701. ( "\\leqsland" calcFunc-leq 160 161 )
  702. ( "\\ge" calcFunc-geq 160 161 )
  703. ( "\\geqq" calcFunc-geq 160 161 )
  704. ( "\\geqslant" calcFunc-geq 160 161 )
  705. ( "=" calcFunc-eq 160 161 )
  706. ( "\\neq" calcFunc-neq 160 161 )
  707. ( "\\ne" calcFunc-neq 160 161 )
  708. ( "\\lnot" calcFunc-lnot -1 121 )
  709. ( "\\land" calcFunc-land 110 111 )
  710. ( "\\lor" calcFunc-lor 100 101 )
  711. ( "?" (math-read-if) 91 90 )
  712. ( "!!!" calcFunc-pnot -1 85 )
  713. ( "&&&" calcFunc-pand 80 81 )
  714. ( "|||" calcFunc-por 75 76 )
  715. ( "\\gets" calcFunc-assign 51 50 )
  716. ( ":=" calcFunc-assign 51 50 )
  717. ( "::" calcFunc-condition 45 46 )
  718. ( "\\to" calcFunc-evalto 40 41 )
  719. ( "\\to" calcFunc-evalto 40 -1 )
  720. ( "=>" calcFunc-evalto 40 41 )
  721. ( "=>" calcFunc-evalto 40 -1 ))))
  722. (put 'latex 'math-function-table
  723. (append
  724. (get 'tex 'math-function-table)
  725. '(( \\frac . (math-latex-parse-frac))
  726. ( \\tfrac . (math-latex-parse-frac))
  727. ( \\dfrac . (math-latex-parse-frac))
  728. ( \\binom . (math-latex-parse-two-args calcFunc-choose))
  729. ( \\tbinom . (math-latex-parse-two-args calcFunc-choose))
  730. ( \\dbinom . (math-latex-parse-two-args calcFunc-choose))
  731. ( \\phi . calcFunc-totient )
  732. ( \\mu . calcFunc-moebius ))))
  733. (put 'latex 'math-special-function-table
  734. '((/ . (math-compose-latex-frac "\\frac"))
  735. (calcFunc-choose . (math-compose-latex-frac "\\binom"))
  736. (calcFunc-sum . (math-compose-tex-sum "\\sum"))
  737. (calcFunc-prod . (math-compose-tex-sum "\\prod"))
  738. (calcFunc-sqrt . math-compose-tex-sqrt)
  739. (intv . math-compose-tex-intv)))
  740. (put 'latex 'math-variable-table
  741. (get 'tex 'math-variable-table))
  742. (put 'latex 'math-punc-table
  743. '((?\{ . ?\()
  744. (?\} . ?\))
  745. (?\& . ?\,)))
  746. (put 'latex 'math-complex-format 'i)
  747. (put 'latex 'math-matrix-formatter
  748. (function
  749. (lambda (a)
  750. (if (and (integerp calc-language-option)
  751. (or (= calc-language-option 0)
  752. (> calc-language-option 1)
  753. (< calc-language-option -1)))
  754. (append '(vleft 0 "\\begin{pmatrix}")
  755. (math-compose-tex-matrix (cdr a) t)
  756. '("\\end{pmatrix}"))
  757. (append '(horiz "\\begin{pmatrix} ")
  758. (math-compose-tex-matrix (cdr a) t)
  759. '(" \\end{pmatrix}"))))))
  760. (put 'latex 'math-var-formatter 'math-compose-tex-var)
  761. (put 'latex 'math-func-formatter 'math-compose-tex-func)
  762. (put 'latex 'math-dots "\\ldots")
  763. (put 'latex 'math-big-parens '("\\left( " . " \\right)"))
  764. (put 'latex 'math-evalto '("\\evalto " . " \\to "))
  765. (put 'latex 'math-lang-read-symbol
  766. '((?\\
  767. (< math-exp-pos (1- (length math-exp-str)))
  768. (progn
  769. (or (string-match "\\\\hbox *{\\([a-zA-Zα-ωΑ-Ω0-9]+\\)}"
  770. math-exp-str math-exp-pos)
  771. (string-match "\\\\text *{\\([a-zA-Zα-ωΑ-Ω0-9]+\\)}"
  772. math-exp-str math-exp-pos)
  773. (string-match "\\(\\\\\\([a-zA-Zα-ωΑ-Ω]+\\|[^a-zA-Zα-ωΑ-Ω]\\)\\)"
  774. math-exp-str math-exp-pos))
  775. (setq math-exp-token 'symbol
  776. math-exp-pos (match-end 0)
  777. math-expr-data (math-restore-dashes
  778. (math-match-substring math-exp-str 1)))
  779. (let ((code (assoc math-expr-data math-tex-ignore-words))
  780. envname)
  781. (cond ((null code))
  782. ((null (cdr code))
  783. (math-read-token))
  784. ((eq (nth 1 code) 'punc)
  785. (setq math-exp-token 'punc
  786. math-expr-data (nth 2 code)))
  787. ((and (eq (nth 1 code) 'begenv)
  788. (string-match " *{\\([^}]*\\)}" math-exp-str math-exp-pos))
  789. (setq math-exp-pos (match-end 0)
  790. envname (match-string 1 math-exp-str)
  791. math-exp-token 'punc
  792. math-expr-data "[")
  793. (cond ((or (string= envname "matrix")
  794. (string= envname "bmatrix")
  795. (string= envname "smallmatrix")
  796. (string= envname "pmatrix"))
  797. (if (string-match (concat "\\\\end{" envname "}")
  798. math-exp-str math-exp-pos)
  799. (setq math-exp-str
  800. (replace-match "]" t t math-exp-str))
  801. (error "%s" (concat "No closing \\end{" envname "}"))))))
  802. ((and (eq (nth 1 code) 'mat)
  803. (string-match " *{" math-exp-str math-exp-pos))
  804. (setq math-exp-pos (match-end 0)
  805. math-exp-token 'punc
  806. math-expr-data "[")
  807. (let ((right (string-match "}" math-exp-str math-exp-pos)))
  808. (and right
  809. (setq math-exp-str (copy-sequence math-exp-str))
  810. (aset math-exp-str right ?\]))))))))))
  811. (defun math-latex-parse-frac (f val)
  812. (let (numer denom)
  813. (setq numer (car (math-read-expr-list)))
  814. (math-read-token)
  815. (setq denom (math-read-factor))
  816. (if (and (Math-num-integerp numer)
  817. (Math-num-integerp denom))
  818. (list 'frac numer denom)
  819. (list '/ numer denom))))
  820. (defun math-latex-parse-two-args (f val)
  821. (let (first second)
  822. (setq first (car (math-read-expr-list)))
  823. (math-read-token)
  824. (setq second (math-read-factor))
  825. (list (nth 2 f) first second)))
  826. (defun math-compose-latex-frac (a fn)
  827. (list 'horiz (nth 1 fn) "{" (math-compose-expr (nth 1 a) -1)
  828. "}{"
  829. (math-compose-expr (nth 2 a) -1)
  830. "}"))
  831. (put 'latex 'math-input-filter 'math-tex-input-filter)
  832. (defun calc-eqn-language (n)
  833. (interactive "P")
  834. (calc-wrapper
  835. (calc-set-language 'eqn)
  836. (message "Eqn language mode")))
  837. (put 'eqn 'math-oper-table
  838. '( ( "prime" (math-parse-eqn-prime) 950 -1 )
  839. ( "prime" calcFunc-Prime 950 -1 )
  840. ( "dot" calcFunc-dot 950 -1 )
  841. ( "dotdot" calcFunc-dotdot 950 -1 )
  842. ( "hat" calcFunc-hat 950 -1 )
  843. ( "tilde" calcFunc-tilde 950 -1 )
  844. ( "vec" calcFunc-Vec 950 -1 )
  845. ( "dyad" calcFunc-dyad 950 -1 )
  846. ( "bar" calcFunc-bar 950 -1 )
  847. ( "under" calcFunc-under 950 -1 )
  848. ( "sub" calcFunc-subscr 931 930 )
  849. ( "sup" ^ 921 920 )
  850. ( "sqrt" calcFunc-sqrt -1 910 )
  851. ( "over" / 900 901 )
  852. ( "u|" calcFunc-abs -1 0 )
  853. ( "|" closing 0 -1 )
  854. ( "left floor" calcFunc-floor -1 0 )
  855. ( "right floor" closing 0 -1 )
  856. ( "left ceil" calcFunc-ceil -1 0 )
  857. ( "right ceil" closing 0 -1 )
  858. ( "+-" sdev 300 300 )
  859. ( "!" calcFunc-fact 210 -1 )
  860. ( "u+" ident -1 197 )
  861. ( "u-" neg -1 197 )
  862. ( "times" * 191 190 )
  863. ( "*" * 191 190 )
  864. ( "2x" * 191 190 )
  865. ( "/" / 180 181 )
  866. ( "%" % 180 181 )
  867. ( "+" + 170 171 )
  868. ( "-" - 170 171 )
  869. ( "<" calcFunc-lt 160 161 )
  870. ( ">" calcFunc-gt 160 161 )
  871. ( "<=" calcFunc-leq 160 161 )
  872. ( ">=" calcFunc-geq 160 161 )
  873. ( "=" calcFunc-eq 160 161 )
  874. ( "==" calcFunc-eq 160 161 )
  875. ( "!=" calcFunc-neq 160 161 )
  876. ( "u!" calcFunc-lnot -1 121 )
  877. ( "&&" calcFunc-land 110 111 )
  878. ( "||" calcFunc-lor 100 101 )
  879. ( "?" (math-read-if) 91 90 )
  880. ( "!!!" calcFunc-pnot -1 85 )
  881. ( "&&&" calcFunc-pand 80 81 )
  882. ( "|||" calcFunc-por 75 76 )
  883. ( "<-" calcFunc-assign 51 50 )
  884. ( ":=" calcFunc-assign 51 50 )
  885. ( "::" calcFunc-condition 45 46 )
  886. ( "->" calcFunc-evalto 40 41 )
  887. ( "->" calcFunc-evalto 40 -1 )
  888. ( "=>" calcFunc-evalto 40 41 )
  889. ( "=>" calcFunc-evalto 40 -1 )))
  890. (put 'eqn 'math-function-table
  891. '( ( arc\ cos . calcFunc-arccos )
  892. ( arc\ cosh . calcFunc-arccosh )
  893. ( arc\ sin . calcFunc-arcsin )
  894. ( arc\ sinh . calcFunc-arcsinh )
  895. ( arc\ tan . calcFunc-arctan )
  896. ( arc\ tanh . calcFunc-arctanh )
  897. ( GAMMA . calcFunc-gamma )
  898. ( phi . calcFunc-totient )
  899. ( mu . calcFunc-moebius )
  900. ( matrix . (math-parse-eqn-matrix) )))
  901. (put 'eqn 'math-special-function-table
  902. '((intv . math-compose-eqn-intv)))
  903. (put 'eqn 'math-punc-table
  904. '((?\{ . ?\()
  905. (?\} . ?\))))
  906. (put 'eqn 'math-variable-table
  907. '( ( inf . var-uinf )))
  908. (put 'eqn 'math-complex-format 'i)
  909. (put 'eqn 'math-big-parens '("{left ( " . " right )}"))
  910. (put 'eqn 'math-evalto '("evalto " . " -> "))
  911. (put 'eqn 'math-matrix-formatter
  912. (function
  913. (lambda (a)
  914. (append '(horiz "matrix { ")
  915. (math-compose-eqn-matrix
  916. (cdr (math-transpose a)))
  917. '("}")))))
  918. (put 'eqn 'math-var-formatter
  919. (function
  920. (lambda (a prec)
  921. (let (v)
  922. (if (and math-compose-hash-args
  923. (let ((p calc-arg-values))
  924. (setq v 1)
  925. (while (and p (not (equal (car p) a)))
  926. (setq p (and (eq math-compose-hash-args t) (cdr p))
  927. v (1+ v)))
  928. p))
  929. (if (eq math-compose-hash-args 1)
  930. "#"
  931. (format "#%d" v))
  932. (if (string-match ".'\\'" (symbol-name (nth 2 a)))
  933. (math-compose-expr
  934. (list 'calcFunc-Prime
  935. (list
  936. 'var
  937. (intern (substring (symbol-name (nth 1 a)) 0 -1))
  938. (intern (substring (symbol-name (nth 2 a)) 0 -1))))
  939. prec)
  940. (symbol-name (nth 1 a))))))))
  941. (defconst math-eqn-special-funcs
  942. '( calcFunc-log
  943. calcFunc-ln calcFunc-exp
  944. calcFunc-sin calcFunc-cos calcFunc-tan
  945. calcFunc-sec calcFunc-csc calcFunc-cot
  946. calcFunc-sinh calcFunc-cosh calcFunc-tanh
  947. calcFunc-sech calcFunc-csch calcFunc-coth
  948. calcFunc-arcsin calcFunc-arccos calcFunc-arctan
  949. calcFunc-arcsinh calcFunc-arccosh calcFunc-arctanh))
  950. (put 'eqn 'math-func-formatter
  951. (function
  952. (lambda (func a)
  953. (let (left right)
  954. (if (string-match "[^']'+\\'" func)
  955. (let ((n (- (length func) (match-beginning 0) 1)))
  956. (setq func (substring func 0 (- n)))
  957. (while (>= (setq n (1- n)) 0)
  958. (setq func (concat func " prime")))))
  959. (cond ((or (> (length a) 2)
  960. (not (math-tex-expr-is-flat (nth 1 a))))
  961. (setq left "{left ( "
  962. right " right )}"))
  963. ((and
  964. (memq (car a) math-eqn-special-funcs)
  965. (= (length a) 2)
  966. (or (Math-realp (nth 1 a))
  967. (memq (car (nth 1 a)) '(var *))))
  968. (setq left "~{" right "}"))
  969. (t
  970. (setq left " ( "
  971. right " )")))
  972. (list 'horiz func left
  973. (math-compose-vector (cdr a) " , " 0)
  974. right)))))
  975. (put 'eqn 'math-lang-read-symbol
  976. '((?\"
  977. (string-match "\\(\"\\([^\"\\]\\|\\\\.\\)*\\)\\(\"\\|\\'\\)"
  978. math-exp-str math-exp-pos)
  979. (progn
  980. (setq math-exp-str (copy-sequence math-exp-str))
  981. (aset math-exp-str (match-beginning 1) ?\{)
  982. (if (< (match-end 1) (length math-exp-str))
  983. (aset math-exp-str (match-end 1) ?\}))
  984. (math-read-token)))))
  985. (defconst math-eqn-ignore-words
  986. '( ("roman") ("bold") ("italic") ("mark") ("lineup") ("evalto")
  987. ("left" ("floor") ("ceil"))
  988. ("right" ("floor") ("ceil"))
  989. ("arc" ("sin") ("cos") ("tan") ("sinh") ("cosh") ("tanh"))
  990. ("size" n) ("font" n) ("fwd" n) ("back" n) ("up" n) ("down" n)
  991. ("above" punc ",")))
  992. (put 'eqn 'math-lang-adjust-words
  993. (function
  994. (lambda ()
  995. (let ((code (assoc math-expr-data math-eqn-ignore-words)))
  996. (cond ((null code))
  997. ((null (cdr code))
  998. (math-read-token))
  999. ((consp (nth 1 code))
  1000. (math-read-token)
  1001. (if (assoc math-expr-data (cdr code))
  1002. (setq math-expr-data (format "%s %s"
  1003. (car code) math-expr-data))))
  1004. ((eq (nth 1 code) 'punc)
  1005. (setq math-exp-token 'punc
  1006. math-expr-data (nth 2 code)))
  1007. (t
  1008. (math-read-token)
  1009. (math-read-token)))))))
  1010. (put 'eqn 'math-lang-read
  1011. '((eq (string-match "->\\|<-\\|+-\\|\\\\dots\\|~\\|\\^"
  1012. math-exp-str math-exp-pos)
  1013. math-exp-pos)
  1014. (progn
  1015. (setq math-exp-token 'punc
  1016. math-expr-data (math-match-substring math-exp-str 0)
  1017. math-exp-pos (match-end 0))
  1018. (and (eq (string-match "\\\\dots\\." math-exp-str math-exp-pos)
  1019. math-exp-pos)
  1020. (setq math-exp-pos (match-end 0)))
  1021. (if (memq (aref math-expr-data 0) '(?~ ?^))
  1022. (math-read-token)))))
  1023. (defun math-compose-eqn-matrix (a)
  1024. (if a
  1025. (cons
  1026. (cond ((eq calc-matrix-just 'right) "rcol ")
  1027. ((eq calc-matrix-just 'center) "ccol ")
  1028. (t "lcol "))
  1029. (cons
  1030. (list 'break math-compose-level)
  1031. (cons
  1032. "{ "
  1033. (cons
  1034. (let ((math-compose-level (1+ math-compose-level)))
  1035. (math-compose-vector (cdr (car a)) " above " 1000))
  1036. (cons
  1037. " } "
  1038. (math-compose-eqn-matrix (cdr a)))))))
  1039. nil))
  1040. (defun math-parse-eqn-matrix (f sym)
  1041. (let ((vec nil))
  1042. (while (assoc math-expr-data '(("ccol") ("lcol") ("rcol")))
  1043. (math-read-token)
  1044. (or (equal math-expr-data calc-function-open)
  1045. (throw 'syntax "Expected `{'"))
  1046. (math-read-token)
  1047. (setq vec (cons (cons 'vec (math-read-expr-list)) vec))
  1048. (or (equal math-expr-data calc-function-close)
  1049. (throw 'syntax "Expected `}'"))
  1050. (math-read-token))
  1051. (or (equal math-expr-data calc-function-close)
  1052. (throw 'syntax "Expected `}'"))
  1053. (math-read-token)
  1054. (math-transpose (cons 'vec (nreverse vec)))))
  1055. (defun math-parse-eqn-prime (x sym)
  1056. (if (eq (car-safe x) 'var)
  1057. (if (equal math-expr-data calc-function-open)
  1058. (progn
  1059. (math-read-token)
  1060. (let ((args (if (or (equal math-expr-data calc-function-close)
  1061. (eq math-exp-token 'end))
  1062. nil
  1063. (math-read-expr-list))))
  1064. (if (not (or (equal math-expr-data calc-function-close)
  1065. (eq math-exp-token 'end)))
  1066. (throw 'syntax "Expected `)'"))
  1067. (math-read-token)
  1068. (cons (intern (format "calcFunc-%s'" (nth 1 x))) args)))
  1069. (list 'var
  1070. (intern (concat (symbol-name (nth 1 x)) "'"))
  1071. (intern (concat (symbol-name (nth 2 x)) "'"))))
  1072. (list 'calcFunc-Prime x)))
  1073. (defun math-compose-eqn-intv (a)
  1074. (list 'horiz
  1075. (if (memq (nth 1 a) '(0 1)) "(" "[")
  1076. (math-compose-expr (nth 2 a) 0)
  1077. " ... "
  1078. (math-compose-expr (nth 3 a) 0)
  1079. (if (memq (nth 1 a) '(0 2)) ")" "]")))
  1080. ;;; Yacas
  1081. (defun calc-yacas-language ()
  1082. "Change the Calc language to be Yacas-like."
  1083. (interactive)
  1084. (calc-wrapper
  1085. (calc-set-language 'yacas)
  1086. (message "Yacas language mode")))
  1087. (put 'yacas 'math-vector-brackets "{}")
  1088. (put 'yacas 'math-complex-format 'I)
  1089. (add-to-list 'calc-lang-brackets-are-subscripts 'yacas)
  1090. (put 'yacas 'math-variable-table
  1091. '(( Infinity . var-inf)
  1092. ( Infinity . var-uinf)
  1093. ( Undefined . var-nan)
  1094. ( Pi . var-pi)
  1095. ( E . var-e) ;; Not really in Yacas
  1096. ( GoldenRatio . var-phi)
  1097. ( Gamma . var-gamma)))
  1098. (put 'yacas 'math-parse-table
  1099. '((("Deriv(" 0 ")" 0)
  1100. calcFunc-deriv (var ArgB var-ArgB) (var ArgA var-ArgA))
  1101. (("D(" 0 ")" 0)
  1102. calcFunc-deriv (var ArgB var-ArgB) (var ArgA var-ArgA))
  1103. (("Integrate(" 0 ")" 0)
  1104. calcFunc-integ (var ArgB var-ArgB)(var ArgA var-ArgA))
  1105. (("Integrate(" 0 "," 0 "," 0 ")" 0)
  1106. calcFunc-integ (var ArgD var-ArgD) (var ArgA var-ArgA)
  1107. (var ArgB var-ArgB) (var ArgC var-ArgC))
  1108. (("Subst(" 0 "," 0 ")" 0)
  1109. calcFunc-subst (var ArgC var-ArgC) (var ArgA var-ArgA)
  1110. (var ArgB var-ArgB))
  1111. (("Taylor(" 0 "," 0 "," 0 ")" 0)
  1112. calcFunc-taylor (var ArgD var-ArgD)
  1113. (calcFunc-eq (var ArgA var-ArgA) (var ArgB var-ArgB))
  1114. (var ArgC var-ArgC))))
  1115. (put 'yacas 'math-oper-table
  1116. '(("+" + 30 30)
  1117. ("-" - 30 60)
  1118. ("*" * 60 60)
  1119. ("/" / 70 70)
  1120. ("u-" neg -1 60)
  1121. ("^" ^ 80 80)
  1122. ("u+" ident -1 30)
  1123. ("<<" calcFunc-lsh 80 80)
  1124. (">>" calcFunc-rsh 80 80)
  1125. ("!" calcFunc-fact 80 -1)
  1126. ("!!" calcFunc-dfact 80 -1)
  1127. ("X" calcFunc-cross 70 70)
  1128. ("=" calcFunc-eq 10 10)
  1129. ("!=" calcFunc-neq 10 10)
  1130. ("<" calcFunc-lt 10 10)
  1131. (">" calcFunc-gt 10 10)
  1132. ("<=" calcFunc-leq 10 10)
  1133. (">=" calcFunc-geq 10 10)
  1134. ("And" calcFunc-land 5 5)
  1135. ("Or" calcFunc-or 4 4)
  1136. ("Not" calcFunc-lnot -1 3)
  1137. (":=" calcFunc-assign 1 1)))
  1138. (put 'yacas 'math-function-table
  1139. '(( Div . calcFunc-idiv)
  1140. ( Mod . calcFunc-mod)
  1141. ( Abs . calcFunc-abs)
  1142. ( Sign . calcFunc-sign)
  1143. ( Sqrt . calcFunc-sqrt)
  1144. ( Max . calcFunc-max)
  1145. ( Min . calcFunc-min)
  1146. ( Floor . calcFunc-floor)
  1147. ( Ceil . calcFunc-ceil)
  1148. ( Round . calcFunc-round)
  1149. ( Conjugate . calcFunc-conj)
  1150. ( Arg . calcFunc-arg)
  1151. ( Re . calcFunc-re)
  1152. ( Im . calcFunc-im)
  1153. ( Rationalize . calcFunc-pfrac)
  1154. ( Sin . calcFunc-sin)
  1155. ( Cos . calcFunc-cos)
  1156. ( Tan . calcFunc-tan)
  1157. ( Sec . calcFunc-sec)
  1158. ( Csc . calcFunc-csc)
  1159. ( Cot . calcFunc-cot)
  1160. ( ArcSin . calcFunc-arcsin)
  1161. ( ArcCos . calcFunc-arccos)
  1162. ( ArcTan . calcFunc-arctan)
  1163. ( Sinh . calcFunc-sinh)
  1164. ( Cosh . calcFunc-cosh)
  1165. ( Tanh . calcFunc-tanh)
  1166. ( Sech . calcFunc-sech)
  1167. ( Csch . calcFunc-csch)
  1168. ( Coth . calcFunc-coth)
  1169. ( ArcSinh . calcFunc-arcsinh)
  1170. ( ArcCosh . calcFunc-arccosh)
  1171. ( ArcTanh . calcFunc-arctanh)
  1172. ( Ln . calcFunc-ln)
  1173. ( Exp . calcFunc-exp)
  1174. ( Gamma . calcFunc-gamma)
  1175. ( Gcd . calcFunc-gcd)
  1176. ( Lcm . calcFunc-lcm)
  1177. ( Bin . calcFunc-choose)
  1178. ( Bernoulli . calcFunc-bern)
  1179. ( Euler . calcFunc-euler)
  1180. ( StirlingNumber1 . calcFunc-stir1)
  1181. ( StirlingNumber2 . calcFunc-stir2)
  1182. ( IsPrime . calcFunc-prime)
  1183. ( Factors . calcFunc-prfac)
  1184. ( NextPrime . calcFunc-nextprime)
  1185. ( Moebius . calcFunc-moebius)
  1186. ( Random . calcFunc-random)
  1187. ( Concat . calcFunc-vconcat)
  1188. ( Head . calcFunc-head)
  1189. ( Tail . calcFunc-tail)
  1190. ( Length . calcFunc-vlen)
  1191. ( Reverse . calcFunc-rev)
  1192. ( CrossProduct . calcFunc-cross)
  1193. ( Dot . calcFunc-mul)
  1194. ( DiagonalMatrix . calcFunc-diag)
  1195. ( Transpose . calcFunc-trn)
  1196. ( Inverse . calcFunc-inv)
  1197. ( Determinant . calcFunc-det)
  1198. ( Trace . calcFunc-tr)
  1199. ( RemoveDuplicates . calcFunc-rdup)
  1200. ( Union . calcFunc-vunion)
  1201. ( Intersection . calcFunc-vint)
  1202. ( Difference . calcFunc-vdiff)
  1203. ( Apply . calcFunc-apply)
  1204. ( Map . calcFunc-map)
  1205. ( Simplify . calcFunc-simplify)
  1206. ( ExpandBrackets . calcFunc-expand)
  1207. ( Solve . calcFunc-solve)
  1208. ( Degree . calcFunc-pdeg)
  1209. ( If . calcFunc-if)
  1210. ( Contains . (math-lang-switch-args calcFunc-in))
  1211. ( Sum . (math-yacas-parse-Sum calcFunc-sum))
  1212. ( Factorize . (math-yacas-parse-Sum calcFunc-prod))))
  1213. (put 'yacas 'math-special-function-table
  1214. '(( calcFunc-sum . (math-yacas-compose-sum "Sum"))
  1215. ( calcFunc-prod . (math-yacas-compose-sum "Factorize"))
  1216. ( calcFunc-deriv . (math-yacas-compose-deriv "Deriv"))
  1217. ( calcFunc-integ . (math-yacas-compose-deriv "Integrate"))
  1218. ( calcFunc-taylor . math-yacas-compose-taylor)
  1219. ( calcFunc-in . (math-lang-compose-switch-args "Contains"))))
  1220. (put 'yacas 'math-compose-subscr
  1221. (function
  1222. (lambda (a)
  1223. (let ((args (cdr (cdr a))))
  1224. (list 'horiz
  1225. (math-compose-expr (nth 1 a) 1000)
  1226. "["
  1227. (math-compose-vector args ", " 0)
  1228. "]")))))
  1229. (defun math-yacas-parse-Sum (f val)
  1230. "Read in the arguments to \"Sum\" in Calc's Yacas mode."
  1231. (let ((args (math-read-expr-list)))
  1232. (math-read-token)
  1233. (list (nth 2 f)
  1234. (nth 3 args)
  1235. (nth 0 args)
  1236. (nth 1 args)
  1237. (nth 2 args))))
  1238. (defun math-yacas-compose-sum (a fn)
  1239. "Compose the \"Sum\" function in Calc's Yacas mode."
  1240. (list 'horiz
  1241. (nth 1 fn)
  1242. "("
  1243. (math-compose-expr (nth 2 a) -1)
  1244. ","
  1245. (math-compose-expr (nth 3 a) -1)
  1246. ","
  1247. (math-compose-expr (nth 4 a) -1)
  1248. ","
  1249. (math-compose-expr (nth 1 a) -1)
  1250. ")"))
  1251. (defun math-yacas-compose-deriv (a fn)
  1252. "Compose the \"Deriv\" function in Calc's Yacas mode."
  1253. (list 'horiz
  1254. (nth 1 fn)
  1255. "("
  1256. (math-compose-expr (nth 2 a) -1)
  1257. (if (not (nth 3 a))
  1258. ")"
  1259. (concat
  1260. ","
  1261. (math-compose-expr (nth 3 a) -1)
  1262. ","
  1263. (math-compose-expr (nth 4 a) -1)
  1264. ")"))
  1265. " "
  1266. (math-compose-expr (nth 1 a) -1)))
  1267. (defun math-yacas-compose-taylor (a)
  1268. "Compose the \"Taylor\" function in Calc's Yacas mode."
  1269. (list 'horiz
  1270. "Taylor("
  1271. (if (eq (car-safe (nth 2 a)) 'calcFunc-eq)
  1272. (concat (math-compose-expr (nth 1 (nth 2 a)) -1)
  1273. ","
  1274. (math-compose-expr (nth 2 (nth 2 a)) -1))
  1275. (concat (math-compose-expr (nth 2 a) -1) ",0"))
  1276. ","
  1277. (math-compose-expr (nth 3 a) -1)
  1278. ") "
  1279. (math-compose-expr (nth 1 a) -1)))
  1280. ;;; Maxima
  1281. (defun calc-maxima-language ()
  1282. "Change the Calc language to be Maxima-like."
  1283. (interactive)
  1284. (calc-wrapper
  1285. (calc-set-language 'maxima)
  1286. (message "Maxima language mode")))
  1287. (put 'maxima 'math-oper-table
  1288. '(("+" + 100 100)
  1289. ("-" - 100 134)
  1290. ("*" * 120 120)
  1291. ("." * 130 129)
  1292. ("/" / 120 120)
  1293. ("u-" neg -1 180)
  1294. ("u+" ident -1 180)
  1295. ("^" ^ 140 139)
  1296. ("**" ^ 140 139)
  1297. ("!" calcFunc-fact 160 -1)
  1298. ("!!" calcFunc-dfact 160 -1)
  1299. ("=" calcFunc-eq 80 80)
  1300. ("#" calcFunc-neq 80 80)
  1301. ("<" calcFunc-lt 80 80)
  1302. (">" calcFunc-gt 80 80)
  1303. ("<=" calcFunc-leq 80 80)
  1304. (">=" calcFunc-geq 80 80)
  1305. ("and" calcFunc-land 65 65)
  1306. ("or" calcFunc-or 60 60)
  1307. ("not" calcFunc-lnot -1 70)
  1308. (":" calcFunc-assign 180 20)))
  1309. (put 'maxima 'math-function-table
  1310. '(( matrix . vec)
  1311. ( abs . calcFunc-abs)
  1312. ( cabs . calcFunc-abs)
  1313. ( signum . calcFunc-sign)
  1314. ( floor . calcFunc-floor)
  1315. ( entier . calcFunc-floor)
  1316. ( fix . calcFunc-floor)
  1317. ( conjugate . calcFunc-conj )
  1318. ( carg . calcFunc-arg)
  1319. ( realpart . calcFunc-re)
  1320. ( imagpart . calcFunc-im)
  1321. ( rationalize . calcFunc-pfrac)
  1322. ( asin . calcFunc-arcsin)
  1323. ( acos . calcFunc-arccos)
  1324. ( atan . calcFunc-arctan)
  1325. ( atan2 . calcFunc-arctan2)
  1326. ( asinh . calcFunc-arcsinh)
  1327. ( acosh . calcFunc-arccosh)
  1328. ( atanh . calcFunc-arctanh)
  1329. ( log . calcFunc-ln)
  1330. ( plog . calcFunc-ln)
  1331. ( bessel_j . calcFunc-besJ)
  1332. ( bessel_y . calcFunc-besY)
  1333. ( factorial . calcFunc-fact)
  1334. ( binomial . calcFunc-choose)
  1335. ( primep . calcFunc-prime)
  1336. ( next_prime . calcFunc-nextprime)
  1337. ( prev_prime . calcFunc-prevprime)
  1338. ( append . calcFunc-vconcat)
  1339. ( rest . calcFunc-tail)
  1340. ( reverse . calcFunc-rev)
  1341. ( innerproduct . calcFunc-mul)
  1342. ( inprod . calcFunc-mul)
  1343. ( row . calcFunc-mrow)
  1344. ( columnvector . calcFunc-mcol)
  1345. ( covect . calcFunc-mcol)
  1346. ( transpose . calcFunc-trn)
  1347. ( invert . calcFunc-inv)
  1348. ( determinant . calcFunc-det)
  1349. ( mattrace . calcFunc-tr)
  1350. ( member . calcFunc-in)
  1351. ( lmax . calcFunc-vmax)
  1352. ( lmin . calcFunc-vmin)
  1353. ( distrib . calcFunc-expand)
  1354. ( partfrac . calcFunc-apart)
  1355. ( rat . calcFunc-nrat)
  1356. ( product . calcFunc-prod)
  1357. ( diff . calcFunc-deriv)
  1358. ( integrate . calcFunc-integ)
  1359. ( quotient . calcFunc-pdiv)
  1360. ( remainder . calcFunc-prem)
  1361. ( divide . calcFunc-pdivrem)
  1362. ( equal . calcFunc-eq)
  1363. ( notequal . calcFunc-neq)
  1364. ( rhs . calcFunc-rmeq)
  1365. ( subst . (math-maxima-parse-subst))
  1366. ( substitute . (math-maxima-parse-subst))
  1367. ( taylor . (math-maxima-parse-taylor))))
  1368. (defun math-maxima-parse-subst (f val)
  1369. "Read in the arguments to \"subst\" in Calc's Maxima mode."
  1370. (let ((args (math-read-expr-list)))
  1371. (math-read-token)
  1372. (list 'calcFunc-subst
  1373. (nth 1 args)
  1374. (nth 2 args)
  1375. (nth 0 args))))
  1376. (defun math-maxima-parse-taylor (f val)
  1377. "Read in the arguments to \"taylor\" in Calc's Maxima mode."
  1378. (let ((args (math-read-expr-list)))
  1379. (math-read-token)
  1380. (list 'calcFunc-taylor
  1381. (nth 0 args)
  1382. (list 'calcFunc-eq
  1383. (nth 1 args)
  1384. (nth 2 args))
  1385. (nth 3 args))))
  1386. (put 'maxima 'math-parse-table
  1387. '((("if" 0 "then" 0 "else" 0)
  1388. calcFunc-if
  1389. (var ArgA var-ArgA)
  1390. (var ArgB var-ArgB)
  1391. (var ArgC var-ArgC))))
  1392. (put 'maxima 'math-special-function-table
  1393. '(( calcFunc-taylor . math-maxima-compose-taylor)
  1394. ( calcFunc-subst . math-maxima-compose-subst)
  1395. ( calcFunc-if . math-maxima-compose-if)))
  1396. (defun math-maxima-compose-taylor (a)
  1397. "Compose the \"taylor\" function in Calc's Maxima mode."
  1398. (list 'horiz
  1399. "taylor("
  1400. (math-compose-expr (nth 1 a) -1)
  1401. ","
  1402. (if (eq (car-safe (nth 2 a)) 'calcFunc-eq)
  1403. (concat (math-compose-expr (nth 1 (nth 2 a)) -1)
  1404. ","
  1405. (math-compose-expr (nth 2 (nth 2 a)) -1))
  1406. (concat (math-compose-expr (nth 2 a) -1) ",0"))
  1407. ","
  1408. (math-compose-expr (nth 3 a) -1)
  1409. ")"))
  1410. (defun math-maxima-compose-subst (a)
  1411. "Compose the \"subst\" function in Calc's Maxima mode."
  1412. (list 'horiz
  1413. "substitute("
  1414. (math-compose-expr (nth 2 a) -1)
  1415. ","
  1416. (math-compose-expr (nth 3 a) -1)
  1417. ","
  1418. (math-compose-expr (nth 1 a) -1)
  1419. ")"))
  1420. (defun math-maxima-compose-if (a)
  1421. "Compose the \"if\" function in Calc's Maxima mode."
  1422. (list 'horiz
  1423. "if "
  1424. (math-compose-expr (nth 1 a) -1)
  1425. " then "
  1426. (math-compose-expr (nth 2 a) -1)
  1427. " else "
  1428. (math-compose-expr (nth 3 a) -1)))
  1429. (put 'maxima 'math-variable-table
  1430. '(( infinity . var-uinf)
  1431. ( %pi . var-pi)
  1432. ( %e . var-e)
  1433. ( %i . var-i)
  1434. ( %phi . var-phi)
  1435. ( %gamma . var-gamma)))
  1436. (put 'maxima 'math-complex-format '%i)
  1437. (add-to-list 'calc-lang-allow-underscores 'maxima)
  1438. (add-to-list 'calc-lang-allow-percentsigns 'maxima)
  1439. (add-to-list 'calc-lang-brackets-are-subscripts 'maxima)
  1440. (put 'maxima 'math-compose-subscr
  1441. (function
  1442. (lambda (a)
  1443. (let ((args (cdr (cdr a))))
  1444. (list 'horiz
  1445. (math-compose-expr (nth 1 a) 1000)
  1446. "["
  1447. (math-compose-vector args ", " 0)
  1448. "]")))))
  1449. (put 'maxima 'math-matrix-formatter
  1450. (function
  1451. (lambda (a)
  1452. (list 'horiz
  1453. "matrix("
  1454. (math-compose-vector (cdr a)
  1455. (concat math-comp-comma " ")
  1456. math-comp-vector-prec)
  1457. ")"))))
  1458. ;;; Giac
  1459. (defun calc-giac-language ()
  1460. "Change the Calc language to be Giac-like."
  1461. (interactive)
  1462. (calc-wrapper
  1463. (calc-set-language 'giac)
  1464. (message "Giac language mode")))
  1465. (put 'giac 'math-oper-table
  1466. '( ( "[" (math-read-giac-subscr) 250 -1 )
  1467. ( "+" + 180 181 )
  1468. ( "-" - 180 181 )
  1469. ( "/" / 191 192 )
  1470. ( "*" * 191 192 )
  1471. ( "^" ^ 201 200 )
  1472. ( "u+" ident -1 197 )
  1473. ( "u-" neg -1 197 )
  1474. ( "!" calcFunc-fact 210 -1 )
  1475. ( ".." (math-read-maple-dots) 165 165 )
  1476. ( "\\dots" (math-read-maple-dots) 165 165 )
  1477. ( "intersect" calcFunc-vint 191 192 )
  1478. ( "union" calcFunc-vunion 180 181 )
  1479. ( "minus" calcFunc-vdiff 180 181 )
  1480. ( "<" calcFunc-lt 160 160 )
  1481. ( ">" calcFunc-gt 160 160 )
  1482. ( "<=" calcFunc-leq 160 160 )
  1483. ( ">=" calcFunc-geq 160 160 )
  1484. ( "=" calcFunc-eq 160 160 )
  1485. ( "==" calcFunc-eq 160 160 )
  1486. ( "!=" calcFunc-neq 160 160 )
  1487. ( "and" calcFunc-land 110 111 )
  1488. ( "or" calcFunc-lor 100 101 )
  1489. ( "&&" calcFunc-land 110 111 )
  1490. ( "||" calcFunc-lor 100 101 )
  1491. ( "not" calcFunc-lnot -1 121 )
  1492. ( ":=" calcFunc-assign 51 50 )))
  1493. (put 'giac 'math-function-table
  1494. '(( rdiv . calcFunc-div)
  1495. ( iquo . calcFunc-idiv)
  1496. ( irem . calcFunc-mod)
  1497. ( remain . calcFunc-mod)
  1498. ( floor . calcFunc-floor)
  1499. ( iPart . calcFunc-floor)
  1500. ( ceil . calcFunc-ceil)
  1501. ( ceiling . calcFunc-ceil)
  1502. ( re . calcFunc-re)
  1503. ( real . calcFunc-re)
  1504. ( im . calcFunc-im)
  1505. ( imag . calcFunc-im)
  1506. ( float2rational . calcFunc-pfrac)
  1507. ( exact . calcFunc-pfrac)
  1508. ( evalf . calcFunc-pfloat)
  1509. ( bitand . calcFunc-and)
  1510. ( bitor . calcFunc-or)
  1511. ( bitxor . calcFunc-xor)
  1512. ( asin . calcFunc-arcsin)
  1513. ( acos . calcFunc-arccos)
  1514. ( atan . calcFunc-arctan)
  1515. ( asinh . calcFunc-arcsinh)
  1516. ( acosh . calcFunc-arccosh)
  1517. ( atanh . calcFunc-arctanh)
  1518. ( log . calcFunc-ln)
  1519. ( logb . calcFunc-log)
  1520. ( factorial . calcFunc-fact)
  1521. ( comb . calcFunc-choose)
  1522. ( binomial . calcFunc-choose)
  1523. ( nCr . calcFunc-choose)
  1524. ( perm . calcFunc-perm)
  1525. ( nPr . calcFunc-perm)
  1526. ( bernoulli . calcFunc-bern)
  1527. ( is_prime . calcFunc-prime)
  1528. ( isprime . calcFunc-prime)
  1529. ( isPrime . calcFunc-prime)
  1530. ( ifactors . calcFunc-prfac)
  1531. ( euler . calcFunc-totient)
  1532. ( phi . calcFunc-totient)
  1533. ( rand . calcFunc-random)
  1534. ( concat . calcFunc-vconcat)
  1535. ( augment . calcFunc-vconcat)
  1536. ( mid . calcFunc-subvec)
  1537. ( length . calcFunc-length)
  1538. ( size . calcFunc-length)
  1539. ( nops . calcFunc-length)
  1540. ( SortA . calcFunc-sort)
  1541. ( SortB . calcFunc-rsort)
  1542. ( revlist . calcFunc-rev)
  1543. ( cross . calcFunc-cross)
  1544. ( crossP . calcFunc-cross)
  1545. ( crossproduct . calcFunc-cross)
  1546. ( mul . calcFunc-mul)
  1547. ( dot . calcFunc-mul)
  1548. ( dotprod . calcFunc-mul)
  1549. ( dotP . calcFunc-mul)
  1550. ( scalar_product . calcFunc-mul)
  1551. ( scalar_Product . calcFunc-mul)
  1552. ( row . calcFunc-mrow)
  1553. ( col . calcFunc-mcol)
  1554. ( dim . calcFunc-mdims)
  1555. ( tran . calcFunc-trn)
  1556. ( transpose . calcFunc-trn)
  1557. ( lu . calcFunc-lud)
  1558. ( trace . calcFunc-tr)
  1559. ( member . calcFunc-in)
  1560. ( sum . calcFunc-vsum)
  1561. ( add . calcFunc-vsum)
  1562. ( product . calcFunc-vprod)
  1563. ( mean . calcFunc-vmean)
  1564. ( median . calcFunc-vmedian)
  1565. ( stddev . calcFunc-vsdev)
  1566. ( stddevp . calcFunc-vpsdev)
  1567. ( variance . calcFunc-vpvar)
  1568. ( map . calcFunc-map)
  1569. ( apply . calcFunc-map)
  1570. ( of . calcFunc-map)
  1571. ( zip . calcFunc-map)
  1572. ( expand . calcFunc-expand)
  1573. ( fdistrib . calcFunc-expand)
  1574. ( partfrac . calcFunc-apart)
  1575. ( ratnormal . calcFunc-nrat)
  1576. ( diff . calcFunc-deriv)
  1577. ( derive . calcFunc-deriv)
  1578. ( integrate . calcFunc-integ)
  1579. ( int . calcFunc-integ)
  1580. ( Int . calcFunc-integ)
  1581. ( romberg . calcFunc-ninteg)
  1582. ( nInt . calcFunc-ninteg)
  1583. ( lcoeff . calcFunc-plead)
  1584. ( content . calcFunc-pcont)
  1585. ( primpart . calcFunc-pprim)
  1586. ( quo . calcFunc-pdiv)
  1587. ( rem . calcFunc-prem)
  1588. ( quorem . calcFunc-pdivrem)
  1589. ( divide . calcFunc-pdivrem)
  1590. ( equal . calcFunc-eq)
  1591. ( ifte . calcFunc-if)
  1592. ( not . calcFunc-lnot)
  1593. ( rhs . calcFunc-rmeq)
  1594. ( right . calcFunc-rmeq)
  1595. ( prepend . (math-lang-switch-args calcFunc-cons))
  1596. ( contains . (math-lang-switch-args calcFunc-in))
  1597. ( has . (math-lang-switch-args calcFunc-refers))))
  1598. (defun math-lang-switch-args (f val)
  1599. "Read the arguments to a Calc function in reverse order.
  1600. This is used for various language modes which have functions in reverse
  1601. order to Calc's."
  1602. (let ((args (math-read-expr-list)))
  1603. (math-read-token)
  1604. (list (nth 2 f)
  1605. (nth 1 args)
  1606. (nth 0 args))))
  1607. (put 'giac 'math-parse-table
  1608. '((("set" 0)
  1609. calcFunc-rdup
  1610. (var ArgA var-ArgA))))
  1611. (put 'giac 'math-special-function-table
  1612. '((calcFunc-cons . (math-lang-compose-switch-args "prepend"))
  1613. (calcFunc-in . (math-lang-compose-switch-args "contains"))
  1614. (calcFunc-refers . (math-lang-compose-switch-args "has"))
  1615. (intv . math-compose-maple-intv)))
  1616. (defun math-lang-compose-switch-args (a fn)
  1617. "Compose the arguments to a Calc function in reverse order.
  1618. This is used for various language modes which have functions in reverse
  1619. order to Calc's."
  1620. (list 'horiz (nth 1 fn)
  1621. "("
  1622. (math-compose-expr (nth 2 a) 0)
  1623. ","
  1624. (math-compose-expr (nth 1 a) 0)
  1625. ")"))
  1626. (put 'giac 'math-variable-table
  1627. '(( infinity . var-inf)
  1628. ( infinity . var-uinf)))
  1629. (put 'giac 'math-complex-format 'i)
  1630. (add-to-list 'calc-lang-allow-underscores 'giac)
  1631. (put 'giac 'math-compose-subscr
  1632. (function
  1633. (lambda (a)
  1634. (let ((args (cdr (cdr a))))
  1635. (list 'horiz
  1636. (math-compose-expr (nth 1 a) 1000)
  1637. "["
  1638. (math-compose-expr
  1639. (calc-normalize (list '- (nth 2 a) 1)) 0)
  1640. "]")))))
  1641. (defun math-read-giac-subscr (x op)
  1642. (let ((idx (math-read-expr-level 0)))
  1643. (or (equal math-expr-data "]")
  1644. (throw 'syntax "Expected `]'"))
  1645. (math-read-token)
  1646. (list 'calcFunc-subscr x (calc-normalize (list '+ idx 1)))))
  1647. (add-to-list 'calc-lang-c-type-hex 'giac)
  1648. (defun calc-mathematica-language ()
  1649. (interactive)
  1650. (calc-wrapper
  1651. (calc-set-language 'math)
  1652. (message "Mathematica language mode")))
  1653. (put 'math 'math-oper-table
  1654. '( ( "[[" (math-read-math-subscr) 250 -1 )
  1655. ( "!" calcFunc-fact 210 -1 )
  1656. ( "!!" calcFunc-dfact 210 -1 )
  1657. ( "^" ^ 201 200 )
  1658. ( "u+" ident -1 197 )
  1659. ( "u-" neg -1 197 )
  1660. ( "/" / 195 196 )
  1661. ( "*" * 190 191 )
  1662. ( "2x" * 190 191 )
  1663. ( "+" + 180 181 )
  1664. ( "-" - 180 181 )
  1665. ( "<" calcFunc-lt 160 161 )
  1666. ( ">" calcFunc-gt 160 161 )
  1667. ( "<=" calcFunc-leq 160 161 )
  1668. ( ">=" calcFunc-geq 160 161 )
  1669. ( "==" calcFunc-eq 150 151 )
  1670. ( "!=" calcFunc-neq 150 151 )
  1671. ( "u!" calcFunc-lnot -1 121 )
  1672. ( "&&" calcFunc-land 110 111 )
  1673. ( "||" calcFunc-lor 100 101 )
  1674. ( "!!!" calcFunc-pnot -1 85 )
  1675. ( "&&&" calcFunc-pand 80 81 )
  1676. ( "|||" calcFunc-por 75 76 )
  1677. ( ":=" calcFunc-assign 51 50 )
  1678. ( "=" calcFunc-assign 51 50 )
  1679. ( "->" calcFunc-assign 51 50 )
  1680. ( ":>" calcFunc-assign 51 50 )
  1681. ( "::" calcFunc-condition 45 46 )
  1682. ))
  1683. (put 'math 'math-function-table
  1684. '( ( Abs . calcFunc-abs )
  1685. ( ArcCos . calcFunc-arccos )
  1686. ( ArcCosh . calcFunc-arccosh )
  1687. ( ArcSin . calcFunc-arcsin )
  1688. ( ArcSinh . calcFunc-arcsinh )
  1689. ( ArcTan . calcFunc-arctan )
  1690. ( ArcTanh . calcFunc-arctanh )
  1691. ( Arg . calcFunc-arg )
  1692. ( Binomial . calcFunc-choose )
  1693. ( Ceiling . calcFunc-ceil )
  1694. ( Conjugate . calcFunc-conj )
  1695. ( Cos . calcFunc-cos )
  1696. ( Cosh . calcFunc-cosh )
  1697. ( Cot . calcFunc-cot )
  1698. ( Coth . calcFunc-coth )
  1699. ( Csc . calcFunc-csc )
  1700. ( Csch . calcFunc-csch )
  1701. ( D . calcFunc-deriv )
  1702. ( Dt . calcFunc-tderiv )
  1703. ( Det . calcFunc-det )
  1704. ( Exp . calcFunc-exp )
  1705. ( EulerPhi . calcFunc-totient )
  1706. ( Floor . calcFunc-floor )
  1707. ( Gamma . calcFunc-gamma )
  1708. ( GCD . calcFunc-gcd )
  1709. ( If . calcFunc-if )
  1710. ( Im . calcFunc-im )
  1711. ( Inverse . calcFunc-inv )
  1712. ( Integrate . calcFunc-integ )
  1713. ( Join . calcFunc-vconcat )
  1714. ( LCM . calcFunc-lcm )
  1715. ( Log . calcFunc-ln )
  1716. ( Max . calcFunc-max )
  1717. ( Min . calcFunc-min )
  1718. ( Mod . calcFunc-mod )
  1719. ( MoebiusMu . calcFunc-moebius )
  1720. ( Random . calcFunc-random )
  1721. ( Round . calcFunc-round )
  1722. ( Re . calcFunc-re )
  1723. ( Sec . calcFunc-sec )
  1724. ( Sech . calcFunc-sech )
  1725. ( Sign . calcFunc-sign )
  1726. ( Sin . calcFunc-sin )
  1727. ( Sinh . calcFunc-sinh )
  1728. ( Sqrt . calcFunc-sqrt )
  1729. ( Tan . calcFunc-tan )
  1730. ( Tanh . calcFunc-tanh )
  1731. ( Transpose . calcFunc-trn )
  1732. ( Length . calcFunc-vlen )
  1733. ))
  1734. (put 'math 'math-variable-table
  1735. '( ( I . var-i )
  1736. ( Pi . var-pi )
  1737. ( E . var-e )
  1738. ( GoldenRatio . var-phi )
  1739. ( EulerGamma . var-gamma )
  1740. ( Infinity . var-inf )
  1741. ( ComplexInfinity . var-uinf )
  1742. ( Indeterminate . var-nan )
  1743. ))
  1744. (put 'math 'math-vector-brackets "{}")
  1745. (put 'math 'math-complex-format 'I)
  1746. (put 'math 'math-function-open "[")
  1747. (put 'math 'math-function-close "]")
  1748. (put 'math 'math-radix-formatter
  1749. (function (lambda (r s) (format "%d^^%s" r s))))
  1750. (put 'math 'math-lang-read
  1751. '((eq (string-match "\\[\\[\\|->\\|:>" math-exp-str math-exp-pos)
  1752. math-exp-pos)
  1753. (setq math-exp-token 'punc
  1754. math-expr-data (math-match-substring math-exp-str 0)
  1755. math-exp-pos (match-end 0))))
  1756. (put 'math 'math-compose-subscr
  1757. (function
  1758. (lambda (a)
  1759. (list 'horiz
  1760. (math-compose-expr (nth 1 a) 1000)
  1761. "[["
  1762. (math-compose-expr (nth 2 a) 0)
  1763. "]]"))))
  1764. (defun math-read-math-subscr (x op)
  1765. (let ((idx (math-read-expr-level 0)))
  1766. (or (and (equal math-expr-data "]")
  1767. (progn
  1768. (math-read-token)
  1769. (equal math-expr-data "]")))
  1770. (throw 'syntax "Expected `]]'"))
  1771. (math-read-token)
  1772. (list 'calcFunc-subscr x idx)))
  1773. (defun calc-maple-language ()
  1774. (interactive)
  1775. (calc-wrapper
  1776. (calc-set-language 'maple)
  1777. (message "Maple language mode")))
  1778. (put 'maple 'math-oper-table
  1779. '( ( "matrix" ident -1 300 )
  1780. ( "MATRIX" ident -1 300 )
  1781. ( "!" calcFunc-fact 210 -1 )
  1782. ( "^" ^ 201 200 )
  1783. ( "**" ^ 201 200 )
  1784. ( "u+" ident -1 197 )
  1785. ( "u-" neg -1 197 )
  1786. ( "/" / 191 192 )
  1787. ( "*" * 191 192 )
  1788. ( "intersect" calcFunc-vint 191 192 )
  1789. ( "+" + 180 181 )
  1790. ( "-" - 180 181 )
  1791. ( "union" calcFunc-vunion 180 181 )
  1792. ( "minus" calcFunc-vdiff 180 181 )
  1793. ( "mod" % 170 170 )
  1794. ( ".." (math-read-maple-dots) 165 165 )
  1795. ( "\\dots" (math-read-maple-dots) 165 165 )
  1796. ( "<" calcFunc-lt 160 160 )
  1797. ( ">" calcFunc-gt 160 160 )
  1798. ( "<=" calcFunc-leq 160 160 )
  1799. ( ">=" calcFunc-geq 160 160 )
  1800. ( "=" calcFunc-eq 160 160 )
  1801. ( "<>" calcFunc-neq 160 160 )
  1802. ( "not" calcFunc-lnot -1 121 )
  1803. ( "and" calcFunc-land 110 111 )
  1804. ( "or" calcFunc-lor 100 101 )
  1805. ( "!!!" calcFunc-pnot -1 85 )
  1806. ( "&&&" calcFunc-pand 80 81 )
  1807. ( "|||" calcFunc-por 75 76 )
  1808. ( ":=" calcFunc-assign 51 50 )
  1809. ( "::" calcFunc-condition 45 46 )
  1810. ))
  1811. (put 'maple 'math-function-table
  1812. '( ( bernoulli . calcFunc-bern )
  1813. ( binomial . calcFunc-choose )
  1814. ( diff . calcFunc-deriv )
  1815. ( GAMMA . calcFunc-gamma )
  1816. ( ifactor . calcFunc-prfac )
  1817. ( igcd . calcFunc-gcd )
  1818. ( ilcm . calcFunc-lcm )
  1819. ( int . calcFunc-integ )
  1820. ( modp . % )
  1821. ( irem . % )
  1822. ( iquo . calcFunc-idiv )
  1823. ( isprime . calcFunc-prime )
  1824. ( length . calcFunc-vlen )
  1825. ( member . calcFunc-in )
  1826. ( crossprod . calcFunc-cross )
  1827. ( inverse . calcFunc-inv )
  1828. ( trace . calcFunc-tr )
  1829. ( transpose . calcFunc-trn )
  1830. ( vectdim . calcFunc-vlen )
  1831. ))
  1832. (put 'maple 'math-special-function-table
  1833. '((intv . math-compose-maple-intv)))
  1834. (put 'maple 'math-variable-table
  1835. '( ( I . var-i )
  1836. ( Pi . var-pi )
  1837. ( E . var-e )
  1838. ( infinity . var-inf )
  1839. ( infinity . var-uinf )
  1840. ( infinity . var-nan )
  1841. ))
  1842. (put 'maple 'math-complex-format 'I)
  1843. (put 'maple 'math-matrix-formatter
  1844. (function
  1845. (lambda (a)
  1846. (list 'horiz
  1847. "matrix("
  1848. math-comp-left-bracket
  1849. (math-compose-vector (cdr a)
  1850. (concat math-comp-comma " ")
  1851. math-comp-vector-prec)
  1852. math-comp-right-bracket
  1853. ")"))))
  1854. (put 'maple 'math-compose-subscr
  1855. (function
  1856. (lambda (a)
  1857. (let ((args (cdr (cdr a))))
  1858. (list 'horiz
  1859. (math-compose-expr (nth 1 a) 1000)
  1860. "["
  1861. (math-compose-vector args ", " 0)
  1862. "]")))))
  1863. (add-to-list 'calc-lang-allow-underscores 'maple)
  1864. (add-to-list 'calc-lang-brackets-are-subscripts 'maple)
  1865. (defun math-compose-maple-intv (a)
  1866. (list 'horiz
  1867. (math-compose-expr (nth 2 a) 0)
  1868. " .. "
  1869. (math-compose-expr (nth 3 a) 0)))
  1870. (defun math-read-maple-dots (x op)
  1871. (list 'intv 3 x (math-read-expr-level (nth 3 op))))
  1872. ;; The variable math-read-big-lines is local to math-read-big-expr in
  1873. ;; calc-ext.el, but is used by math-read-big-rec, math-read-big-char,
  1874. ;; math-read-big-emptyp, math-read-big-error and math-read-big-balance,
  1875. ;; which are called (directly and indirectly) by math-read-big-expr.
  1876. ;; It is also local to math-read-big-bigp in calc-ext.el, which calls
  1877. ;; math-read-big-balance.
  1878. (defvar math-read-big-lines)
  1879. ;; The variables math-read-big-baseline and math-read-big-h2 are
  1880. ;; local to math-read-big-expr in calc-ext.el, but used by
  1881. ;; math-read-big-rec.
  1882. (defvar math-read-big-baseline)
  1883. (defvar math-read-big-h2)
  1884. ;; The variables math-rb-h1, math-rb-h2, math-rb-v1 and math-rb-v2
  1885. ;; are local to math-read-big-rec, but are used by math-read-big-char,
  1886. ;; math-read-big-emptyp and math-read-big-balance which are called by
  1887. ;; math-read-big-rec.
  1888. ;; math-rb-h2 is also local to math-read-big-bigp in calc-ext.el,
  1889. ;; which calls math-read-big-balance.
  1890. (defvar math-rb-h1)
  1891. (defvar math-rb-h2)
  1892. (defvar math-rb-v1)
  1893. (defvar math-rb-v2)
  1894. (defun math-read-big-rec (math-rb-h1 math-rb-v1 math-rb-h2 math-rb-v2
  1895. &optional baseline prec short)
  1896. (or prec (setq prec 0))
  1897. ;; Clip whitespace above or below.
  1898. (while (and (< math-rb-v1 math-rb-v2)
  1899. (math-read-big-emptyp math-rb-h1 math-rb-v1 math-rb-h2 (1+ math-rb-v1)))
  1900. (setq math-rb-v1 (1+ math-rb-v1)))
  1901. (while (and (< math-rb-v1 math-rb-v2)
  1902. (math-read-big-emptyp math-rb-h1 (1- math-rb-v2) math-rb-h2 math-rb-v2))
  1903. (setq math-rb-v2 (1- math-rb-v2)))
  1904. ;; If formula is a single line high, normal parser can handle it.
  1905. (if (<= math-rb-v2 (1+ math-rb-v1))
  1906. (if (or (<= math-rb-v2 math-rb-v1)
  1907. (> math-rb-h1 (length (setq math-rb-v2
  1908. (nth math-rb-v1 math-read-big-lines)))))
  1909. (math-read-big-error math-rb-h1 math-rb-v1)
  1910. (setq math-read-big-baseline math-rb-v1
  1911. math-read-big-h2 math-rb-h2
  1912. math-rb-v2 (nth math-rb-v1 math-read-big-lines)
  1913. math-rb-h2 (math-read-expr
  1914. (substring math-rb-v2 math-rb-h1
  1915. (min math-rb-h2 (length math-rb-v2)))))
  1916. (if (eq (car-safe math-rb-h2) 'error)
  1917. (math-read-big-error (+ math-rb-h1 (nth 1 math-rb-h2))
  1918. math-rb-v1 (nth 2 math-rb-h2))
  1919. math-rb-h2))
  1920. ;; Clip whitespace at left or right.
  1921. (while (and (< math-rb-h1 math-rb-h2)
  1922. (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) math-rb-v2))
  1923. (setq math-rb-h1 (1+ math-rb-h1)))
  1924. (while (and (< math-rb-h1 math-rb-h2)
  1925. (math-read-big-emptyp (1- math-rb-h2) math-rb-v1 math-rb-h2 math-rb-v2))
  1926. (setq math-rb-h2 (1- math-rb-h2)))
  1927. ;; Scan to find widest left-justified "----" in the region.
  1928. (let* ((widest nil)
  1929. (widest-h2 0)
  1930. (lines-v1 (nthcdr math-rb-v1 math-read-big-lines))
  1931. (p lines-v1)
  1932. (v math-rb-v1)
  1933. (other-v nil)
  1934. other-char line len h)
  1935. (while (< v math-rb-v2)
  1936. (setq line (car p)
  1937. len (min math-rb-h2 (length line)))
  1938. (and (< math-rb-h1 len)
  1939. (/= (aref line math-rb-h1) ?\ )
  1940. (if (and (= (aref line math-rb-h1) ?\-)
  1941. ;; Make sure it's not a minus sign.
  1942. (or (and (< (1+ math-rb-h1) len)
  1943. (= (aref line (1+ math-rb-h1)) ?\-))
  1944. (/= (math-read-big-char math-rb-h1 (1- v)) ?\ )
  1945. (/= (math-read-big-char math-rb-h1 (1+ v)) ?\ )))
  1946. (progn
  1947. (setq h math-rb-h1)
  1948. (while (and (< (setq h (1+ h)) len)
  1949. (= (aref line h) ?\-)))
  1950. (if (> h widest-h2)
  1951. (setq widest v
  1952. widest-h2 h)))
  1953. (or other-v (setq other-v v other-char (aref line math-rb-h1)))))
  1954. (setq v (1+ v)
  1955. p (cdr p)))
  1956. (cond ((not (setq v other-v))
  1957. (math-read-big-error math-rb-h1 math-rb-v1)) ; Should never happen!
  1958. ;; Quotient.
  1959. (widest
  1960. (setq h widest-h2
  1961. v widest)
  1962. (let ((num (math-read-big-rec math-rb-h1 math-rb-v1 h v))
  1963. (den (math-read-big-rec math-rb-h1 (1+ v) h math-rb-v2)))
  1964. (setq p (if (and (math-integerp num) (math-integerp den))
  1965. (math-make-frac num den)
  1966. (list '/ num den)))))
  1967. ;; Big radical sign.
  1968. ((= other-char ?\\)
  1969. (or (= (math-read-big-char (1+ math-rb-h1) v) ?\|)
  1970. (math-read-big-error (1+ math-rb-h1) v "Malformed root sign"))
  1971. (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
  1972. (while (= (math-read-big-char (1+ math-rb-h1) (setq v (1- v))) ?\|))
  1973. (or (= (math-read-big-char (setq h (+ math-rb-h1 2)) v) ?\_)
  1974. (math-read-big-error h v "Malformed root sign"))
  1975. (while (= (math-read-big-char (setq h (1+ h)) v) ?\_))
  1976. (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
  1977. (math-read-big-emptyp math-rb-h1 (1+ other-v) h math-rb-v2 nil t)
  1978. (setq p (list 'calcFunc-sqrt (math-read-big-rec
  1979. (+ math-rb-h1 2) (1+ v)
  1980. h (1+ other-v) baseline))
  1981. v math-read-big-baseline))
  1982. ;; Small radical sign.
  1983. ((and (= other-char ?V)
  1984. (= (math-read-big-char (1+ math-rb-h1) (1- v)) ?\_))
  1985. (setq h (1+ math-rb-h1))
  1986. (math-read-big-emptyp math-rb-h1 math-rb-v1 h (1- v) nil t)
  1987. (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t)
  1988. (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
  1989. (while (= (math-read-big-char (setq h (1+ h)) (1- v)) ?\_))
  1990. (setq p (list 'calcFunc-sqrt (math-read-big-rec
  1991. (1+ math-rb-h1) v h (1+ v) t))
  1992. v math-read-big-baseline))
  1993. ;; Binomial coefficient.
  1994. ((and (= other-char ?\()
  1995. (= (math-read-big-char (1+ math-rb-h1) v) ?\ )
  1996. (= (string-match "( *)" (nth v math-read-big-lines)
  1997. math-rb-h1) math-rb-h1))
  1998. (setq h (match-end 0))
  1999. (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
  2000. (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t)
  2001. (math-read-big-emptyp (1- h) math-rb-v1 h v nil t)
  2002. (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t)
  2003. (setq p (list 'calcFunc-choose
  2004. (math-read-big-rec (1+ math-rb-h1) math-rb-v1 (1- h) v)
  2005. (math-read-big-rec (1+ math-rb-h1) (1+ v)
  2006. (1- h) math-rb-v2))))
  2007. ;; Minus sign.
  2008. ((= other-char ?\-)
  2009. (setq p (list 'neg (math-read-big-rec (1+ math-rb-h1) math-rb-v1
  2010. math-rb-h2 math-rb-v2 v 250 t))
  2011. v math-read-big-baseline
  2012. h math-read-big-h2))
  2013. ;; Parentheses.
  2014. ((= other-char ?\()
  2015. (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
  2016. (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t)
  2017. (setq h (math-read-big-balance (1+ math-rb-h1) v "(" t))
  2018. (math-read-big-emptyp (1- h) math-rb-v1 h v nil t)
  2019. (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t)
  2020. (let ((sep (math-read-big-char (1- h) v))
  2021. hmid)
  2022. (if (= sep ?\.)
  2023. (setq h (1+ h)))
  2024. (if (= sep ?\])
  2025. (math-read-big-error (1- h) v "Expected `)'"))
  2026. (if (= sep ?\))
  2027. (setq p (math-read-big-rec
  2028. (1+ math-rb-h1) math-rb-v1 (1- h) math-rb-v2 v))
  2029. (setq hmid (math-read-big-balance h v "(")
  2030. p (list p
  2031. (math-read-big-rec h math-rb-v1 (1- hmid) math-rb-v2 v))
  2032. h hmid)
  2033. (cond ((= sep ?\.)
  2034. (setq p (cons 'intv (cons (if (= (math-read-big-char
  2035. (1- h) v)
  2036. ?\))
  2037. 0 1)
  2038. p))))
  2039. ((= (math-read-big-char (1- h) v) ?\])
  2040. (math-read-big-error (1- h) v "Expected `)'"))
  2041. ((= sep ?\,)
  2042. (or (and (math-realp (car p)) (math-realp (nth 1 p)))
  2043. (math-read-big-error
  2044. math-rb-h1 v "Complex components must be real"))
  2045. (setq p (cons 'cplx p)))
  2046. ((= sep ?\;)
  2047. (or (and (math-realp (car p)) (math-anglep (nth 1 p)))
  2048. (math-read-big-error
  2049. math-rb-h1 v "Complex components must be real"))
  2050. (setq p (cons 'polar p)))))))
  2051. ;; Matrix.
  2052. ((and (= other-char ?\[)
  2053. (or (= (math-read-big-char (setq h math-rb-h1) (1+ v)) ?\[)
  2054. (= (math-read-big-char (setq h (1+ h)) v) ?\[)
  2055. (and (= (math-read-big-char h v) ?\ )
  2056. (= (math-read-big-char (setq h (1+ h)) v) ?\[)))
  2057. (= (math-read-big-char h (1+ v)) ?\[))
  2058. (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t)
  2059. (let ((vtop v)
  2060. (hleft h)
  2061. (hright nil))
  2062. (setq p nil)
  2063. (while (progn
  2064. (setq h (math-read-big-balance (1+ hleft) v "["))
  2065. (if hright
  2066. (or (= h hright)
  2067. (math-read-big-error hright v "Expected `]'"))
  2068. (setq hright h))
  2069. (setq p (cons (math-read-big-rec
  2070. hleft v h (1+ v)) p))
  2071. (and (memq (math-read-big-char h v) '(?\ ?\,))
  2072. (= (math-read-big-char hleft (1+ v)) ?\[)))
  2073. (setq v (1+ v)))
  2074. (or (= hleft math-rb-h1)
  2075. (progn
  2076. (if (= (math-read-big-char h v) ?\ )
  2077. (setq h (1+ h)))
  2078. (and (= (math-read-big-char h v) ?\])
  2079. (setq h (1+ h))))
  2080. (math-read-big-error (1- h) v "Expected `]'"))
  2081. (if (= (math-read-big-char h vtop) ?\,)
  2082. (setq h (1+ h)))
  2083. (math-read-big-emptyp math-rb-h1 (1+ v) (1- h) math-rb-v2 nil t)
  2084. (setq v (+ vtop (/ (- v vtop) 2))
  2085. p (cons 'vec (nreverse p)))))
  2086. ;; Square brackets.
  2087. ((= other-char ?\[)
  2088. (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
  2089. (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t)
  2090. (setq p nil
  2091. h (1+ math-rb-h1))
  2092. (while (progn
  2093. (setq widest (math-read-big-balance h v "[" t))
  2094. (math-read-big-emptyp (1- h) math-rb-v1 h v nil t)
  2095. (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t)
  2096. (setq p (cons (math-read-big-rec
  2097. h math-rb-v1 (1- widest) math-rb-v2 v) p)
  2098. h widest)
  2099. (= (math-read-big-char (1- h) v) ?\,)))
  2100. (setq widest (math-read-big-char (1- h) v))
  2101. (if (or (memq widest '(?\; ?\)))
  2102. (and (eq widest ?\.) (cdr p)))
  2103. (math-read-big-error (1- h) v "Expected `]'"))
  2104. (if (= widest ?\.)
  2105. (setq h (1+ h)
  2106. widest (math-read-big-balance h v "[")
  2107. p (nconc p (list (math-read-big-rec
  2108. h math-rb-v1 (1- widest) math-rb-v2 v)))
  2109. h widest
  2110. p (cons 'intv (cons (if (= (math-read-big-char (1- h) v)
  2111. ?\])
  2112. 3 2)
  2113. p)))
  2114. (setq p (cons 'vec (nreverse p)))))
  2115. ;; Date form.
  2116. ((= other-char ?\<)
  2117. (setq line (nth v math-read-big-lines))
  2118. (string-match ">" line math-rb-h1)
  2119. (setq h (match-end 0))
  2120. (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t)
  2121. (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t)
  2122. (setq p (math-read-big-rec math-rb-h1 v h (1+ v) v)))
  2123. ;; Variable name or function call.
  2124. ((or (and (>= other-char ?a) (<= other-char ?z))
  2125. (and (>= other-char ?A) (<= other-char ?Z))
  2126. (and (>= other-char ?α) (<= other-char ?ω))
  2127. (and (>= other-char ?Α) (<= other-char ?Ω)))
  2128. (setq line (nth v math-read-big-lines))
  2129. (string-match "\\([a-zA-Zα-ωΑ-Ω'_]+\\) *" line math-rb-h1)
  2130. (setq h (match-end 1)
  2131. widest (match-end 0)
  2132. p (math-match-substring line 1))
  2133. (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t)
  2134. (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t)
  2135. (if (= (math-read-big-char widest v) ?\()
  2136. (progn
  2137. (setq line (if (string-match "-" p)
  2138. (intern p)
  2139. (intern (concat "calcFunc-" p)))
  2140. h (1+ widest)
  2141. p nil)
  2142. (math-read-big-emptyp widest math-rb-v1 h v nil t)
  2143. (math-read-big-emptyp widest (1+ v) h math-rb-v2 nil t)
  2144. (while (progn
  2145. (setq widest (math-read-big-balance h v "(" t))
  2146. (math-read-big-emptyp (1- h) math-rb-v1 h v nil t)
  2147. (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t)
  2148. (setq p (cons (math-read-big-rec
  2149. h math-rb-v1 (1- widest) math-rb-v2 v) p)
  2150. h widest)
  2151. (= (math-read-big-char (1- h) v) ?\,)))
  2152. (or (= (math-read-big-char (1- h) v) ?\))
  2153. (math-read-big-error (1- h) v "Expected `)'"))
  2154. (setq p (cons line (nreverse p))))
  2155. (setq p (list 'var
  2156. (intern (math-remove-dashes p))
  2157. (if (string-match "-" p)
  2158. (intern p)
  2159. (intern (concat "var-" p)))))))
  2160. ;; Number.
  2161. (t
  2162. (setq line (nth v math-read-big-lines))
  2163. (or (= (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\([0-9]+\\(#\\|\\^\\^\\)[0-9a-zA-Z:]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?" line math-rb-h1) math-rb-h1)
  2164. (math-read-big-error h v "Expected a number"))
  2165. (setq h (match-end 0)
  2166. p (math-read-number (math-match-substring line 0)))
  2167. (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t)
  2168. (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t)))
  2169. ;; Now left term is bounded by math-rb-h1, math-rb-v1, h, math-rb-v2;
  2170. ;; baseline = v.
  2171. (if baseline
  2172. (or (= v baseline)
  2173. (math-read-big-error math-rb-h1 v "Inconsistent baseline in formula"))
  2174. (setq baseline v))
  2175. ;; Look for superscripts or subscripts.
  2176. (setq line (nth baseline math-read-big-lines)
  2177. len (min math-rb-h2 (length line))
  2178. widest h)
  2179. (while (and (< widest len)
  2180. (= (aref line widest) ?\ ))
  2181. (setq widest (1+ widest)))
  2182. (and (>= widest len) (setq widest math-rb-h2))
  2183. (if (math-read-big-emptyp h v widest math-rb-v2)
  2184. (if (math-read-big-emptyp h math-rb-v1 widest v)
  2185. (setq h widest)
  2186. (setq p (list '^ p (math-read-big-rec h math-rb-v1 widest v))
  2187. h widest))
  2188. (if (math-read-big-emptyp h math-rb-v1 widest v)
  2189. (setq p (list 'calcFunc-subscr p
  2190. (math-read-big-rec h v widest math-rb-v2))
  2191. h widest)))
  2192. ;; Look for an operator name and grab additional terms.
  2193. (while (and (< h len)
  2194. (if (setq widest (and (math-read-big-emptyp
  2195. h math-rb-v1 (1+ h) v)
  2196. (math-read-big-emptyp
  2197. h (1+ v) (1+ h) math-rb-v2)
  2198. (string-match "<=\\|>=\\|\\+/-\\|!=\\|&&\\|||\\|:=\\|=>\\|." line h)
  2199. (assoc (math-match-substring line 0)
  2200. (math-standard-ops))))
  2201. (and (>= (nth 2 widest) prec)
  2202. (setq h (match-end 0)))
  2203. (and (not (eq (string-match ",\\|;\\|\\.\\.\\|)\\|\\]\\|:" line h)
  2204. h))
  2205. (setq widest '("2x" * 196 195)))))
  2206. (cond ((eq (nth 3 widest) -1)
  2207. (setq p (list (nth 1 widest) p)))
  2208. ((equal (car widest) "?")
  2209. (let ((y (math-read-big-rec h math-rb-v1 math-rb-h2
  2210. math-rb-v2 baseline nil t)))
  2211. (or (= (math-read-big-char math-read-big-h2 baseline) ?\:)
  2212. (math-read-big-error math-read-big-h2 baseline
  2213. "Expected `:'"))
  2214. (setq p (list (nth 1 widest) p y
  2215. (math-read-big-rec
  2216. (1+ math-read-big-h2) math-rb-v1 math-rb-h2 math-rb-v2
  2217. baseline (nth 3 widest) t))
  2218. h math-read-big-h2)))
  2219. (t
  2220. (setq p (list (nth 1 widest) p
  2221. (math-read-big-rec h math-rb-v1 math-rb-h2 math-rb-v2
  2222. baseline (nth 3 widest) t))
  2223. h math-read-big-h2))))
  2224. ;; Return all relevant information to caller.
  2225. (setq math-read-big-baseline baseline
  2226. math-read-big-h2 h)
  2227. (or short (= math-read-big-h2 math-rb-h2)
  2228. (math-read-big-error h baseline))
  2229. p)))
  2230. (defun math-read-big-char (h v)
  2231. (or (and (>= h math-rb-h1)
  2232. (< h math-rb-h2)
  2233. (>= v math-rb-v1)
  2234. (< v math-rb-v2)
  2235. (let ((line (nth v math-read-big-lines)))
  2236. (and line
  2237. (< h (length line))
  2238. (aref line h))))
  2239. ?\ ))
  2240. (defun math-read-big-emptyp (eh1 ev1 eh2 ev2 &optional what error)
  2241. (and (< ev1 math-rb-v1) (setq ev1 math-rb-v1))
  2242. (and (< eh1 math-rb-h1) (setq eh1 math-rb-h1))
  2243. (and (> ev2 math-rb-v2) (setq ev2 math-rb-v2))
  2244. (and (> eh2 math-rb-h2) (setq eh2 math-rb-h2))
  2245. (or what (setq what ?\ ))
  2246. (let ((p (nthcdr ev1 math-read-big-lines))
  2247. h)
  2248. (while (and (< ev1 ev2)
  2249. (progn
  2250. (setq h (min eh2 (length (car p))))
  2251. (while (and (>= (setq h (1- h)) eh1)
  2252. (= (aref (car p) h) what)))
  2253. (and error (>= h eh1)
  2254. (math-read-big-error h ev1 (if (stringp error)
  2255. error
  2256. "Whitespace expected")))
  2257. (< h eh1)))
  2258. (setq ev1 (1+ ev1)
  2259. p (cdr p)))
  2260. (>= ev1 ev2)))
  2261. ;; math-read-big-err-msg is local to math-read-big-expr in calc-ext.el,
  2262. ;; but is used by math-read-big-error which is called (indirectly) by
  2263. ;; math-read-big-expr.
  2264. (defvar math-read-big-err-msg)
  2265. (defun math-read-big-error (h v &optional msg)
  2266. (let ((pos 0)
  2267. (p math-read-big-lines))
  2268. (while (> v 0)
  2269. (setq pos (+ pos 1 (length (car p)))
  2270. p (cdr p)
  2271. v (1- v)))
  2272. (setq h (+ pos (min h (length (car p))))
  2273. math-read-big-err-msg (list 'error h (or msg "Syntax error")))
  2274. (throw 'syntax nil)))
  2275. (defun math-read-big-balance (h v what &optional commas)
  2276. (let* ((line (nth v math-read-big-lines))
  2277. (len (min math-rb-h2 (length line)))
  2278. (count 1))
  2279. (while (> count 0)
  2280. (if (>= h len)
  2281. (if what
  2282. (math-read-big-error nil v (format-message
  2283. "Unmatched `%s'" what))
  2284. (setq count 0))
  2285. (if (memq (aref line h) '(?\( ?\[))
  2286. (setq count (1+ count))
  2287. (if (if (and commas (= count 1))
  2288. (or (memq (aref line h) '(?\) ?\] ?\, ?\;))
  2289. (and (eq (aref line h) ?\.)
  2290. (< (1+ h) len)
  2291. (eq (aref line (1+ h)) ?\.)))
  2292. (memq (aref line h) '(?\) ?\])))
  2293. (setq count (1- count))))
  2294. (setq h (1+ h))))
  2295. h))
  2296. (provide 'calc-lang)
  2297. ;;; calc-lang.el ends here