1% BEGIN LICENSE BLOCK 2% Version: CMPL 1.1 3% 4% The contents of this file are subject to the Cisco-style Mozilla Public 5% License Version 1.1 (the "License"); you may not use this file except 6% in compliance with the License. You may obtain a copy of the License 7% at www.eclipse-clp.org/license. 8% 9% Software distributed under the License is distributed on an "AS IS" 10% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11% the License for the specific language governing rights and limitations 12% under the License. 13% 14% The Original Code is The ECLiPSe Constraint Logic Programming System. 15% The Initial Developer of the Original Code is Cisco Systems, Inc. 16% Portions created by the Initial Developer are 17% Copyright (C) 2006 Cisco Systems, Inc. All Rights Reserved. 18% 19% Contributor(s): 20% 21% END LICENSE BLOCK 22 23:- comment(alias, "Arithmetic"). 24:- comment(summary, "Built-ins for arithmetic computations"). 25:- comment(desc, html("See also the User Manual chapter on Arithmetic")). 26:- comment(categories, ["Built-In Predicates"]). 27 28:- tool((<) / 2). 29:- tool((=:=) / 2). 30:- tool((=<) / 2). 31:- tool((=\=) / 2). 32:- tool((>) / 2). 33:- tool((>=) / 2). 34:- tool(eval / 2). 35:- tool((is) / 2). 36:- tool(max / 2). 37:- tool(min / 2). 38:- tool(sum / 2). 39 40:- comment(succ / 2, [ 41 summary:"Successor relation over natural numbers.", 42 amode:(succ(+,-) is semidet), 43 amode:(succ(-,+) is semidet), 44 desc:html("\ 45 Successor relation over natural numbers. Succeeds if X is an 46 integer greater or equal to zero, and Y is one greater than X. 47 If one of the arguments is uninstantiated, it gets computed from 48 the other by adding or subtracting 1, respectively. 49<P> 50 If the system is in coroutining mode and both arguments are 51 uninstantiated, succ/2 delays until at least one argument is known. 52<P> 53"), 54 args:["X" : "an integer or a variable", "Y" : "an integer or a variable"], 55 fail_if:"Fails if X or Y are negative integers, or if Y is 0", 56 exceptions:[5 : "an argument is a non-integer number", 57 4 : "both arguments are uninstantiated (non-coroutining mode only)", 58 24 : "X or Y is not a number"], 59 eg:" 60 Success: 61 succ(0, 1). 62 succ(7, 8). 63 succ(10000000000000000000, 10000000000000000001). 64 succ(0, Y). (gives Y=1) 65 succ(X, 3). (gives X=2) 66 67 Fail: 68 succ(X, 0). 69 succ(X, -5). 70 succ(-1, Y). 71 72 Error: 73 succ(X, Y). (error 4) 74 succ(0.0, Y). (error 5) 75 succ(a, Y). (error 24) 76", 77 see_also:[plus / 3, (+)/3, (-)/3]]). 78 79:- comment(plus / 3, [ 80 summary:"Succeeds if Sum is the sum of integer arguments Add1 and Add2. 81 82", 83 amode:(plus(+,+,-) is det), 84 amode:(plus(+,-,+) is det), 85 amode:(plus(-,+,+) is det), 86 desc:html(" Defines the arithmetic relation Add1 + Add2 = Sum. If all arguments are 87 instantiated plus/3 succeeds if this relation holds. If one of the 88 arguments is uninstantiated, it is bound to an integer such that the 89 relation holds. If the system is in coroutining mode and more than one 90 argument is uninstantiated, plus/3 delays until at least two of the 91 arguments are known. 92 93<P> 94"), 95 args:["Add1" : "an integer or a variable", "Add2" : "an integer or a variable", "Sum" : "an integer or a variable"], 96 exceptions:[5 : "an argument is neither an integer nor a variable", 4 : "more than one argument is uninstantiated (non-coroutining mode only)"], 97 eg:" 98 Success: 99 plus(1, 2, 3). 100 plus(3, 4, Z). (gives Z=7) 101 plus(X, 4, 7). (gives X=3) 102 plus(3, Y, 7). (gives Y=4) 103 Fail: 104 plus(3, 4, 5). 105 Error: 106 plus(3.0, 4.0, 7.0). (error 5) 107 plus(2 + 3, 1, 6). (error 5) 108 plus(X, 1, Z). (error 4) 109 110 111 112", 113 see_also:[times / 3]]). 114 115:- comment(times / 3, [ 116 summary:"Succeeds if Product is the result of multiplying integer arguments Factor1 117and Factor2. 118 119", 120 amode:(times(+,+,-) is det), 121 amode:(times(+,-,+) is semidet), 122 amode:(times(-,+,+) is semidet), 123 desc:html(" Defines the arithmetic relation Factor1 * Factor2 = Product. If all 124 arguments are instantiated times/3 succeeds if this relation holds. If 125 one of the arguments is uninstantiated, it is bound to an integer such 126 that the relation holds. Note that this is not always possible. If the 127 system is in coroutining mode and more than one argument is 128 uninstantiated, times/3 delays until at least two of the arguments are 129 known. 130 131<P> 132"), 133 args:["Factor1" : "An integer or a variable.", "Factor2" : "An integer or a variable.", "Product" : "An integer or a variable."], 134 fail_if:"Fails if it is impossible to find an integer instantiation such that\n Factor1 * Factor2 = Product holds", 135 exceptions:[4 : "more than one argument is uninstantiated (non-coroutining mode only)", 5 : "an argument is neither an integer nor a variable"], 136 eg:" 137 Success: 138 times(2, 3, 6). 139 times(2, 3, Z). (gives Z=6) 140 times(X, 3, 6). (gives X=2) 141 times(2, Y, 6). (gives Y=3) 142 Fail: 143 times(3, 4, 5). 144 times(3, X, 5). 145 Error: 146 times(2.0, 3.0, 6.0). (error 5) 147 times(1 + 4, 2, 10). (error 5) 148 times(X, 1, Z). (error 4) 149 150 151 152", 153 see_also:[plus / 3]]). 154 155:- comment(between / 4, [ 156 summary:"Generate integer values between From and To with Step increment. 157 158", 159 amode:(between(+, +, +, -) is nondet), 160 desc:html(" When first called, this predicate checks that From is less than or equal 161 to To (or greater than or equal if Step is negative) and if so, it binds 162 Result to From. On backtracking it increments Result by Step until it 163 is greater than To (less than To is Step is negative) and then it fails. 164 165<P> 166"), 167 args:["From" : "Integer", "To" : "Integer", "Step" : "Integer", "Result" : "A variable or an integer"], 168 fail_if:"Fails if To is less than From (for positive Step), or From less than To (for negative Step)", 169 exceptions:[4 : "Input arguments are not instantiated.", 170 5 : "An argument is not an integer.", 171 6 : "Step is zero.", 172 24 : "An argument is not a number."], 173 eg:" 174Success: 175 between(1, 4, 1, X). 176 between(5, 0, -2, X). 177 between(2, 10, 3, 8). 178 between(3, 3, 1, X). 179Fail: 180 between(2, 0, 1, X). 181Error: 182 between(1, 4, S, X). (Error 4) 183 between(1, 4, 0.1, X). (Error 5) 184 between(1, 4, 0, X). (Error 6) 185 between(1, 4, 1, a). (Error 24) 186 187 188 189", 190 see_also:[]]). 191 192:- comment(ceiling / 2, [ 193 summary:"Unifies Result with the least integral value that is greater than or equal to 194Number and of the same numeric type as Number. 195 196", 197 amode:(ceiling(+,-) is det), 198 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 199 arithmetic expressions. So the call to ceiling(Number, Result) is 200 equivalent to 201<PRE> 202 Result is ceiling(Number) 203</PRE> 204 which should be preferred. 205<P> 206 This operation works on all numeric types. The result value is the 207 smallest integral value that is greater than Number (rounding up 208 towards positive infinity). 209<P> 210 The result type is the same as the argument type. To convert the 211 type to integer, use integer/2. 212<P> 213 In coroutining mode, if Number is uninstantiated, the call to ceiling/2 214 is delayed until this variable is instantiated. 215 216<P> 217"), 218 args:["Number" : "A number.", "Result" : "A variable or number."], 219 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 220 eg:" 221Success: 222 ceiling(1.8, 2.0). 223 ceiling(-1.8, -1.0). 224 ceiling(5, 5). 225 ceiling(-6.4, Result). (gives Result = -6.0) 226Fail: 227 ceiling(0.0, 1.0). 228 ceiling(0.5, 0). 229 ceiling(1, r). 230Error: 231 ceiling(A, 6.0). (Error 4). 232 ceiling(4 + 2.3, 6.0). (Error 24). 233 234 235 236", 237 see_also:[(is) / 2, floor / 2, round/2, truncate/2, integer/2]]). 238 239:- comment(clrbit / 3, [ 240 summary:"Result is Number with the Index'th bit cleared. 241 242", 243 amode:(clrbit(+,+,-) is det), 244 desc:html(" Clear the Index'th bit in Number giving Result. The least significant 245 bit has index zero. Two's complement representation is assumed. 246 This predicate is used by the ECLiPSe compiler to expand evaluable 247 arithmetic expressions. So the call to clrbit(Number, Index, Result) is 248 equivalent to 249<PRE> 250 Result is clrbit(Number, Index) 251</PRE> 252 which should be preferred. 253 254<P> 255 In coroutining mode, if Number or Index are uninstantiated, the call 256 is delayed until these variables are instantiated. 257 258<P> 259"), 260 args:["Number" : "Integer.", "Index" : "Non-negative integer.", "Result" : "A variable or integer."], 261 exceptions:[4 : "Number or Index is not instantiated (non-coroutining mode only).", 5 : "Number or Index is a number but not an integer.", 262 24 : "Number or Index is not of a numeric type."], 263 eg:" 264Success: 265 clrbit(15, 3, 7). 266 clrbit(40, 3, X). gives X=32. 267 X is clrbit(setbit(0,5),5). gives X=0. 268 269 270 271", 272 see_also:[(is) / 2, setbit / 3, getbit / 3]]). 273 274:- comment(denominator / 2, [ 275 summary:"Extracts the denominator of the rational Number and unifies the resulting 276integer with Result. 277 278", 279 amode:(denominator(+,-) is det), 280 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 281 arithmetic expressions. So the call to denominator(Number, Result) is 282 equivalent to 283<PRE> 284 Result is denominator(Number) 285</PRE> 286 which should be preferred. 287<P> 288 In coroutining mode, if Number is uninstantiated, the call to 289 denominator/2 is delayed until this variable is instantiated. 290 291<P> 292"), 293 args:["Number" : "An integer or rational number.", "Result" : "A variable or integer."], 294 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 5 : "Number is a float or breal.", 24 : "Number is not of a numeric type."], 295 eg:" 296Success: 297 denominator(3_4, 4). 298 denominator(9_12, 4). 299 denominator(-3_4, 4). 300 denominator(25, 1). 301Fail: 302 denominator(3_4, 3). 303 denominator(3.1, 3). 304 denominator(3_4, 3_1). 305 denominator(3_4, r). 306Error: 307 denominator(A, 3). (Error 4). 308 denominator(1_3 + 3_4, 12). (Error 24). 309 310 311 312", 313 see_also:[(is) / 2, numerator / 2, rational / 2]]). 314 315:- comment(eval / 2, [ 316 summary:"Used to evaluate eval/1 terms in arithmetic expressions.", 317 amode:(eval(+,-) is det), 318 desc:html("\ 319 This is one of the predicates used by the ECLiPSe compiler to expand 320 arithmetic expressions. If an expression contains a subexpression that 321 is not known at compile time, it must be wrapped in eval/1, e.g. 322<PRE> 323 X is eval(Expr)+1 324</PRE> 325 This will be compiled into the sequence 326<PRE> 327 eval(Expr,T1), +(T1,1,X) 328</PRE> 329 and eval/2 will interpret the expression Expr at runtime. 330"), 331 args:["Expression" : "An arithmetic expression.", "Result" : "A variable or a number."], 332 exceptions:[4 : "Expression is uninstantiated.", 333 21 : "An evaluation predicate in the expression is not defined.", 334 24 : "Expression is not a valid arithmetic expression."], 335 eg:" 336 337 338 339", 340 see_also:[(is)/2]]). 341 342:- comment(floor / 2, [ 343 summary:"Unifies Result with the greatest integral value that is less or equal than 344Number and of the same numeric type as Number. 345 346", 347 amode:(floor(+,-) is det), 348 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 349 arithmetic expressions. So the call to floor(Number, Result) is 350 equivalent to 351<PRE> 352 Result is floor(Number) 353</PRE> 354 which should be preferred for portability. 355<P> 356 This operation works on all numeric types. The result value is the 357 largest integral value that is smaller that Number (rounding down 358 towards minus infinity). 359<P> 360 The result type is the same as the argument type. To convert the 361 type to integer, use integer/2. 362<P> 363 In coroutining mode, if Number is uninstantiated, the call to floor/2 364 is delayed until this variable is instantiated. 365 366<P> 367"), 368 args:["Number" : "A number.", "Result" : "A variable or number."], 369 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 370 eg:" 371Success: 372 floor(1.8, 1.0). 373 floor(-1.8, -2.0). 374 floor(5, 5). 375 floor(-6.4, Result). (gives Result = -7.0) 376Fail: 377 floor(1.0, 0.0). 378 floor(0.5, 0). 379 floor(1, r). 380Error: 381 floor(A, 6.0). (Error 4). 382 floor(4 + 2.3, 6.0). (Error 24). 383 384 385 386", 387 see_also:[(is) / 2, ceiling/2, round/2, truncate/2, integer/2]]). 388 389:- comment(truncate / 2, [ 390 summary:"Unifies Result with the closest integer value between 0 and 391Number, and of the same numeric type as Number. 392 393", 394 amode:(truncate(+,-) is det), 395 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 396 arithmetic expressions. So the call to truncate(Number, Result) is 397 equivalent to 398<PRE> 399 Result is truncate(Number) 400</PRE> 401 which should be preferred for portability. 402<P> 403 This operation works on all numeric types. The result value is the 404 closest integral value that lies between 0 and Number (rounding 405 towards zero). 406<P> 407 The result type is the same as the argument type. To convert the 408 type to integer, use integer/2. 409<P> 410 In coroutining mode, if Number is uninstantiated, the call to truncate/2 411 is delayed until this variable is instantiated. 412<P> 413"), 414 args:["Number" : "A number.", "Result" : "A variable or number."], 415 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 416 eg:" 417Success: 418 X is truncate(1.8). (gives Result = 1.0) 419 420 truncate(1.8, 1.0). 421 truncate(-1.8, -1.0). 422 truncate(5, 5). 423 truncate(-6.4, Result). (gives Result = -6.0) 424Fail: 425 truncate(1.0, 0.0). 426 truncate(0.5, 0). 427 truncate(1, r). 428Error: 429 truncate(A, 6.0). (Error 4). 430 truncate(4 + 2.3, 6.0). (Error 24). 431", 432 see_also:[(is) / 2, floor/2, ceiling/2, round/2, integer/2, fix/2]]). 433 434:- comment(getbit / 3, [ 435 summary:"Result is the Index'th bit of Number. 436 437", 438 amode:(getbit(+,+,-) is det), 439 desc:html(" Returns the Index'th bit of Number, assuming binary two's complement 440 representation. The least significant bit has index zero. 441 The result is either 0 or 1. 442 This predicate is used by the ECLiPSe compiler to expand evaluable 443 arithmetic expressions. So the call to getbit(Number, Index, Result) is 444 equivalent to 445<PRE> 446 Result is getbit(Number, Index) 447</PRE> 448 which should be preferred. 449<P> 450 In coroutining mode, if Number or Index are uninstantiated, the call 451 is delayed until these variables are instantiated. 452 453<P> 454"), 455 args:["Number" : "Integer.", "Index" : "Non-negative integer.", "Result" : "A variable or integer."], 456 exceptions:[4 : "Number or Index is not instantiated (non-coroutining mode only).", 5 : "Number or Index is a number but not an integer.", 457 24 : "Number or Index is not of a numeric type."], 458 eg:" 459Success: 460 getbit(10, 3, 1). 461 getbit(10, 2, 0). 462 getbit(10, 99, 0). 463 464 465 466", 467 see_also:[(is) / 2, clrbit / 3, setbit / 3]]). 468 469:- comment((is) / 2, [ 470 summary:"Evaluates the arithmetic expression Expression and unifies the resulting 471value with Result. 472 473", 474 template:"?Result is +Expression", 475 amode:(is(-,+) is det), 476 desc:html("\ 477 is/2 is used to evaluate arithmetic expressions. An arithmetic 478 expression is a Prolog term that is made up of variables, numbers, 479 atoms and compound terms. If it contains variables, they must be 480 bound to numbers at the time the evaluation takes place. 481<P> 482 ECLiPSe distinguishes four types of numbers: 483<DL> 484 <DT><STRONG>integers</STRONG> e.g. 12345 485 <DD>Integers can be of arbitrary magnitude. Integers that fit 486 into the word size of the machine are handled more efficiently. 487 <DT><STRONG>rationals</STRONG> e.g. 3_4 488 <DD>Rational numbers represent the corresponding mathematical 489 notion (the ratio of two integers). The operations defined on 490 rationals give precise (rational) results. 491 <DT><STRONG>floats</STRONG> e.g. 3.1415 492 <DD>Floats are an imprecise approximation of real numbers. 493 They are represented as IEEE double precision floats. Floating 494 point operations are typically subject to rounding errors. 495 Undefined operations produce infinity results if possible, 496 otherwise exceptions (not NaNs). 497 <DT><STRONG>bounded reals (breal)</STRONG> e.g. 3.1415__3.1416 498 <DD>Bounded reals are a safe representation of real numbers, 499 characterised by a lower and upper bound in floating point format. 500 Operations on breals are safe in the sense that the resulting 501 bounds always enclose the precise result (interval arithmetic). 502</DL> 503 Numbers of different types do not unify! 504<P> 505 The system performs automatic type conversions in the direction 506<BLOCKQUOTE> 507 integer -> rational -> float -> breal. 508</BLOCKQUOTE> 509 These conversions are done (i) to make the types of two input 510 arguments equal and (ii) to lift the type of an input argument to 511 the one expected by the function. The result type is the lifted 512 input type, unless otherwise specified. 513<P> 514 A table of predefined arithmetic functions is given below. A predefined 515 function is evaluated by first evaluating its arguments and then calling 516 the corresponding evaluation predicate. The evaluation predicate 517 belonging to a compound term func(a_1,..,a_n) is the predicate 518 func/(n+1). It receives a_1,..,a_n as its first n arguments and returns 519 a numeric result as its last argument. This result is then used in 520 the arithmetic computation. 521<P> 522 This evaluation mechanism outlined above is not restricted to the 523 predefined arithmetic functors shown in the table. In fact it works for 524 all atoms and compound terms. It is therefore possible to define a new 525 arithmetic operation by just defining an evaluation predicate. 526 Similarly, many ECLiPSe built-ins return numbers in the last argument 527 and can thus be used as evaluation predicates (e.g.cputime/1, random/1, 528 string_length/2, ...). Note that recursive evaluation of arguments is 529 only done for the predefined arithmetic functions, for the others the 530 arguments are simply passed to the evaluation predicate. 531<P> 532 Most arithmetic errors will not be reported in is/2, but in the 533 evaluation predicate where it occurred. 534<PRE> 535 Function Description Argument Types Result Type 536 ---------------------------------------------------------------------------- 537 + E unary plus number number 538 - E unary minus number number 539 abs(E) absolute value number number 540 sgn(E) sign value number integer 541 floor(E) round down number number 542 ceiling(E) round up number number 543 round(E) round to nearest number number 544 truncate(E) round towards zero number number 545 546 E1 + E2 addition number x number number 547 E1 - E2 subtraction number x number number 548 E1 * E2 multiplication number x number number 549 E1 / E2 division number x number see below 550 E1 // E2 integer division truncated integer x integer integer 551 E1 rem E2 integer remainder integer x integer integer 552 E1 div E2 integer division floored integer x integer integer 553 E1 mod E2 integer modulus integer x integer integer 554 gcd(E1,E2) greatest common divisor integer x integer integer 555 lcm(E1,E2) least common multiple integer x integer integer 556 E1 ^ E2 power operation number x number number 557 min(E1,E2) minimum of 2 values number x number number 558 max(E1,E2) maximum of 2 values number x number number 559 560 \\ E bitwise complement integer integer 561 E1 /\\ E2 bitwise conjunction integer x integer integer 562 E1 \\/ E2 bitwise disjunction integer x integer integer 563 xor(E1,E2) bitwise exclusive or integer x integer integer 564 E1 >> E2 shift E1 right by E2 bits integer x integer integer 565 E1 << E2 shift E1 left by E2 bits integer x integer integer 566 setbit(E1,E2) set bit E2 in E1 integer x integer integer 567 clrbit(E1,E2) clear bit E2 in E1 integer x integer integer 568 getbit(E1,E2) get of bit E2 in E1 integer x integer integer 569 570 sin(E) trigonometric function number float or breal 571 cos(E) trigonometric function number float or breal 572 tan(E) trigonometric function number float or breal 573 asin(E) trigonometric function number float 574 acos(E) trigonometric function number float 575 atan(E) trigonometric function number float or breal 576 atan(E1,E2) trigonometric function number x number float or breal 577 exp(E) exponential function ex number float or breal 578 ln(E) natural logarithm number float or breal 579 sqrt(E) square root number float or breal 580 pi the constant pi --- float 581 e the constant e --- float 582 583 fix(E) truncate to integer number integer 584 integer(E) convert to integer number integer 585 float(E) convert to float number float 586 rational(E) convert to rational number rational 587 rationalize(E) convert to rational number rational 588 numerator(E) numerator of rational integer or rational integer 589 denominator(E) denominator of rational integer or rational integer 590 breal(E) convert to bounded real number breal 591 breal_from_bounds(Lo, Hi) 592 make bounded real from bounds number x number breal 593 breal_min(E) lower bound of bounded real number float 594 breal_max(E) upper bound of bounded real number float 595 596 sum(Es) sum of list elements list number 597 min(Es) minimum of list elements list number 598 max(Es) maximum of list elements list number 599 eval(E) eval runtime expression term number 600</PRE> 601 The division operator / yields either a rational or a float result, 602 depending on the value of the global flag prefer_rationals. The same is 603 true for the result of ^ if an integer is raised to a negative integral 604 power. 605<P> 606 The relation between integer divisions // and div, and remainder and 607 modulus operations rem and mod is as follows: 608<PRE> 609 X =:= (X rem Y) + (X // Y) * Y. 610 X =:= (X mod Y) + (X div Y) * Y. 611</PRE> 612"), 613 args:["Result" : "A variable or a number.", "Expression" : "An arithmetic expression."], 614 fail_if:"Fails if a user-defined evaluation predicate fails", 615 exceptions:[4 : "Expression is uninstantiated", 616 21 : "An evaluation predicate in the expression is not defined.", 617 24 : "Expression is not a valid arithmetic expression."], 618 eg:" 619 Success: 620 103 is 3 + 4 * 5 ^ 2. 621 X is asin(sin(pi/4)). (gives X = 0.785398). 622 Y is 2 * 3, X is 4 + Y. (gives X = 10, Y = 6). 623 X is string_length(\"four\") + 1. (gives X = 5). 624 625 [eclipse]: [user]. 626 myconst(4.56). 627 user compiled 40 bytes in 0.02 seconds 628 yes. 629 [eclipse]: 5.56 is myconst + 1. 630 yes. 631Fail: 632 3.14 is pi. % different values 633 atom is 4. 634 1 is 1.0. 635Error: 636 X is _. (Error 4) 637 X is \"s\". (Error 24) 638 639 [eclipse]: X is undef(1). 640 calling an undefined procedure undef(1, _g63) in ... 641 642 [eclipse]: X is 3 + Y. 643 instantiation fault in +(3, _g45, _g53) 644 645 646 647", 648 see_also:[get_flag / 2, set_flag / 3, (+) / 2, (-) / 2, abs / 2, 649 sgn / 2, ceiling / 2, floor / 2, round / 2, truncate/2, 650 (+) / 3, (-) / 3, (*) / 3, (/) / 3, (//) / 3, (rem)/3, (div)/3, 651 (mod) / 3, (^) / 3, min / 3, max / 3, gcd/3, lcm/3, 652 (\) / 2, (/\) / 3, (\/) / 3, xor / 3, (>>) / 3, (<<) / 3, 653 clrbit / 3, getbit / 3, setbit / 3, sin / 2, cos / 2, tan / 2, 654 asin / 2, acos / 2, atan / 2, atan/3, exp / 2, ln / 2, sqrt / 2, 655 fix / 2, integer/2, float / 2, rational / 2, rationalize/2, 656 numerator / 2, denominator / 2, 657 breal/2, breal_from_bounds/3, breal_min/2, breal_max/2, sum/2, 658 min/2, max/2, 659 eval/2, integer/1, float/1, rational/1, breal/1, number/1]]). 660 661:- comment(numerator / 2, [ 662 summary:"Extracts the numerator of the rational Number and unifies the resulting 663integer with Result. 664 665", 666 amode:(numerator(+,-) is det), 667 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 668 arithmetic expressions. So the call to numerator(Number, Result) is 669 equivalent to 670<PRE> 671 Result is numerator(Number) 672</PRE> 673 which should be preferred. 674<P> 675 In coroutining mode, if Number is uninstantiated, the call to 676 numerator/2 is delayed until this variable is instantiated. 677 678<P> 679"), 680 args:["Number" : "An integer or rational number.", "Result" : "A variable or integer."], 681 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 5 : "Number is a float or breal.", 682 24 : "Number is not of a numeric type."], 683 eg:" 684Success: 685 numerator(3_4, 3). 686 numerator(9_12, 3). 687 numerator(-3_4, -3). 688 numerator(25, 25). 689Fail: 690 numerator(3_4, 4). 691 numerator(3_4, 3_1). 692 numerator(3_4, r). 693Error: 694 numerator(A, 3). (Error 4). 695 numerator(3.1, 3). (Error 5). 696 numerator(1_3 + 3_4, 13). (Error 24). 697 698 699 700", 701 see_also:[(is) / 2, denominator / 2, rational / 2]]). 702 703:- comment(rational / 2, [ 704 summary:"Converts Number into a rational number and unifies it with Result. 705 706", 707 amode:(rational(+,-) is det), 708 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 709 arithmetic expressions. So the call to rational(Number, Result) is 710 equivalent to 711<PRE> 712 Result is rational(Number) 713</PRE> 714 which should be preferred. 715<P> 716 When Number is an integer, Result is a rational with denominator 1. 717<P> 718 When Number is already a rational, Result is identical to Number. 719<P> 720 When Number is a float, Result is a rational whose value is exactly equal 721 to the value of the floating-point number. Since floats are usually 722 approximations of the intended value, the results may look unintuitive 723 and have unnecessarily large numerators and denominators. Use rationalize/2 724 to produce the most compact rational that still converts back into the 725 original float. rational/2 is usually faster than rationalize/2. 726<P> 727 Bounded reals cannot be converted to rationals. 728<P> 729 In coroutining mode, if Number is uninstantiated, the call to 730 rational/2 is delayed until this variable is instantiated. 731"), 732 args:["Number" : "A number.", "Result" : "A variable or rational number."], 733 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 734 24 : "Number is not of a numeric type.", 735 141 : "Number is a bounded real"], 736 eg:" 737Success: 738 rational(25, 25_1). 739 rational(1.5, 3_2). 740 rational(3_4,3_4). 741 rational(9_12,3_4). 742 rational(-6, Result). (gives Result = -6_1) 743 rational(0.1, Result). (gives Result = 3602879701896397_36028797018963968) 744Fail: 745 rational(1, 2_1). 746 rational(3, 3). 747 rational(1, r). 748Error: 749 rational(A, 1_3). (Error 4). 750 rational(4 + 2, 6_1). (Error 24). 751 rational(0.9__1.1, X). (Error 141). 752 753 754 755", 756 see_also:[rationalize/2, (is) / 2]]). 757 758:- comment(rationalize / 2, [ 759 summary:"Converts Number into a compact rational number and unifies it with Result. 760 761", 762 amode:(rationalize(+,-) is det), 763 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 764 arithmetic expressions. So the call to rationalize(Number, Result) is 765 equivalent to 766<PRE> 767 Result is rationalize(Number) 768</PRE> 769 which should be preferred. 770<P> 771 When Number is an integer, Result is a rational with denominator 1. 772<P> 773 When Number is already a rational, Result is identical to Number. 774<P> 775 When Number is a float, Result is a rational whose value approximates 776 the value of the float to the accuracy of the float representation. 777 rationalize/2 usually produces more compact rationals that rational/2. 778 Both rationalize/2 and rational/2 produce results that convert back into 779 the original float. rational/2 is usually faster than rationalize/2. 780<P> 781 Bounded reals cannot be converted to rationals. 782<P> 783 In coroutining mode, if Number is uninstantiated, the call to 784 rationalize/2 is delayed until this variable is instantiated. 785"), 786 args:["Number" : "A number.", "Result" : "A variable or rational number."], 787 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 788 24 : "Number is not of a numeric type.", 789 141 : "Number is a bounded real"], 790 eg:" 791Success: 792 rationalize(25, 25_1). 793 rationalize(1.5, 3_2). 794 rationalize(3_4,3_4). 795 rationalize(9_12,3_4). 796 rationalize(-6, Result). (gives Result = -6_1) 797 rationalize(0.1, Result). (gives Result = 1_10) 798Fail: 799 rationalize(1, 2_1). 800 rationalize(3, 3). 801 rationalize(1, r). 802Error: 803 rationalize(A, 1_3). (Error 4). 804 rationalize(4 + 2, 6_1). (Error 24). 805 rationalize(0.9__1.1, X). (Error 141). 806 807 808 809", 810 see_also:[rational/2, (is) / 2]]). 811 812:- comment(setbit / 3, [ 813 summary:"Result is Number with the Index'th bit set. 814 815", 816 amode:(setbit(+,+,-) is det), 817 desc:html(" Set the Index'th bit in Number giving Result. The least significant 818 bit has index zero. Two's complement representation is assumed. 819 This predicate is used by the ECLiPSe compiler to expand evaluable 820 arithmetic expressions. So the call to setbit(Number, Index, Result) is 821 equivalent to 822<PRE> 823 Result is setbit(Number, Index) 824</PRE> 825 which should be preferred. 826<P> 827 In coroutining mode, if Number or Index are uninstantiated, the call 828 is delayed until these variables are instantiated. 829"), 830 args:["Number" : "Integer.", "Index" : "Non-negative integer.", "Result" : "A variable or integer."], 831 exceptions:[4 : "Number or Index is not instantiated (non-coroutining mode only).", 5 : "Number or Index is a number but not an integer.", 832 24 : "Number or Index is not of a numeric type."], 833 eg:" 834Success: 835 setbit(0, 3, 8). 836 setbit(1, 8, X). gives X=257. 837 X is setbit(setbit(0,3),5). gives X=40. 838 839 840 841", 842 see_also:[(is) / 2, clrbit / 3, getbit / 3]]). 843 844:- comment(sgn / 2, [ 845 summary:"Unifies Result with the sign of Number which is either -1, 0 or 1. 846 847", 848 amode:(sgn(+,-) is det), 849 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 850 arithmetic expressions. So the call to sgn(Number, Result) is 851 equivalent to 852<PRE> 853 Result is sgn(Number) 854</PRE> 855 which should be preferred for portability. 856<P> 857 sgn/2 gives the integer -1 if Number is negative, 0 if it is zero and 1 858 if it is greater than zero. It is always true that 859<PRE> 860 X =:= sgn(X) * abs(X) 861</PRE> 862 In coroutining mode, if Number is uninstantiated, the call to sgn/2 is 863 delayed until this variable is instantiated. 864"), 865 args:["Number" : "A number.", "Result" : "A variable or an integer."], 866 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 867 eg:" 868Success: 869 sgn(42, 1). 870 sgn(-5, Result). (gives Result = -1) 871 sgn(-6.2, Result). (gives Result = -1) 872 sgn(0.0, 0). 873Fail: 874 sgn(1, 0). 875 sgn(1, 1.0). 876 sgn(1, r). 877Error: 878 sgn(A, 6). (Error 4). 879 sgn(4 + 2, 6). (Error 24). 880 881 882 883", 884 see_also:[(is) / 2]]). 885 886:- comment(sum / 2, [ 887 summary:"Evaluates the the arithmetic expressions in ExprList and unifies their sum 888with Result. 889 890", 891 amode:(sum(+,-) is det), 892 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 893 arithmetic expressions. So the call to sum(ExprList, Result) is 894 equivalent to 895<PRE> 896 Result is sum(ExprList) 897</PRE> 898 which should be preferred. 899<P> 900 In coroutining mode, if the list is only partly instantiated, the 901 predicate delays until the list is complete. 902"), 903 args:["ExprList" : "A list of arithmetic expressions.", "Result" : "A variable or number."], 904 exceptions:[4 : "ExprList is a partial list (non-coroutining mode only).", 5 : "ExprList is not a proper list."], 905 eg:" 906Success: 907 X is sum([1,2,3]). % gives X = 6 908 909 910 911", 912 see_also:[(is) / 2, (+) / 3]]). 913 914:- comment(min / 2, [ 915 summary:"Evaluates the the arithmetic expressions in ExprList and unifies their minimum 916with Result. 917 918", 919 amode:(min(+,-) is det), 920 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 921 arithmetic expressions. So the call to min(ExprList, Result) is 922 equivalent to 923<PRE> 924 Result is min(ExprList) 925</PRE> 926 which should be preferred. 927<P> 928 In coroutining mode, if the list is only partly instantiated, the 929 predicate delays until the list is complete. 930"), 931 args:["ExprList" : "A list of arithmetic expressions.", "Result" : "A variable or number."], 932 exceptions:[4 : "ExprList is a partial list (non-coroutining mode only).", 5 : "ExprList is not a proper list."], 933 eg:" 934Success: 935 X is min([1,2,3]). % gives X = 1 936 X is min([1,2.0,3]). % gives X = 1.0 937", 938 see_also:[(is) / 2, min/3, max/2]]). 939 940:- comment(max / 2, [ 941 summary:"Evaluates the the arithmetic expressions in ExprList and unifies their maximum 942with Result. 943 944", 945 amode:(max(+,-) is det), 946 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 947 arithmetic expressions. So the call to max(ExprList, Result) is 948 equivalent to 949<PRE> 950 Result is max(ExprList) 951</PRE> 952 which should be preferred. 953<P> 954 In coroutining mode, if the list is only partly instantiated, the 955 predicate delays until the list is complete. 956"), 957 args:["ExprList" : "A list of arithmetic expressions.", "Result" : "A variable or number."], 958 exceptions:[4 : "ExprList is a partial list (non-coroutining mode only).", 5 : "ExprList is not a proper list."], 959 eg:" 960Success: 961 X is max([1,2,3]). % gives X = 3 962 X is max([1,2.0,3]). % gives X = 3.0 963", 964 see_also:[(is) / 2, max/3, min/2]]). 965 966:- comment(abs / 2, [ 967 summary:"Unifies the absolute value of Number with Result. 968 969", 970 amode:(abs(+,-) is det), 971 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 972 arithmetic expressions. So the call to abs(Number, Result) is 973 equivalent to 974<PRE> 975 Result is abs(Number) 976</PRE> 977 which should be preferred for portability. 978<P> 979 Number and Result have to be of the same type. 980<P> 981 In coroutining mode, if Number is uninstantiated, the call to abs/2 is 982 delayed until this variable is instantiated. 983"), 984 args:["Number" : "A number.", "Result" : "A variable or a number."], 985 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 986 eg:" 987Success: 988 abs(1, 1). 989 abs(-5, Result). (gives Result = 5) 990 abs(-6.2, Result). (gives Result = 6.2) 991Fail: 992 abs(1, 0). 993 abs(1, 1.0). 994 abs(-1.0, 1). 995 abs(1, r). 996Error: 997 abs(A, 6). (Error 4). 998 abs(4 + 2, 6). (Error 24). 999 1000 1001 1002", 1003 see_also:[(is) / 2]]). 1004 1005:- comment(acos / 2, [ 1006 summary:"Evaluates the trigonometric function acos(Number) and unifies the resulting 1007value with Result. 1008 1009", 1010 amode:(acos(+,-) is det), 1011 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1012 arithmetic expressions. So the call to acos(Number, Result) is 1013 equivalent to 1014<PRE> 1015 Result is acos(Number) 1016</PRE> 1017 which should be preferred for portability. 1018<P> 1019 In coroutining mode, if Number is uninstantiated, the call to acos/2 is 1020 delayed until this variable is instantiated. 1021"), 1022 args:["Number" : "A number.", "Result" : "A variable or float."], 1023 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 1024 24 : "Number is not of a numeric type.", 1025 20 : "Illegal arithmetic operation: Number is greater than 1 or less than -1.", 1026 141 : "Argument is of type breal"], 1027 eg:" 1028Success: 1029 acos(1.0, 0.0). 1030 acos(-0.5, Result). (gives Result = 2.0944) 1031 acos(0, Result). (gives Result = 1.5708) 1032Fail: 1033 acos(1, 1.0). 1034 acos(1, r). 1035 acos(1, 0). 1036Error: 1037 acos(A, 6.0). (Error 4). 1038 acos(2, Result). (Error 20). 1039 acos(4 - 3, 0.0). (Error 24). 1040 1041 1042 1043", 1044 see_also:[(is) / 2]]). 1045 1046:- comment((/\) / 3, [ 1047 summary:"Evaluates the bitwise conjunction Number1 /\\ Number2 and unifies the 1048resulting value with Result. 1049 1050", 1051 amode:(/\(+,+,-) is det), 1052 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1053 arithmetic expressions. So the call to /\\(Number1, Number2, Result) is 1054 equivalent to 1055<PRE> 1056 Result is Number1 /\\ Number2 1057</PRE> 1058 which should be preferred for portability. 1059<P> 1060 This operation behaves as if operating on an unlimited length two's 1061 complement representation. 1062<P> 1063 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 1064 to /\\/3 is delayed until these variables are instantiated. 1065"), 1066 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 1067 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 1068 5 : "Number1 or Number2 is a number but not an integer.", 24 : "Number1 or Number2 is not of a numeric type."], 1069 eg:" 1070Success: 1071 /\\(11, 7, 3). 1072 /\\(-11, 7, Result). (gives Result = 5) 1073Fail: 1074 /\\(1, 2, 3). 1075 /\\(5, 2, r). 1076 /\\(6, 2.0, 2.0). 1077Error: 1078 /\\(A, 2, 6). (Error 4). 1079 /\\(4 + 2, 2, 2). (Error 24). 1080 1081 1082 1083", 1084 see_also:[(is) / 2]]). 1085 1086:- comment(asin / 2, [ 1087 summary:"Evaluates the trigonometric function asin(Number) and unifies the resulting 1088value with Result. 1089 1090", 1091 amode:(asin(+,-) is det), 1092 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1093 arithmetic expressions. So the call to asin(Number, Result) is 1094 equivalent to 1095<PRE> 1096 Result is asin(Number) 1097</PRE> 1098 which should be preferred for portability. 1099<P> 1100 In coroutining mode, if Number is uninstantiated, the call to asin/2 is 1101 delayed until this variable is instantiated. 1102 1103<P> 1104"), 1105 args:["Number" : "A number.", "Result" : "A variable or float."], 1106 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 1107 24 : "Number is not of a numeric type.", 1108 20 : "Illegal arithmetic operation: Number is greater than 1 or less than -1.", 1109 141 : "Argument is of type breal"], 1110 eg:" 1111Success: 1112 asin(1.0, Result). (gives Result = 1.5708) 1113 asin(-0,5, Result). (gives Result = -0.523599) 1114Fail: 1115 asin(1, 0.0). 1116 asin(1, 3). 1117 asin(1, r). 1118Error: 1119 asin(A, 6.0). (Error 4). 1120 asin(2, Result). (Error 20). 1121 asin(4 + 2, -0.279415). (Error 24). 1122 1123 1124 1125", 1126 see_also:[(is) / 2]]). 1127 1128:- comment(atan / 2, [ 1129 summary:"Evaluates the trigonometric function atan(Number) and unifies the resulting 1130value with Result. 1131 1132", 1133 amode:(atan(+,-) is det), 1134 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1135 arithmetic expressions. So the call to atan(Number, Result) is 1136 equivalent to 1137<PRE> 1138 Result is atan(Number) 1139</PRE> 1140 which should be preferred for portability. 1141<P> 1142 In coroutining mode, if Number is uninstantiated, the call to atan/2 is 1143 delayed until this variable is instantiated. 1144 1145<P> 1146"), 1147 args:["Number" : "A number.", "Result" : "A variable, float or breal."], 1148 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 1149 eg:" 1150Success: 1151 atan(0.0, 0.0). 1152 atan(1.0, Result). (gives Result = 0.785398) 1153 atan(-8, Result). (gives Result = -1.44644) 1154Fail: 1155 atan(1, 0.0). 1156 atan(1.55741, 1). 1157 atan(5, r). 1158Error: 1159 atan(A, 6.0). (Error 4). 1160 atan(1 + 0.55741, 1.0). (Error 24). 1161 1162 1163 1164", 1165 see_also:[(is) / 2]]). 1166 1167:- comment(atan / 3, [ 1168 summary:"Computes the arc tangent function of two variables and unifies the resulting value with Result.", 1169 amode:(atan(+,+,-) is det), 1170 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1171 arithmetic expressions. So the call to atan(Y, X, Result) is 1172 equivalent to 1173<PRE> 1174 Result is atan(Y, X) 1175</PRE> 1176 which should be preferred for portability. 1177<P> 1178 It is similar to calculating the arc tangent of Y/X, except that the 1179 signs of both arguments are used to determine the quadrant of the result. 1180 The result lies in the interval -pi..pi. The operation is valid even if 1181 X is zero, in which case the result is pi/2 or -pi/2. One application 1182 is the conversion of cartesian to polar coordinates, where this function 1183 computes the angle component (in radians). 1184<P> 1185 In coroutining mode, if X or Y is uninstantiated, the call to atan/3 is 1186 delayed until both variables are instantiated. 1187 1188<P> 1189"), 1190 args:["Y" : "A number.", "X":"A number.", "Result" : "A variable, float or breal."], 1191 exceptions:[4 : "X or Y is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 1192 eg:" 1193Success: 1194 atan( 0.0, -1.0, Result). (gives Result = 3.141592) 1195 atan( 1.0, -1.0, Result). (gives Result = 2.356194) 1196 atan( 1.0, 0.0, Result). (gives Result = 1.570796) 1197 atan( 1.0, 1.0, Result). (gives Result = 0.785398) 1198 atan( 0.0, 0.0, Result). (gives Result = 0.0) 1199 atan(-1.0, 1.0, Result). (gives Result = -0.785398) 1200 atan(-1.0, 0.0, Result). (gives Result = -1.570796) 1201 atan(-1.0, -1.0, Result). (gives Result = -2.356194) 1202 atan(-0.0, -1.0, Result). (gives Result = -3.141592) 1203 1204 atan( 7.0, 7.0, Result). (gives Result = 0.785398) 1205 1206Fail: 1207 atan(1.55741, 0.0, 1). 1208 1209Error: 1210 atan(A, 0.0, 6.0). (Error 4). 1211 atan(1 + 0.55741, 1.0, R). (Error 24). 1212", 1213 see_also:[(is) / 2]]). 1214 1215:- comment((\) / 2, [ 1216 summary:"Evaluates the bitwise complement of Number and unifies the resulting value 1217with Result. 1218 1219", 1220 amode:(\(+,-) is det), 1221 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1222 arithmetic expressions. So the call to \\(Number, Result) is equivalent 1223 to 1224<PRE> 1225 Result is \\Number 1226</PRE> 1227 which should be preferred for portability. 1228<P> 1229 This operation behaves as if operating on an unlimited length two's 1230 complement representation. 1231<P> 1232 In coroutining mode, if Number is uninstantiated, the call to \\/2 is 1233 delayed until this variable is instantiated. 1234 1235<P> 1236"), 1237 args:["Number" : "Integer.", "Result" : "A variable or integer."], 1238 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 5 : "Number is a number but not an integer.", 24 : "Number is not of a numeric type."], 1239 eg:" 1240Success: 1241 \\(1, -2). 1242 \\(5, Result). (gives Result = -6) 1243 \\(-6, Result). (gives Result = 5) 1244Fail: 1245 \\(1, 0). 1246 \\(1, r). 1247Error: 1248 \\(A, 6). (Error 4). 1249 \\(0.0, 0.0). (Error 5). 1250 \\(4 + 2, -7). (Error 24). 1251 1252 1253 1254", 1255 see_also:[(is) / 2]]). 1256 1257:- comment(cos / 2, [ 1258 summary:"Evaluates the trigonometric function cos(Number) and unifies the resulting 1259value with Result. 1260 1261", 1262 amode:(cos(+,-) is det), 1263 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1264 arithmetic expressions. So the call to cos(Number, Result) is 1265 equivalent to 1266<PRE> 1267 Result is cos(Number) 1268</PRE> 1269 which should be preferred for portability. 1270<P> 1271 In coroutining mode, if Number is uninstantiated, the call to cos/2 is 1272 delayed until this variable is instantiated. 1273 1274<P> 1275"), 1276 args:["Number" : "A number.", "Result" : "A variable, float or breal."], 1277 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 1278 eg:" 1279Success: 1280 cos(0, 1.0). 1281 cos(1.2, Result). (gives Result = 0.362358) 1282 cos(-33, Result). (gives Result = -0.0132767) 1283Fail: 1284 cos(1, 0.0). 1285 cos(0, 1). 1286 cos(5, r). 1287Error: 1288 cos(A, 6.0). (Error 4). 1289 cos(4 + 2, 0.96017). (Error 24). 1290 1291 1292 1293", 1294 see_also:[(is) / 2]]). 1295 1296:- comment((/) / 3, [ 1297 summary:"Evaluates the quotient Number1 / Number2 and unifies the resulting value 1298with Result. 1299 1300", 1301 amode:(/(+,+,-) is det), 1302 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1303 arithmetic expressions. So the call to /(Number1, Number2, Result) is 1304 equivalent to 1305<PRE> 1306 Result is Number1 / Number2 1307</PRE> 1308 which should be preferred for portability. 1309<P> 1310 The result type of the division depends on the value of the global flag 1311 prefer_rationals. When it is off, the result is a float, 1312 when it is on, the result is a rational. In coroutining mode, if 1313 Number1 or Number2 are uninstantiated, the call to //3 is delayed until 1314 these variables are instantiated. 1315 1316<P> 1317"), 1318 args:["Number1" : "A number.", "Number2" : "A number.", "Result" : "A variable or float (resp. rational)."], 1319 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 24 : "Number1 or Number2 is not of a numeric type.", 20 : "Illegal arithmetic operation: division by 0"], 1320 eg:" 1321Success: 1322 /(10, 2, 5.0). 1323 /(10, -2.0, -5.0). 1324 /(9, 12, 3_4). (with set_flag(prefer_rationals, on)) 1325Fail: 1326 /(1, 2, 1.0). 1327 /(5, 2, r). 1328 /(6, 2, 3). 1329Error: 1330 /(A, 2, 6.0). (Error 4). 1331 /(2, 0, Result). (Error 20). 1332 /(4 + 2, 2, 12). (Error 24). 1333 1334 1335 1336", 1337 see_also:[(is) / 2, get_flag / 2, set_flag / 2]]). 1338 1339:- comment((=:=) / 2, [ 1340 summary:"Succeed if the value of Expr1 is equal to the value of Expr2. 1341 1342", 1343 template:"+Expr1 =:= +Expr2", 1344 amode:((+ =:= +) is semidet), 1345 desc:html(" Both arguments are evaluated and their types adjusted. Then the 1346 resulting numbers are compared. The predicate succeeds if the values of 1347 Expr1 and Expr2 are equal (beware of rounding errors when comparing 1348 floats). If the system is in coroutining mode and the arguments are not 1349 ground, this predicate delays until the expressions are fully 1350 instantiated. 1351<P> 1352 The predicate also delays when the comparison involves bounded reals, 1353 and the compared values overlap such that the result is undecidable. 1354<P> 1355"), 1356 args:["Expr1" : "An arithmetic expression", "Expr2" : "An arithmetic expression"], 1357 fail_if:"fails if the value of Expr1 is not equal to the value of Expr2", 1358 exceptions:[4 : "Expr1 or Expr2 is a variable (non-coroutining mode only).", 5 : "Expr1 or Expr2 is not an arithmetic expression."], 1359 eg:" 1360 Success: 1361 5 - 2 =:= 6 / 2. 1362 1 =:= sin(pi/2). % 1 converted to 1.0 1363 Fail: 1364 2 + 3 =:= 2 * 3. 1365 Error: 1366 _ =:= 0. (Error 4) 1367 \"s\" =:= 0. (Error 5) 1368 1369 1370 1371", 1372 see_also:[_:(=:=)/2, (is) / 2, (<) / 2, (=\=) / 2, (>=) / 2, (=<) / 2, (>) / 2]]). 1373 1374:- comment(exp / 2, [ 1375 summary:"Evaluates the exponential function exp(Number) (\"e to the power of Number\") 1376and unifies the resulting value with Result. 1377 1378", 1379 amode:(exp(+,-) is det), 1380 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1381 arithmetic expressions. So the call to exp(Number, Result) is 1382 equivalent to 1383<PRE> 1384 Result is exp(Number) 1385</PRE> 1386 which should be preferred for portability. 1387<P> 1388 In coroutining mode, if Number is uninstantiated, the call to exp/2 is 1389 delayed until this variable is instantiated. 1390 1391<P> 1392"), 1393 args:["Number" : "A number.", "Result" : "A variable, float or breal."], 1394 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 1395 eg:" 1396Success: 1397 exp(0.0, Result). (gives Result = 1.0) 1398 exp(-6, Result). (gives Result = 0.00247875) 1399Fail: 1400 exp(1, 0.0). 1401 exp(0, 1). 1402 exp(1, r). 1403Error: 1404 exp(A, 6.0). (Error 4). 1405 exp(4 + 2, 403.429). (Error 24). 1406 1407 1408 1409", 1410 see_also:[(is) / 2]]). 1411 1412:- comment(fix / 2, [ 1413 summary:"Unifies the integer part of Number with Result (Truncation towards zero). 1414 1415", 1416 amode:(fix(+,-) is det), 1417 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1418 arithmetic expressions. So the call to fix(Number, Result) is 1419 equivalent to 1420<PRE> 1421 Result is fix(Number) 1422</PRE> 1423 which should be preferred for portability. 1424<P> 1425 This function is deprecated. For clearer code, please use 1426<PRE> 1427 Result is integer(truncate(Number)). 1428</PRE> 1429<P> 1430 In coroutining mode, if Number is uninstantiated, the call to fix/2 is 1431 delayed until this variable is instantiated. 1432 1433<P> 1434"), 1435 args:["Number" : "A number.", "Result" : "A variable or integer."], 1436 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 1437 5 : "Number is of type breal.", 1438 24 : "Number is not of a numeric type."], 1439 eg:" 1440Success: 1441 fix(1.5, 1). 1442 fix(-6.4, -6). 1443Fail: 1444 fix(1, 0). 1445 fix(0.0, 0.0). 1446 fix(1, r). 1447Error: 1448 fix(A, 6.0). (Error 4). 1449 fix(4 + 2.3, 6). (Error 24). 1450 1451 1452 1453", 1454 see_also:[(is) / 2, integer/2, truncate/2, floor/2, ceiling/2, round/2]]). 1455 1456:- comment(integer / 2, [ 1457 summary:"Convert an integral number of any type to an integer", 1458 amode:(integer(+,-) is det), 1459 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1460 arithmetic expressions. So the call to integer(Number, Result) is 1461 equivalent to 1462<PRE> 1463 Result is integer(Number) 1464</PRE> 1465 which should be preferred for portability. 1466<P> 1467 This is a pure type conversion operation. If Number has an integral value 1468 of any type, Result is that same value, but represented as an integer. 1469 If Number does not have an integral value, an exception is raised. 1470 This function should therefore normally be applied to the result of 1471 one of the rounding operations floor, ceiling, round or truncate. 1472<P> 1473 In coroutining mode, if Number is uninstantiated, the call to integer/2 is 1474 delayed until this variable is instantiated. 1475<P> 1476"), 1477 args:["Number" : "A number.", "Result" : "A variable or integer."], 1478 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 1479 5 : "Number is of type breal.", 1480 20 : "Number is not integral.", 1481 24 : "Number is not of a numeric type."], 1482 eg:" 1483Success: 1484 X is integer(5.0). (gives X = 5) 1485 1486 integer(5, 5). 1487 integer(5.0, 5). 1488 integer(5_1, 5). 1489 integer(5.0__5.0, 5). 1490 1491Fail: 1492 integer(0.0, 0.0). 1493 integer(1, r). 1494 1495Error: 1496 integer(1.1, X). (Error 20) 1497 integer(5_4, X). (Error 20) 1498 integer(0.99__1.01, X). (Error 20) 1499 integer(A, 6.0). (Error 4). 1500 integer(4 + 2.3, 6). (Error 24). 1501", 1502 see_also:[(is) / 2, floor/2, ceiling/2, round/2, truncate/2]]). 1503 1504:- comment(float / 2, [ 1505 summary:"Converts Number to float and unifies the resulting value with 1506Result. 1507 1508", 1509 amode:(float(+,-) is det), 1510 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1511 arithmetic expressions. So the call to float(Number, Result) is 1512 equivalent to 1513<PRE> 1514 Result is float(Number) 1515</PRE> 1516 which should be preferred for portability. 1517<P> 1518 In coroutining mode, if Number is uninstantiated, the call to float/2 1519 is delayed until this variable is instantiated. 1520 1521<P> 1522"), 1523 args:["Number" : "A number.", "Result" : "A variable or float."], 1524 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 1525 eg:" 1526Success: 1527 float(1, 1.0). 1528 float(-6, Result). (gives Result = -6.0) 1529Fail: 1530 float(1, 0.0). 1531 float(0, 0). 1532 float(1, r). 1533Error: 1534 float(A, 6.0). (Error 4). 1535 float(4 + 2, 6.0). (Error 24). 1536 1537 1538 1539", 1540 see_also:[(is) / 2]]). 1541 1542:- comment((>) / 2, [ 1543 summary:"Succeed if the value of Expr1 is greater than the value of Expr2. 1544 1545", 1546 template:"+Expr1 > +Expr2", 1547 amode:((+ > +) is semidet), 1548 desc:html(" Both arguments are evaluated and their types adjusted. Then the 1549 resulting numbers are compared. The predicate succeeds if the value of 1550 Expr1 is greater than the value of Expr2. If the system is in 1551 coroutining mode and the arguments are not ground, this predicate delays 1552 until the expressions are fully instantiated. 1553<P> 1554 The predicate also delays when the comparison involves bounded reals, 1555 and the compared values overlap such that the result is undecidable. 1556 1557<P> 1558"), 1559 args:["Expr1" : "An arithmetic expression", "Expr2" : "An arithmetic expression"], 1560 fail_if:"fails if the value of Expr1 is less or equal to the value of Expr2", 1561 exceptions:[4 : "Expr1 or Expr2 is a variable (non-coroutining mode only).", 5 : "Expr1 or Expr2 is not an arithmetic expression."], 1562 eg:" 1563 Success: 1564 5 - 1 > 6 / 2. 1565 1 > sin(pi/4). % 1 converted to 1.0 1566 Fail: 1567 2 + 3 > 2 * 3. 1568 Error: 1569 _ > 0. (Error 4) 1570 \"s\" > 0. (Error 5) 1571 1572 1573 1574", 1575 see_also:[_:(>)/2, (is) / 2, (=:=) / 2, (=\=) / 2, (>=) / 2, (<) / 2, (=<) / 2]]). 1576 1577:- comment((>=) / 2, [ 1578 summary:"Succeed if the value of Expr1 is greater than or equal to the value of 1579Expr2. 1580 1581", 1582 template:"+Expr1 >= +Expr2", 1583 amode:((+ >= +) is semidet), 1584 desc:html(" Both arguments are evaluated and their types adjusted. Then the 1585 resulting numbers are compared. The predicate succeeds if the value of 1586 Expr1 is greater than or equal to the value of Expr2. If the system is 1587 in coroutining mode and the arguments are not ground, this predicate 1588 delays until the expressions are fully instantiated. 1589<P> 1590 The predicate also delays when the comparison involves bounded reals, 1591 and the compared values overlap such that the result is undecidable. 1592 1593<P> 1594"), 1595 args:["Expr1" : "An arithmetic expression", "Expr2" : "An arithmetic expression"], 1596 fail_if:"fails if the value of Expr1 is less than the value of Expr2", 1597 exceptions:[4 : "Expr1 or Expr2 is a variable (non-coroutining mode only).", 5 : "Expr1 or Expr2 is not an arithmetic expression."], 1598 eg:" 1599 Success: 1600 5 - 1 >= 6 / 2. 1601 1 >= sin(pi/2). % 1 converted to 1.0 1602 Fail: 1603 2 + 3 >= 2 * 3. 1604 Error: 1605 _ >= 10. (Error 4) 1606 \"s\" >= 10. (Error 5) 1607 1608 1609 1610", 1611 see_also:[_:(>=)/2, (is) / 2, (=:=) / 2, (=\=) / 2, (<) / 2, (>) / 2, (=<) / 2]]). 1612 1613:- comment((//) / 3, [ 1614 summary:"Evaluates the integer quotient Number1 // Number2 and unifies the resulting 1615value with Result. 1616 1617", 1618 amode:(//(+,+,-) is det), 1619 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1620 arithmetic expressions. So the call to //(Number1, Number2, Result) is 1621 equivalent to 1622<PRE> 1623 Result is Number1 // Number2 1624</PRE> 1625 which should be preferred for portability. 1626<P> 1627 This division operates on integer arguments, and delivers an integer 1628 result rounded towards zero (truncated). The corresponding remainder 1629 is computed by the rem operation, such that the following equivalence 1630 always holds: 1631<PRE> 1632 X =:= (X rem Y) + (X // Y) * Y. 1633</PRE> 1634 The relationship with floating-point division is: 1635<PRE> 1636 X // Y =:= integer(truncate(X/Y)). 1637</PRE> 1638<P> 1639 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 1640 to (//)/3 is delayed until these variables are instantiated. 1641<P> 1642"), 1643 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 1644 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 5 : "Number1 or Number2 is a number but not an integer.", 24 : "Number1 or Number2 is not of a numeric type.", 20 : "Illegal arithmetic operation: division by 0"], 1645 eg:" 1646Success: 1647 X is 10 // 3. ( gives X = 3) 1648 1649 //( 10, 3, 3). 1650 //(-10, 3, -3). 1651 //( 10, -3, -3). 1652 //(-10, -3, 3). 1653 1654Fail: 1655 //(1, 2, 3). 1656 //(5, 2, 2.0). 1657 //(5, 2, r). 1658Error: 1659 //(A, 2, 6). (Error 4). 1660 //(6, 2.0, 3.0). (Error 5). 1661 //(2, 0, Result). (Error 20). 1662 //(4 + 2, 2, 12). (Error 24). 1663", 1664 see_also:[(is) / 2, (div)/3, (rem)/3]]). 1665 1666:- comment((div) / 3, [ 1667 summary:"Evaluates the integer quotient Number1 div Number2 and unifies the resulting 1668value with Result. 1669 1670", 1671 amode:(div(+,+,-) is det), 1672 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1673 arithmetic expressions. So the call to div(Number1, Number2, Result) is 1674 equivalent to 1675<PRE> 1676 Result is Number1 div Number2 1677</PRE> 1678 which should be preferred for portability. 1679<P> 1680 This division operates on integer arguments, and delivers an 1681 integer result rounded down towards negative infinity (floored). 1682 The corresponding remainder is computed by the mod operation, such 1683 that the following equivalence always holds: 1684<PRE> 1685 X =:= (X mod Y) + (X div Y) * Y. 1686</PRE> 1687 The relationship with floating-point division is: 1688<PRE> 1689 X div Y =:= integer(floor(X/Y)). 1690</PRE> 1691<P> 1692 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 1693 to (div)/3 is delayed until these variables are instantiated. 1694 1695<P> 1696"), 1697 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 1698 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 5 : "Number1 or Number2 is a number but not an integer.", 1699 24 : "Number1 or Number2 is not of a numeric type.", 20 : "Illegal arithmetic operation: division by 0"], 1700 eg:" 1701Success: 1702 X is 10 div 3. ( gives X = 3) 1703 1704 div( 10, 3, 3). 1705 div(-10, 3, -4). 1706 div( 10, -3, -4). 1707 div(-10, -3, 3). 1708Fail: 1709 div(1, 2, 3). 1710 div(6, 2, 3.0). 1711 div(5, 2, r). 1712Error: 1713 div(A, 2, 6). (Error 4). 1714 div(6, 2.0, 3.0). (Error 5). 1715 div(2, 0, Result). (Error 20). 1716 div(4 + 2, 2, 12). (Error 24). 1717", 1718 see_also:[(is) / 2, (//)/3, (mod)/3]]). 1719 1720:- comment((<) / 2, [ 1721 summary:"Succeed if the value of Expr1 is less than the value of Expr2. 1722 1723", 1724 template:"+Expr1 < +Expr2", 1725 amode:((+ < +) is semidet), 1726 desc:html(" Both arguments are evaluated and their types adjusted. Then the 1727 resulting numbers are compared. The predicate succeeds if the value of 1728 Expr1 is less than the value of Expr2. If the system is in coroutining 1729 mode and the arguments are not ground, this predicate delays until the 1730 expressions are fully instantiated. 1731<P> 1732 The predicate also delays when the comparison involves bounded reals, 1733 and the compared values overlap such that the result is undecidable. 1734 1735<P> 1736"), 1737 args:["Expr1" : "An arithmetic expression", "Expr2" : "An arithmetic expression"], 1738 fail_if:"Fails if the value of Expr1 is greater than or equal to the value of Expr2", 1739 exceptions:[4 : "Expr1 or Expr2 is a variable (non-coroutining mode only).", 5 : "Expr1 or Expr2 is not an arithmetic expression."], 1740 eg:" 1741 Success: 1742 5 - 3 < 6 / 2. 1743 0 < sin(pi/4). % 0 converted to 0.0 1744 Fail: 1745 2 + 4 < 2 * 3. 1746 Error: 1747 _ < 10. (Error 4) 1748 \"s\" < 10. (Error 5) 1749 1750 1751 1752", 1753 see_also:[_:(<)/2, (is) / 2, (=:=) / 2, (=\=) / 2, (>=) / 2, (=<) / 2, (>) / 2]]). 1754 1755:- comment(frandom / 1, [ 1756 summary:"Generates a random floating-point number F in the range <0, 1>. 1757 1758", 1759 amode:(frandom(-) is det), 1760 desc:html(" frandom/1 unifies F with a random floating-point number between 0 and 1. 1761 The code is taken from random2.c by John Burton, available from the net. 1762 Part of original comment: 1763 1764<P> 1765<PRE> 1766 * 1767 * PMMMLCG - Prime Modulus M Multiplicative Linear Congruential Generator * 1768 * Modified version of the Random number generator proposed by * 1769 * Park & Miller in \"Random Number Generators: Good Ones Are Hard to Find\" * 1770 * CACM October 1988, Vol 31, No. 10 * 1771 * - Modifications proposed by Park to provide better statistical * 1772 * properties (i.e. more \"random\" - less correlation between sets of * 1773 * generated numbers * 1774 * - generator is of the form * 1775 * x = ( x * A) % M * 1776 * - Choice of A & M can radically modify the properties of the generator * 1777 * the current values were chosen after followup work to the original * 1778 * paper mentioned above. * 1779 * - The generator has a period of 0x3fffffff with numbers generated in * 1780 * the range of 0 < x < M * 1781 * - The generator can run on any machine with a 32-bit integer, without * 1782 * overflow. * 1783</PRE> 1784"), 1785 args:["F" : "Floating-point number or variable."], 1786 exceptions:[5 : "F is instantiated, but not to a floating-point number."], 1787 eg:" 1788Success: 1789 [eclipse]: frandom(F1), frandom(F2). 1790 F1 = 0.900086582 1791 F2 = 0.0795856342 1792 yes. 1793 1794 [eclipse]: seed(1), frandom(F). 1795 F = 2.2477936e-05 1796 yes. 1797 [eclipse]: seed(1), frandom(F). 1798 F = 2.2477936e-05 1799 yes. 1800 1801Fail: 1802 frandom(123.45). 1803 1804Error: 1805 frandom(1234). (Error 5). 1806 1807 1808 1809", 1810 see_also:[seed / 1, random / 1]]). 1811 1812:- comment((=<) / 2, [ 1813 summary:"Succeed if the value of Expr1 is less than or equal to the value of Expr2. 1814 1815", 1816 template:"+Expr1 =< +Expr2", 1817 amode:((+ =< +) is semidet), 1818 desc:html(" Both arguments are evaluated and their types adjusted. Then the 1819 resulting numbers are compared. The predicate succeeds if the value of 1820 Expr1 is less than or equal to the value of Expr2. If the system is in 1821 coroutining mode and the arguments are not ground, this predicate delays 1822 until the expressions are fully instantiated. 1823<P> 1824 The predicate also delays when the comparison involves bounded reals, 1825 and the compared values overlap such that the result is undecidable. 1826 1827<P> 1828"), 1829 args:["Expr1" : "An arithmetic expression", "Expr2" : "An arithmetic expression"], 1830 fail_if:"fails if the value of Expr1 is greater than the value of Expr2", 1831 exceptions:[4 : "Expr1 or Expr2 is a variable (non-coroutining mode only).", 5 : "Expr1 or Expr2 is not an arithmetic expression."], 1832 eg:" 1833 Success: 1834 5 - 3 =< 6 / 2. 1835 1 =< sin(pi/2). % 1 converted to 1.0 1836 Fail: 1837 2 + 5 =< 2 * 3. 1838 Error: 1839 _ =< 10. (Error 4) 1840 \"s\" =< 10. (Error 5) 1841 1842 1843 1844", 1845 see_also:[_:(=<)/2, (is) / 2, (=:=) / 2, (=\=) / 2, (>=) / 2, (<) / 2, (>) / 2]]). 1846 1847:- comment(ln / 2, [ 1848 summary:"Evaluates the natural logarithm ln(Number) and unifies the resulting value 1849with Result. 1850 1851", 1852 amode:(ln(+,-) is det), 1853 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1854 arithmetic expressions. So the call to ln(Number, Result) is equivalent 1855 to 1856<PRE> 1857 Result is ln(Number) 1858</PRE> 1859 which should be preferred for portability. 1860<P> 1861 In coroutining mode, if Number is uninstantiated, the call to ln/2 is 1862 delayed until this variable is instantiated. 1863 1864<P> 1865"), 1866 args:["Number" : "A number.", "Result" : "A variable float or breal."], 1867 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type.", 20 : "Illegal arithmetic operation: Number is 0 or less."], 1868 eg:" 1869Success: 1870 ln(2.0, Result). (gives Result = 0.693147) 1871 ln(1, Result). (gives Result = 0.0) 1872Fail: 1873 ln(1, 1.0). 1874 ln(1, 0). 1875 ln(1, r). 1876Error: 1877 ln(A, 6.0). (Error 4). 1878 ln(-2, Result). (Error 20). 1879 ln(0, Result). (Error 20). 1880 ln(4 + 2, 1.79176). (Error 24). 1881 1882 1883 1884", 1885 see_also:[(is) / 2]]). 1886 1887:- comment(max / 3, [ 1888 summary:"Unifies the maximum of Number1 and Number2 with Maximum. 1889 1890", 1891 amode:(max(+,+,-) is det), 1892 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1893 arithmetic expressions. So the call to max(Number1, Number2, Maximum) 1894 is equivalent to 1895<PRE> 1896 Maximum is max(Number1, Number2) 1897</PRE> 1898 which should be preferred for portability. 1899<P> 1900 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 1901 to max/3 is delayed until these variables are instantiated. 1902 1903<P> 1904"), 1905 args:["Number1" : "A number.", "Number2" : "A number.", "Maximum" : "A variable or number."], 1906 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 24 : "Number1 or Number2 is not of a numeric type."], 1907 eg:" 1908Success: 1909 max(5, 2, 5). 1910 max(2_3, 3_4, 3_4). 1911 max(5.0 , 2.0, 5.0). 1912 max(5, 2.0, 5.0). (The types are adjusted) 1913 max(5, 2_0, 5_0). (The types are adjusted) 1914Fail: 1915 max(1, 2, 3). 1916 max(1, 2, 2.0). 1917 max(5, 2, r). 1918 max(5, 2.0, 5). 1919Error: 1920 max(A, 2, 6). (Error 4). 1921 max(4 - 2, 3, 3). (Error 24). 1922 1923 1924 1925", 1926 see_also:[(is) / 2]]). 1927 1928:- comment(min / 3, [ 1929 summary:"Unifies the minimum of Number1 and Number2 with Minimum. 1930 1931", 1932 amode:(min(+,+,-) is det), 1933 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1934 arithmetic expressions. So the call to min(Number1, Number2, Minimum) 1935 is equivalent to 1936<PRE> 1937 Minimum is min(Number1, Number2) 1938</PRE> 1939 which should be preferred for portability. 1940<P> 1941 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 1942 to min/3 is delayed until these variables are instantiated. 1943 1944<P> 1945"), 1946 args:["Number1" : "A number.", "Number2" : "A number.", "Minimum" : "A variable or a number."], 1947 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 24 : "Number1 or Number2 is not of a numeric type."], 1948 eg:" 1949Success: 1950 min(5, 2, 2). 1951 min(2_3, 3_4, 2_3). 1952 min(5.0 , 2.0, 2.0). 1953 min(5.0, 2, 2.0). (The types are adjusted) 1954 min(5_0, 2, 2_0). (The types are adjusted) 1955Fail: 1956 min(1, 2, 3). 1957 min(1, 2, 2.0). 1958 min(5, 2.0, 5). 1959 min(5, 2, r). 1960Error: 1961 min(A, 2, 6). (Error 4). 1962 min(4 - 2, 3, 3). (Error 24). 1963 1964 1965 1966", 1967 see_also:[(is) / 2]]). 1968 1969:- comment((-) / 3, [ 1970 summary:"Evaluates the difference Number1 - Number2 and unifies the resulting value 1971with Result. 1972 1973", 1974 amode:(-(+,+,-) is det), 1975 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 1976 arithmetic expressions. So the call to -(Number1, Number2, Result) is 1977 equivalent to 1978<PRE> 1979 Result is Number1 - Number2 1980</PRE> 1981 which should be preferred for portability. 1982<P> 1983 The result is of type breal if any of the arguments is a breal, 1984 else float if any of the arguments is a float, else rational if any 1985 of the arguments is a rational. Only when both arguments are 1986 integers is the result an integer. 1987 1988<P> 1989 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 1990 to -/3 is delayed until these variables are instantiated. 1991 1992<P> 1993"), 1994 args:["Number1" : "A number.", "Number2" : "A number.", "Result" : "A variable or a number."], 1995 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 24 : "Number1 or Number2 is not of a numeric type."], 1996 eg:" 1997Success: 1998 -(5, 2, 3). (gives Result = 3) 1999 -(5, -2.0, Result). (gives Result = 7.0) 2000Fail: 2001 -(1, 2, 3). 2002 -(1, 2, 3.0). 2003 -(5, 2, r). 2004Error: 2005 -(A, 2, 6). (Error 4). 2006 -(4 + 1, 2, 3). (Error 24). 2007 2008 2009 2010", 2011 see_also:[(is) / 2]]). 2012 2013:- comment((rem) / 3, [ 2014 summary:"Evaluates the remainder Number1 rem Number2 and unifies the resulting value 2015with Result. 2016 2017", 2018 amode:(rem(+,+,-) is det), 2019 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2020 arithmetic expressions. So the call to rem(Number1, Number2, Result) is 2021 equivalent to 2022<PRE> 2023 Result is Number1 rem Number2 2024</PRE> 2025 which should be preferred for portability. 2026<P> 2027 The modulus operation computes the remainder corresponding to the 2028 truncating division //. The following relation always holds: 2029<PRE> 2030 X =:= (X rem Y) + (X // Y) * Y. 2031</PRE> 2032 The result Result is either zero, or has the same sign as Number1. The 2033 absolute value of Result does not depend on the signs of the arguments. 2034<P> 2035 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2036 to rem/3 is delayed until these variables are instantiated. 2037<P> 2038 See also the mod operation, whose result only differs when the arguments 2039 have opposite signs. 2040"), 2041 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 2042 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 2043 5 : "Number1 or Number2 is a number but not an integer.", 2044 20 : "Illegal arithmetic operation: Number2 is zero", 2045 24 : "Number1 or Number2 is not of a numeric type."], 2046 eg:" 2047Success: 2048 X is 10 rem 3. (gives X = 1) 2049 2050 rem( 10, 3, 1). 2051 rem(-10, 3, -1). 2052 rem( 10, -3, 1). 2053 rem(-10, -3, -1). 2054 2055 rem( 11, 3, 2). 2056Fail: 2057 rem(1, 2, 3). 2058 rem(6, 2.0, 3.0). 2059 rem(5, 2, r). 2060Error: 2061 rem(A, 2, 6). (Error 4). 2062 rem(2, 0, Result). (Error 20). 2063 rem(4 + 2, 2, 12). (Error 24). 2064", 2065 see_also:[(is) / 2, (//)/3, (mod)/3]]). 2066 2067:- comment((mod) / 3, [ 2068 summary:"Evaluates the modulus Number1 mod Number2 and unifies the resulting value 2069with Result. 2070 2071", 2072 amode:(mod(+,+,-) is det), 2073 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2074 arithmetic expressions. So the call to mod(Number1, Number2, Result) is 2075 equivalent to 2076<PRE> 2077 Result is Number1 mod Number2 2078</PRE> 2079 which should be preferred for portability. 2080<P> 2081 The modulus operation computes the remainder corresponding to the 2082 flooring division div. The following relation always holds: 2083<PRE> 2084 X =:= (X mod Y) + (X div Y) * Y. 2085</PRE> 2086 The result Result is either zero, or has the same sign as Number2. 2087<P> 2088 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2089 to mod/3 is delayed until these variables are instantiated. 2090<P> 2091 CAUTION: The behaviour of mod was changed for standard compliance! 2092 In ECLiPSe versions up to 5.8, mod computed the remainder corresponding 2093 to the truncating division //, and thus gave different results for 2094 arguments with opposite signs. Moreover, the operator precedence was 2095 changed from op(300,xfx,mod) to op(400,yfx,mod), which means that 2096 a*b mod c is now parsed as (a*b)mod c rather than a*(b mod c). 2097"), 2098 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 2099 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 2100 5 : "Number1 or Number2 is a number but not an integer.", 2101 20 : "Illegal arithmetic operation: Number2 is zero", 2102 24 : "Number1 or Number2 is not of a numeric type."], 2103 eg:" 2104Success: 2105 X is 10 mod 3. (gives X = 1) 2106 2107 mod( 10, 3, 1). 2108 mod(-10, 3, 2). 2109 mod( 10, -3, -2). 2110 mod(-10, -3, -1). 2111 2112 mod( 11, 3, 2). 2113Fail: 2114 mod(1, 2, 3). 2115 mod(6, 2.0, 3.0). 2116 mod(5, 2, r). 2117Error: 2118 mod(A, 2, 6). (Error 4). 2119 mod(2, 0, Result). (Error 20). 2120 mod(4 + 2, 2, 12). (Error 24). 2121", 2122 see_also:[(is) / 2, (div)/3, (rem)/3]]). 2123 2124:- comment((*) / 3, [ 2125 summary:"Evaluates the product Number1 * Number2 and unifies the resulting value 2126with Result. 2127 2128", 2129 amode:(*(+,+,-) is det), 2130 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2131 arithmetic expressions. So the call to *(Number1, Number2, Result) is 2132 equivalent to 2133<PRE> 2134 Result is Number1 * Number2 2135</PRE> 2136 which should be preferred for portability. 2137<P> 2138 The result is of type breal if any of the arguments is a breal, 2139 else float if any of the arguments is a float, else rational if any 2140 of the arguments is a rational. Only when both arguments are 2141 integers is the result an integer. 2142 2143<P> 2144 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2145 to */3 is delayed until these variables are instantiated. 2146 2147<P> 2148"), 2149 args:["Number1" : "A number.", "Number2" : "A number.", "Result" : "A variable or a number."], 2150 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 24 : "Number1 or Number2 is not of a numeric type."], 2151 eg:" 2152Success: 2153 *(5, 2, 10). 2154 *(5, -2.0, -10.0). 2155Fail: 2156 *(1, 2, 3). 2157 *(5, 2, 10.0). 2158 *(5, 2.0, 10). 2159 *(1, 2, 3.0). 2160 *(5, 2, r). 2161Error: 2162 *(A, 2, 6). (Error 4). 2163 *(4 + 2, 2, 12). (Error 24). 2164 2165 2166 2167", 2168 see_also:[(is) / 2]]). 2169 2170:- comment(gcd / 3, [ 2171 summary:"Unifies Results with the Greatest Common Divisor of Number1 and Number2", 2172 amode:(gcd(+,+,-) is det), 2173 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2174 arithmetic expressions. So the call to gcd(Number1, Number2, Result) is 2175 equivalent to 2176<PRE> 2177 Result is gcd(Number1, Number2) 2178</PRE> 2179 which should be preferred for portability. 2180<P> 2181 The Greatest Common Divisor operation is only defined on integer arguments. 2182<P> 2183 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2184 is delayed until these variables are instantiated. 2185 2186<P> 2187"), 2188 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 2189 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 5 : "Number1 or Number2 is a number but not an integer.", 24 : "Number1 or Number2 is not of a numeric type."], 2190 eg:" 2191Success: 2192 gcd(9, 15, 3). 2193 gcd(-9, 15, 3). 2194 gcd(2358352782,97895234896224,X). ( gives X = 6 ) 2195 2196Fail: 2197 gcd(1, 2, 3.0). 2198Error: 2199 gcd(A, 2, 6). (Error 4). 2200 gcd(1.0, 2, 3.0). (Error 5). 2201 gcd(4 + 2, 2, 12). (Error 24). 2202", 2203 see_also:[gcd/5, lcm/3, (is) / 2]]). 2204 2205:- comment(gcd / 5, [ 2206 summary:"Unifies GCD with the Greatest Common Divisor of 2207 Number1 and Number2, and gives appropriate coefficients U and 2208 V for the corresponding Bezout equation", 2209 2210 amode:(gcd(+,+,-,-,-) is det), 2211 desc:html(" 2212 The Greatest Common Divisor operation is only defined on integer arguments. 2213<P> 2214 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2215 is delayed until these variables are instantiated. 2216<P> 2217 The Bezout equation is Number1*U + Number2*V = GCD. These 2218 coefficients are calculated by an extended version of Euclid's 2219 algorithm. 2220 2221<P> 2222"), 2223 args:["Number1" : "Integer.", "Number2" : "Integer.", 2224 "U" : "A variable of integer.","V" : "A variable or integer.", 2225 "GCD" : "A variable or integer."], 2226 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 5 : "Number1 or Number2 is a number but not an integer.", 24 : "Number1 or Number2 is not of a numeric type."], 2227 eg:" 2228Success: 2229 gcd(9, 15, 2, -1, 3). 2230 gcd(-9, 15, -2, -1, 3). 2231 gcd(2358352782,97895234896224,U,V,G). ( gives U = 2130001290117, V = -51312962, G = 6 ) 2232 2233Fail: 2234 gcd(1, 2, U, V, 3.0). 2235Error: 2236 gcd(A, 2, U, V, 6). (Error 4). 2237 gcd(1.0, 2, U, V, 3.0). (Error 5). 2238 gcd(4 + 2, 2, U, V, 12). (Error 24). 2239", 2240 see_also:[gcd/3, lcm/3, (is) / 2]]). 2241 2242:- comment(lcm / 3, [ 2243 summary:"Unifies Results with the Least Common Multiple of Number1 and Number2", 2244 amode:(lcm(+,+,-) is det), 2245 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2246 arithmetic expressions. So the call to lcm(Number1, Number2, Result) is 2247 equivalent to 2248<PRE> 2249 Result is lcm(Number1, Number2) 2250</PRE> 2251 which should be preferred for portability. 2252<P> 2253 The Least Common Multiple operation is only defined on integer arguments. 2254<P> 2255 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2256 is delayed until these variables are instantiated. 2257 2258<P> 2259"), 2260 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 2261 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 5 : "Number1 or Number2 is a number but not an integer.", 24 : "Number1 or Number2 is not of a numeric type."], 2262 eg:" 2263Success: 2264 lcm(9, 15, 45). 2265 lcm(-9, 15, 45). 2266 lcm(2358352782,97895234896224,X). ( gives X = 38478583260342225282528 ) 2267 2268Fail: 2269 lcm(1, 2, 3.0). 2270Error: 2271 lcm(A, 2, 6). (Error 4). 2272 lcm(1.0, 2, 3.0). (Error 5). 2273 lcm(4 + 2, 2, 12). (Error 24). 2274", 2275 see_also:[gcd/3,gcd/5, (is) / 2]]). 2276 2277:- comment((=\=) / 2, [ 2278 summary:"Succeed if the value of Expr1 is not equal to the value of Expr2. 2279 2280", 2281 template:"+Expr1 =\\= +Expr2", 2282 amode:((+ =\= +) is semidet), 2283 desc:html(" Both arguments are evaluated and their types adjusted. Then the 2284 resulting numbers are compared. The predicate succeeds if the values of 2285 Expr1 and Expr2 are not equal (beware of rounding errors when comparing 2286 floats). If the system is in coroutining mode and the arguments are not 2287 ground, this predicate delays until the expressions are fully 2288 instantiated. 2289<P> 2290 The predicate also delays when the comparison involves bounded reals, 2291 and the compared values overlap such that the result is undecidable. 2292 2293<P> 2294"), 2295 args:["Expr1" : "An arithmetic expression", "Expr2" : "An arithmetic expression"], 2296 fail_if:"fails if the value of Expr1 is equal to the value of Expr2", 2297 exceptions:[4 : "Expr1 or Expr2 is a variable (non-coroutining mode only).", 5 : "Expr1 or Expr2 is not an arithmetic expression."], 2298 eg:" 2299Success: 2300 5 - 1 =\\= 6 / 2. 2301 1 =\\= sin(pi/4). % 1 converted to 1.0 2302 2303Fail: 2304 2 + 4 =\\= 2 * 3. 2305 2306Error: 2307 _ =\\= 10. (Error 4) 2308 \"s\" =\\= 10. (Error 5) 2309 2310 2311 2312", 2313 see_also:[_:(=\=)/2, (is) / 2, (=:=) / 2, (>=) / 2, (<) / 2, (>) / 2, (=<) / 2]]). 2314 2315:- comment((\/) / 3, [ 2316 summary:"Evaluates the bitwise disjunction Number1 \\/ Number2 and unifies the 2317resulting value with Result. 2318 2319", 2320 amode:(\/(+,+,-) is det), 2321 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2322 arithmetic expressions. So the call to \\/(Number1, Number2, Result) is 2323 equivalent to 2324<PRE> 2325 Result is Number1 \\/ Number2 2326</PRE> 2327 which should be preferred for portability. 2328<P> 2329 This operation behaves as if operating on an unlimited length two's 2330 complement representation. 2331<P> 2332 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2333 to \\//3 is delayed until these variables are instantiated. 2334 2335<P> 2336"), 2337 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 2338 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 5 : "Number1 or Number2 is a number but not an integer.", 24 : "Number1 or Number2 is not of a numeric type."], 2339 eg:" 2340Success: 2341 \\/(11, 7, 15). 2342 \\/(11, -7, Result). (gives Result = -5) 2343Fail: 2344 \\/(1, 2, 4). 2345 \\/(6, 2.0, 6.0). 2346 \\/(5, 2, r). 2347Error: 2348 \\/(A, 2, 6). (Error 4). 2349 \\/(4 + 2, 2, 6). (Error 24). 2350 2351 2352 2353", 2354 see_also:[(is) / 2]]). 2355 2356:- comment((+) / 3, [ 2357 summary:"Evaluates the sum Number1 + Number2 and unifies the resulting value with 2358Result. 2359 2360", 2361 amode:(+(+,+,-) is det), 2362 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2363 arithmetic expressions. So the call to +(Number1, Number2, Result) is 2364 equivalent to 2365<PRE> 2366 Result is Number1 + Number2 2367</PRE> 2368 which should be preferred for portability. 2369<P> 2370 The result is of type breal if any of the arguments is a breal, 2371 else float if any of the arguments is a float, else rational if any 2372 of the arguments is a rational. Only when both arguments are 2373 integers is the result an integer. 2374 2375<P> 2376 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2377 to +/3 is delayed until these variables are instantiated. 2378 2379<P> 2380"), 2381 args:["Number1" : "A number.", "Number2" : "A number.", "Result" : "A variable or a number."], 2382 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 24 : "Number1 or Number2 is not of a numeric type."], 2383 eg:" 2384Success: 2385 +(5, 2, 7). 2386 +(5, -2.0, 3.0). 2387Fail: 2388 +(1, 2, 7). 2389 +(1, 2, 3.0). 2390 +(5, 2, r). 2391Error: 2392 +(A, 2, 6). (Error 4). 2393 +(7 - 4, 2, 3). (Error 24). 2394 2395 2396 2397", 2398 see_also:[(is) / 2]]). 2399 2400:- comment((^) / 3, [ 2401 summary:"Evaluates the expression Number1 \"to the power of\" Number2 and unifies the 2402resulting value with Result. 2403 2404", 2405 amode:(^(+,+,-) is det), 2406 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2407 arithmetic expressions. So the call to ^(Number1, Number2, Result) is 2408 equivalent to 2409<PRE> 2410 Result is Number1 ^ Number2 2411</PRE> 2412 which should be preferred for portability. 2413<P> 2414 The result is of type float if any of the arguments is a float. 2415 When an integer is raised to the power of a negative integer, the 2416 result type depends on the value of the global flag prefer_rationals. 2417 If it is on, it is a rational, otherwise a float. When the exponent 2418 is not an integer, the result is of type float. 2419 2420<P> 2421 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2422 to ^/3 is delayed until these variables are instantiated. 2423 2424<P> 2425"), 2426 args:["Number1" : "A number.", "Number2" : "A number.", "Result" : "A variable or a number."], 2427 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 24 : "Number1 or Number2 is not of a numeric type.", 20 : "Illegal arithmetic operation: Number1 is negative and Number2 is no integral number.", 20 : "Illegal arithmetic operation: Number1 and Number2 are both zero."], 2428 eg:" 2429Success: 2430 ^(5, 3, 125). 2431 ^(-5, 3, -125). 2432 ^(5, -2, 0.04). 2433 2434 ^(5, 2.2, 34.493244). 2435 ^(5.0, 2, 25.0). 2436 ^(-5.0, 3, -125.0). 2437 ^(0.0, 12.3, 0.0). 2438 ^(3.3, 0.0, 1.0). 2439 ^(0.0, 0.0, 1.0). 2440Fail: 2441 ^(1, 2, 3). 2442 ^(1, 2, 3.0). 2443 ^(5, 2, r). 2444Error: 2445 ^(A, 2, 6). (Error 4). 2446 ^(-5, 0.5, X). (Error 20). 2447 ^(-5.0, 3.1, X). (Error 20). 2448 ^(2 + 3, 2, 25). (Error 24). 2449 2450 2451 2452", 2453 see_also:[(is) / 2, get_flag / 2, set_flag / 2]]). 2454 2455:- comment(round / 2, [ 2456 summary:"Rounds Number to the nearest integral value of the same type", 2457 amode:(round(+,-) is det), 2458 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2459 arithmetic expressions. So the call to round(Number, Result) is 2460 equivalent to 2461<PRE> 2462 Result is round(Number) 2463</PRE> 2464 which should be preferred for portability. 2465<P> 2466 This operation works on all numeric types. The result value is the 2467 integral value that is closest to Number (rounding to nearest). If 2468 Number is exactly in the middle between two integers, the result 2469 is the even one. 2470<P> 2471 The result type is the same as the argument type. To convert the 2472 type to integer, use integer/2. 2473<P> 2474 In coroutining mode, if Number is uninstantiated, the call to round/2 2475 is delayed until this variable is instantiated. 2476 2477<P> 2478"), 2479 args:["Number" : "A number.", "Result" : "A variable or number."], 2480 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 2481 eg:" 2482Success: 2483 round(1.49, 1.0). 2484 round(1.5, 2.0). (odd integer part) 2485 round(2.5, 2.0). 2486 round(2.51, 3.0). (even integer part) 2487 round(3.5, 4.0). 2488 round(-6.4, Result). (gives Result = -6.0) 2489 round(3, 3). 2490Fail: 2491 round(1, 0.0). 2492 round(0.5, 0). 2493 round(1, r). 2494Error: 2495 round(A, 6.0). (Error 4). 2496 round(4 + 2.3, 6.0). (Error 24). 2497 2498 2499 2500", 2501 see_also:[(is) / 2, floor/2, ceiling/2, truncate/2, integer/2]]). 2502 2503:- comment((<<) / 3, [ 2504 summary:"Shifts Number1 left by Number2 bits and unifies the 2505resulting value with Result. 2506 2507", 2508 amode:(<<(+,+,-) is det), 2509 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2510 arithmetic expressions. So the call to <<(Number1, Number2, Result) is 2511 equivalent to 2512<PRE> 2513 Result is Number1 << Number2 2514</PRE> 2515 which should be preferred for portability. 2516<P> 2517 The shift behaves as if operating on an unlimited length two's complement 2518 representation. Shifting by a negative amount is the same as shifting by 2519 the same positive amount in the other direction. 2520<P> 2521 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2522 to <</3 is delayed until these variables are instantiated. 2523 2524<P> 2525"), 2526 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 2527 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 5 : "Number1 or Number2 is a number but not an integer.", 24 : "Number1 or Number2 is not of a numeric type."], 2528 eg:" 2529Success: 2530 <<(1, 3, 8). 2531Fail: 2532 <<(1, 2, 3). 2533 <<(6, 2.0, 24.0). 2534 <<(5, 2, r). 2535Error: 2536 <<(A, 2, 6). (Error 4). 2537 <<(4 + 2, 2, 24). (Error 24). 2538 2539 2540 2541", 2542 see_also:[(is) / 2]]). 2543 2544:- comment((>>) / 3, [ 2545 summary:"Shifts Number1 right arithmetically by Number2 bits and unifies the 2546resulting value with Result. 2547 2548", 2549 amode:(>>(+,+,-) is det), 2550 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2551 arithmetic expressions. So the call to >>(Number1, Number2, Result) is 2552 equivalent to 2553<PRE> 2554 Result is Number1 >> Number2 2555</PRE> 2556 which should be preferred for portability. 2557<P> 2558 The shift behaves as an arithmetic (signed) shift operating on an unlimited 2559 length two's complement representation. Shifting by a negative amount is 2560 the same as shifting by the same positive amount in the other direction. 2561<P> 2562 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2563 to >>/3 is delayed until these variables are instantiated. 2564 2565<P> 2566"), 2567 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 2568 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 5 : "Number1 or Number2 is a number but not an integer.", 24 : "Number1 or Number2 is not of a numeric type."], 2569 eg:" 2570Success: 2571 >>(8, 3, 1). 2572 >>(17, 3, X). (gives X = 2) 2573Fail: 2574 >>(1, 2, 3). 2575 >>(16, 2.0, 4.0). 2576 >>(5, 2, r). 2577Error: 2578 >>(A, 2, 6). (Error 4). 2579 >>(4 + 12, 2, 4). (Error 24). 2580 2581 2582 2583", 2584 see_also:[(is) / 2]]). 2585 2586:- comment(sin / 2, [ 2587 summary:"Evaluates the trigonometric function sin(Number) and unifies the resulting 2588value with Result. 2589 2590", 2591 amode:(sin(+,-) is det), 2592 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2593 arithmetic expressions. So the call to sin(Number, Result) is 2594 equivalent to 2595<PRE> 2596 Result is sin(Number) 2597</PRE> 2598 which should be preferred for portability. 2599<P> 2600 In coroutining mode, if Number is uninstantiated, the call to sin/2 is 2601 delayed until this variable is instantiated. 2602 2603<P> 2604"), 2605 args:["Number" : "A number.", "Result" : "A variable, float or breal."], 2606 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 2607 eg:" 2608Success: 2609 sin(1.5708, 1.0). 2610 sin(-1.5708, Result). (gives Result = -1.0) 2611 sin(0, Result). (gives Result = 0.0) 2612Fail: 2613 sin(1, 0.0). 2614 sin(6, 3). 2615 sin(5, r). 2616Error: 2617 sin(A, 6.0). (Error 4). 2618 sin(4 + 2, -0.279415). (Error 24). 2619 2620 2621 2622", 2623 see_also:[(is) / 2]]). 2624 2625:- comment(sqrt / 2, [ 2626 summary:"Evaluates the square root sqrt(Number) and unifies the resulting value with 2627Result. 2628 2629", 2630 amode:(sqrt(+,-) is det), 2631 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2632 arithmetic expressions. So the call to sqrt(Number, Result) is 2633 equivalent to 2634<PRE> 2635 Result is sqrt(Number) 2636</PRE> 2637 which should be preferred for portability. 2638<P> 2639 In coroutining mode, if Number is uninstantiated, the call to sqrt/2 is 2640 delayed until this variable is instantiated. 2641 2642<P> 2643"), 2644 args:["Number" : "A number.", "Result" : "A variable, float or breal."], 2645 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type.", 20 : "Illegal arithmetic operation: Number is negative."], 2646 eg:" 2647Success: 2648 sqrt(1.0, 1.0). 2649 sqrt(1.0, Result). (gives Result = 1.0) 2650 sqrt(49, Result). (gives Result = 7.0) 2651Fail: 2652 sqrt(1, 0.0). 2653 sqrt(1, 1). 2654 sqrt(1, r). 2655Error: 2656 sqrt(A, 6.0). (Error 4). 2657 sqrt(-2, Result). (Error 20). 2658 sqrt(4 + 2, 2.44949). (Error 24). 2659 2660 2661 2662", 2663 see_also:[(is) / 2]]). 2664 2665:- comment(tan / 2, [ 2666 summary:"Evaluates the trigonometric function tan(Number) and unifies the resulting 2667value with Result. 2668 2669", 2670 amode:(tan(+,-) is det), 2671 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2672 arithmetic expressions. So the call to tan(Number, Result) is 2673 equivalent to 2674<PRE> 2675 Result is tan(Number) 2676</PRE> 2677 which should be preferred for portability. 2678<P> 2679 In coroutining mode, if Number is uninstantiated, the call to tan/2 is 2680 delayed until this variable is instantiated. 2681 2682<P> 2683"), 2684 args:["Number" : "A number.", "Result" : "A variable, float or breal."], 2685 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type.", 20 : "Illegal arithmetic operation: Number is (2k +1) * pi/2 for every integer k."], 2686 eg:" 2687Success: 2688 tan(0, 0.0). 2689 tan(12.3, Result). (gives Result = -0.272854) 2690 tan(-1, Result). (gives Result = -1.55741) 2691Fail: 2692 tan(1, 0.0). 2693 tan(0, 0). 2694 tan(5, r). 2695Error: 2696 tan(A, 6.0). (Error 4). 2697 X is pi/2, tan(X, Result). (Error 20). 2698 tan(10.3 + 2, -0.272854). (Error 24). 2699 2700 2701 2702", 2703 see_also:[(is) / 2]]). 2704 2705:- comment((-) / 2, [ 2706 summary:"Unifies the negative of Number with Result. 2707 2708", 2709 amode:(-(+,-) is det), 2710 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2711 arithmetic expressions. So the call to -(Number, Result) is equivalent 2712 to 2713<PRE> 2714 Result is -Number 2715</PRE> 2716 which should be preferred for portability. 2717<P> 2718 Number and Result have to be of the same type. 2719 2720<P> 2721 In coroutining mode, if Number is uninstantiated, the call to -/2 is 2722 delayed until this variable is instantiated. 2723 2724<P> 2725"), 2726 args:["Number" : "A number.", "Result" : "A variable or a number."], 2727 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 2728 eg:" 2729Success: 2730 -(1, -1). 2731 -(5, Result). (gives Result = -5) 2732 -(-6.2, Result). (gives Result = 6.2) 2733Fail: 2734 -(1, 0). 2735 -(1, -1.0). 2736 -(1.0, -1). 2737 -(1, r). 2738Error: 2739 -(A, 6). (Error 4). 2740 -(4 + 2, -6). (Error 24). 2741 2742 2743 2744", 2745 see_also:[(is) / 2]]). 2746 2747:- comment((+) / 2, [ 2748 summary:"Checks if Number is a number and unifies it with Result. 2749 2750", 2751 amode:(+(+,-) is det), 2752 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2753 arithmetic expressions. So the call to +(Number, Result) is equivalent 2754 to 2755<PRE> 2756 Result is +Number 2757</PRE> 2758 which should be preferred for portability. 2759<P> 2760 Number and Result have to be of the same type. 2761 2762<P> 2763 In coroutining mode, if Number is uninstantiated, the call to +/2 is 2764 delayed until this variable is instantiated. 2765 2766<P> 2767"), 2768 args:["Number" : "A number.", "Result" : "A variable or a number."], 2769 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 24 : "Number is not of a numeric type."], 2770 eg:" 2771Success: 2772 +(1, 1). 2773 +(5, Result). (gives Result = 5) 2774 +(-6.2, Result). (gives Result = -6.2) 2775Fail: 2776 +(1, 0). 2777 +(1.0, 1). 2778 +(1, 1.0). 2779 +(1, r). 2780Error: 2781 +(A, 6). (Error 4). 2782 +(4 + 2, 6). (Error 24). 2783 2784 2785 2786", 2787 see_also:[(is) / 2]]). 2788 2789:- comment(xor / 3, [ 2790 summary:"Evaluates the bitwise exclusive disjunction Number1 xor Number2 and unifies 2791the resulting value with Result. 2792 2793", 2794 amode:(xor(+,+,-) is det), 2795 desc:html(" This predicate is used by the ECLiPSe compiler to expand evaluable 2796 arithmetic expressions. So the call to xor(Number1, Number2, Result) is 2797 equivalent to 2798<PRE> 2799 Result is xor(Number1, Number2) 2800</PRE> 2801 which should be preferred for portability. 2802<P> 2803 In coroutining mode, if Number1 or Number2 are uninstantiated, the call 2804 to xor/3 is delayed until these variables are instantiated. 2805 2806<P> 2807"), 2808 args:["Number1" : "Integer.", "Number2" : "Integer.", "Result" : "A variable or integer."], 2809 exceptions:[4 : "Number1 or Number2 is not instantiated (non-coroutining mode only).", 5 : "Number1 or Number2 is a number but not an integer.", 24 : "Number1 or Number2 is not of a numeric type."], 2810 eg:" 2811Success: 2812 xor(11, 7, 12). 2813 xor(11, -7, Result). (gives Result = -14) 2814Fail: 2815 xor(1, 2, 4). 2816 xor(6, 2, 4.0). 2817 xor(5, 2, r). 2818Error: 2819 xor(A, 2, 6). (Error 4). 2820 xor(6, 2.0, 4.0). (Error 5). 2821 xor(4 + 2, 2, 4). (Error 24). 2822 2823 2824 2825", 2826 see_also:[(is) / 2]]). 2827 2828:- comment(random / 1, [ 2829 summary:"Generates a random integer N. 2830 2831", 2832 amode:(random(-) is det), 2833 desc:html("random/1 unifies N with a random integer between 0 and 2^31-1 2834 (returned by the C library function random(), whose initialization 2835 has been made using the pid of the running ECLiPSe ). 2836 2837<P> 2838 If it is required that the sequence produced by successive calls of 2839 random/1 be reproducible, seed(Seed) can be called to initialise the 2840 calls with the integer Seed. Do not assume that the same sequence will 2841 be produced for the same seed on different platforms, because the C 2842 library's implementation of random() may differ. 2843 2844<P> 2845"), 2846 args:["N" : "Integer or Variable."], 2847 exceptions:[5 : "N is instantiated, but not to an integer."], 2848 eg:" 2849Success: 2850 [eclipse]: random(N1), random(N2). 2851 N1 = 464880439 2852 N2 = 285401533 2853 yes. 2854 2855 [eclipse]: seed(1), random(N). 2856 N = 2078917053 2857 yes. 2858 [eclipse]: seed(1), random(N). 2859 N = 2078917053 2860 yes. 2861 2862Fail: 2863 random(12345). 2864 2865Error: 2866 random(12.34). (Error 5). 2867 2868 2869 2870", 2871 see_also:[frandom / 1, seed / 1]]). 2872 2873:- comment(seed / 1, [ 2874 summary:"Sets the initial seed Seed for generating random numbers with random/1 or 2875frandom/1. 2876 2877", 2878 amode:(seed(+) is det), 2879 desc:html(" Used to initialise the seed which is used for the generation of random 2880 numbers by random/1 or frandom/1. Setting the same seed value with 2881 seed/1 enables the generation of a repeatable random sequence with 2882 random/1 ie. pseudo-random number generation. 2883<P> 2884 The seed value should be an integer in the range 1 .. 2^31-1. 2885<P> 2886"), 2887 args:["Seed" : "Integer."], 2888 exceptions:[4 : "Seed is not instantiated.", 5 : "Seed is instantiated, but not to an integer."], 2889 eg:" 2890Success: 2891 [eclipse]: repeat, random(S). 2892 S = 464880439 More? (;) 2893 S = 285401533 More? (;) 2894 yes. 2895 [eclipse]: seed(1), repeat, random(S). 2896 S = 2078917053 More? (;) 2897 S = 143302914 More? (;) 2898 yes. 2899 [eclipse]: seed(1), repeat, random(S). 2900 S = 2078917053 More? (;) 2901 S = 143302914 More? (;) 2902 yes. 2903 2904 2905 2906", 2907 see_also:[random / 1]]). 2908 2909 2910:- comment(breal_min / 2, [ 2911 summary:"Extracts the lower floating point bound of Number", 2912 amode:(breal_min(+,-) is det), 2913 desc:html("\ 2914 This predicate is used by the ECLiPSe compiler to expand evaluable 2915 arithmetic expressions. So a call to breal_min(Number, Result) is 2916 equivalent to 2917<PRE> 2918 Result is breal_min(Number). 2919</PRE> 2920 A bounded real is a real number represented by a lower and upper 2921 bound in floating point format. This predicate extracts the lower 2922 bound and unifies it with Result. If Number is not a bounded real, 2923 the result returned is equivalent to converting it to a bounded real 2924 first. 2925<P> 2926"), 2927 args:["Number" : "A number.", 2928 "Result" : "A variable or float."], 2929 exceptions:[4 : "Number is not instantiated", 2930 24 : "Number is a not a number."], 2931 eg:" 2932Success: 2933 ?- breal_min(0.99__1.01, X). 2934 X = 0.99 2935 2936 ?- breal_min(1, X). 2937 X = 1.0 2938 2939 ?- breal_min(1.0, X). 2940 X = 1.0 2941 2942 ?- breal_min(1_10, X). 2943 X = 0.099999999999999992 2944 2945Error: 2946 ?- breal_min(\"a\", Z). 2947 number expected in breal_min(\"a\", Z) 2948 2949 ?- breal_min(2 + 4, Z). 2950 number expected in breal_min(2 + 4, Z) 2951", 2952 see_also:[breal_max/2, breal/1, breal/2, breal_bounds/3, 2953 breal_from_bounds/3, (is) / 2]]). 2954 2955 2956:- comment(breal_max / 2, [ 2957 summary:"Extracts the upper floating point bound of Number", 2958 amode:(breal_max(+,-) is det), 2959 desc:html("\ 2960 This predicate is used by the ECLiPSe compiler to expand evaluable 2961 arithmetic expressions. So a call to breal_max(Number, Result) is 2962 equivalent to 2963<PRE> 2964 Result is breal_max(Number). 2965</PRE> 2966 A bounded real is a real number represented by a lower and upper 2967 bound in floating point format. This predicate extracts the upper 2968 bound and unifies it with Result. If Number is not a bounded real, 2969 the result returned is equivalent to converting it to a bounded real 2970 first. 2971<P> 2972"), 2973 args:["Number" : "A number.", 2974 "Result" : "A variable or float."], 2975 exceptions:[4 : "Number is not instantiated", 2976 24 : "Number is a not a number."], 2977 eg:" 2978Success: 2979 ?- breal_max(0.99__1.01, X). 2980 X = 1.01 2981 2982 ?- breal_max(1, X). 2983 X = 1.0 2984 2985 ?- breal_max(1.0, X). 2986 X = 1.0 2987 2988 ?- breal_max(1_10, X). 2989 X = 0.10000000000000002 2990 2991Error: 2992 ?- breal_max(\"a\", Z). 2993 number expected in breal_max(\"a\", Z) 2994 2995 ?- breal_max(2 + 4, Z). 2996 number expected in breal_max(2 + 4, Z) 2997", 2998 see_also:[breal_min/2, breal/1, breal/2, breal_bounds/3, 2999 breal_from_bounds/3, (is) / 2]]). 3000 3001 3002:- comment(breal_bounds / 3, [ 3003 summary:"Extracts lower and upper floating point bounds of Number", 3004 amode:(breal_bounds(+,-,-) is det), 3005 desc:html("\ 3006 A bounded real is a real number represented by a lower and upper 3007 bound in floating point format. This predicate extracts both bounds 3008 and unifies them with Min and Max respectively. If Number is not a 3009 bounded real, the result returned is equivalent to converting it to 3010 a bounded real first. 3011"), 3012 args:["Number" : "A number.", 3013 "Min" : "A variable or float.", 3014 "Max" : "A variable or float."], 3015 exceptions:[4 : "Number is not instantiated", 3016 24 : "Number is a not a number."], 3017 eg:" 3018Success: 3019 ?- breal_bounds(0.99__1.01, Min, Max). 3020 Min = 0.99 3021 Max = 1.01 3022 3023 ?- breal(1.0, One), breal_bounds(One, Min, Max). 3024 One = 1.0__1.0 3025 Min = 1.0 3026 Max = 1.0 3027 3028 ?- breal(1, One), breal_bounds(One, Min, Max). 3029 One = 1.0__1.0 3030 Min = 1.0 3031 Max = 1.0 3032 3033 ?- breal_bounds(1, Min, Max). 3034 Min = 1.0 3035 Max = 1.0 3036 3037 ?- breal_bounds(1.0, Min, Max). 3038 Min = 1.0 3039 Max = 1.0 3040 3041 ?- breal_bounds(1_10, Min, Max). 3042 Min = 0.099999999999999992 3043 Max = 0.10000000000000002 3044 3045Error: 3046 ?- breal_bounds(\"a\", Min, Max). 3047 number expected in breal_bounds(\"a\", Min, Max) 3048 3049 ?- breal_bounds(2 + 4, Min, Max). 3050 number expected in breal_bounds(2 + 4, Min, Max) 3051", 3052 see_also:[breal/1, breal/2, breal_min/2, breal_max/2, 3053 breal_from_bounds/3, (is) / 2]]). 3054 3055 3056:- comment(breal / 2, [ 3057 summary:"Converts Number into a breal number and unifies it with Result.", 3058 amode:(breal(+,-) is det), 3059 desc:html("\ 3060 This predicate is used by the ECLiPSe compiler to expand evaluable 3061 arithmetic expressions. So the call to breal(Number, Result) is 3062 equivalent to 3063<PRE> 3064 Result is breal(Number) 3065</PRE> 3066 which should be preferred. 3067"), 3068 args:["Number" : "A number.", 3069 "Result" : "A variable or bounded real number."], 3070 exceptions:[4 : "Number is not instantiated (non-coroutining mode only).", 3071 24 : "Number is not of a numeric type."], 3072 eg:" 3073Success: 3074 ?- breal(25, X). 3075 X = 25.0__25.0 3076 3077 ?- breal(1.5, X). 3078 X = 1.5__1.5 3079 3080 ?- breal(3_4, X). 3081 X = 0.74999999999999989__0.75000000000000011 3082 3083 ?- breal(1.0__1.01, X). 3084 X = 1.0__1.01 3085 3086Fail: 3087 ?- breal(1.0, 0.9__1.1). 3088 No (0.00s cpu) 3089 3090 ?- breal(3, 3). 3091 No (0.00s cpu) 3092 3093 ?- breal(1, r). 3094 No (0.00s cpu) 3095 3096Error: 3097 ?- breal(A, X). 3098 instantiation fault in breal(A, X) 3099 3100 ?- breal(4 + 2, X). 3101 number expected in breal(4 + 2, X) 3102", 3103 see_also:[integer/2,float/2,rational/2,(is)/2, breal_min/2, breal_max/2, 3104 breal_bounds/3, breal_from_bounds/3, breal/1]]). 3105 3106 3107:- comment(breal_from_bounds / 3, [ 3108 summary:"Constructs a bounded real from the given floating point bounds", 3109 amode:(breal_from_bounds(+,+,-) is det), 3110 desc:html("\ 3111 This predicate is used by the ECLiPSe compiler to expand evaluable 3112 arithmetic expressions. So a call to breal_from_bounds(Lo, Hi, Result) 3113 is equivalent to 3114<PRE> 3115 Result is breal_from_bounds(Lo, Hi). 3116</PRE> 3117 This predicate constructs a new bounded real number with the specified 3118 bounds. In effect, the bounds are first cast to bounded reals, and then 3119 the new bounded real is constructed from the lower bound of Lo and the 3120 upper bound of Hi. 3121<P> 3122"), 3123 args:["Lo" : "A number.", 3124 "Hi" : "A number.", 3125 "Result" : "A variable."], 3126 exceptions:[4 : "Lo or Hi are not instantiated.", 3127 20 : "The lower bound of Lo is greater than the upper bound of Hi.", 3128 24 : "Lo or Hi are not numbers."], 3129 eg:" 3130Success: 3131 ?- breal_from_bounds(0.99, 1.01, X). 3132 X = 0.99__1.01 3133 3134 ?- breal_from_bounds(1_3, 2_3, X). 3135 X = 0.33333333333333326__0.66666666666666674 3136 3137Error: 3138 ?- breal_from_bounds(1, H, X). 3139 instantiation fault in breal_from_bounds(1, H, X) 3140 3141 ?- breal_from_bounds(\"a\", 2.0, X). 3142 number expected in breal_from_bounds(\"a\", 2.0, X) 3143 3144 ?- breal_from_bounds(2 + 4, 3 + 5, Z). 3145 number expected in breal_from_bounds(2 + 4, 3 + 5, Z) 3146 3147 ?- breal_from_bounds(1.0, 2.0, 1.0__2.0). 3148 type error in breal_from_bounds(1.0, 2.0, 1.0__2.0) 3149 3150 ?- breal_from_bounds(1.1, 0.9, X). 3151 arithmetic exception in breal_from_bounds(1.1, 0.9, X) 3152", 3153 see_also:[breal_min/2, breal_max/2, breal/1, breal/2, breal_bounds/3, (is) / 2]]). 3154 3155 3156