/usr/lib/open-axiom/src/algebra/numeric.spad is in open-axiom-source 1.4.1+svn~2626-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | --Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
-- - Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
--
-- - Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in
-- the documentation and/or other materials provided with the
-- distribution.
--
-- - Neither the name of The Numerical ALgorithms Group Ltd. nor the
-- names of its contributors may be used to endorse or promote products
-- derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
)abbrev package NUMERIC Numeric
++ Author: Manuel Bronstein
++ Date Created: 21 Feb 1990
++ Date Last Updated: 17 August 1995, Mike Dewar
++ 24 January 1997, Miked Dewar (added partial operators)
++ Basic Operations: numeric, complexNumeric, numericIfCan, complexNumericIfCan
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description: Numeric provides real and complex numerical evaluation
++ functions for various symbolic types.
Numeric(S:ConvertibleTo Float): with
numeric: S -> Float
++ numeric(x) returns a real approximation of x.
numeric: (S, PositiveInteger) -> Float
++ numeric(x, n) returns a real approximation of x up to n decimal
++ places.
complexNumeric: S -> Complex Float
++ complexNumeric(x) returns a complex approximation of x.
complexNumeric: (S, PositiveInteger) -> Complex Float
++ complexNumeric(x, n) returns a complex approximation of x up
++ to n decimal places.
if S has CommutativeRing then
complexNumeric: Complex S -> Complex Float
++ complexNumeric(x) returns a complex approximation of x.
complexNumeric: (Complex S, PositiveInteger) -> Complex Float
++ complexNumeric(x, n) returns a complex approximation of x up
++ to n decimal places.
complexNumeric: Polynomial Complex S -> Complex Float
++ complexNumeric(x) returns a complex approximation of x.
complexNumeric: (Polynomial Complex S, PositiveInteger) -> Complex Float
++ complexNumeric(x, n) returns a complex approximation of x up
++ to n decimal places.
if S has Ring then
numeric: Polynomial S -> Float
++ numeric(x) returns a real approximation of x.
numeric: (Polynomial S, PositiveInteger) -> Float
++ numeric(x,n) returns a real approximation of x up to n decimal
++ places.
complexNumeric: Polynomial S -> Complex Float
++ complexNumeric(x) returns a complex approximation of x.
complexNumeric: (Polynomial S, PositiveInteger) -> Complex Float
++ complexNumeric(x, n) returns a complex approximation of x
++ up to n decimal places.
if S has IntegralDomain then
numeric: Fraction Polynomial S -> Float
++ numeric(x) returns a real approximation of x.
numeric: (Fraction Polynomial S, PositiveInteger) -> Float
++ numeric(x,n) returns a real approximation of x up to n decimal
++ places.
complexNumeric: Fraction Polynomial S -> Complex Float
++ complexNumeric(x) returns a complex approximation of x.
complexNumeric: (Fraction Polynomial S, PositiveInteger) -> Complex Float
++ complexNumeric(x, n) returns a complex approximation of x
complexNumeric: Fraction Polynomial Complex S -> Complex Float
++ complexNumeric(x) returns a complex approximation of x.
complexNumeric: (Fraction Polynomial Complex S, PositiveInteger) ->
Complex Float
++ complexNumeric(x, n) returns a complex approximation of x
++ up to n decimal places.
if S has OrderedSet then
numeric: Expression S -> Float
++ numeric(x) returns a real approximation of x.
numeric: (Expression S, PositiveInteger) -> Float
++ numeric(x, n) returns a real approximation of x up to n
++ decimal places.
complexNumeric: Expression S -> Complex Float
++ complexNumeric(x) returns a complex approximation of x.
complexNumeric: (Expression S, PositiveInteger) -> Complex Float
++ complexNumeric(x, n) returns a complex approximation of x
++ up to n decimal places.
complexNumeric: Expression Complex S -> Complex Float
++ complexNumeric(x) returns a complex approximation of x.
complexNumeric: (Expression Complex S, PositiveInteger) -> Complex Float
++ complexNumeric(x, n) returns a complex approximation of x
++ up to n decimal places.
if S has CommutativeRing then
complexNumericIfCan: Polynomial Complex S -> Union(Complex Float,"failed")
++ complexNumericIfCan(x) returns a complex approximation of x,
++ or "failed" if \axiom{x} is not constant.
complexNumericIfCan: (Polynomial Complex S, PositiveInteger) -> Union(Complex Float,"failed")
++ complexNumericIfCan(x, n) returns a complex approximation of x up
++ to n decimal places, or "failed" if \axiom{x} is not a constant.
if S has Ring then
numericIfCan: Polynomial S -> Union(Float,"failed")
++ numericIfCan(x) returns a real approximation of x,
++ or "failed" if \axiom{x} is not a constant.
numericIfCan: (Polynomial S, PositiveInteger) -> Union(Float,"failed")
++ numericIfCan(x,n) returns a real approximation of x up to n decimal
++ places, or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: Polynomial S -> Union(Complex Float,"failed")
++ complexNumericIfCan(x) returns a complex approximation of x,
++ or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: (Polynomial S, PositiveInteger) -> Union(Complex Float,"failed")
++ complexNumericIfCan(x, n) returns a complex approximation of x
++ up to n decimal places, or "failed" if \axiom{x} is not a constant.
if S has IntegralDomain then
numericIfCan: Fraction Polynomial S -> Union(Float,"failed")
++ numericIfCan(x) returns a real approximation of x,
++ or "failed" if \axiom{x} is not a constant.
numericIfCan: (Fraction Polynomial S, PositiveInteger) -> Union(Float,"failed")
++ numericIfCan(x,n) returns a real approximation of x up to n decimal
++ places, or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: Fraction Polynomial S -> Union(Complex Float,"failed")
++ complexNumericIfCan(x) returns a complex approximation of x,
++ or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: (Fraction Polynomial S, PositiveInteger) -> Union(Complex Float,"failed")
++ complexNumericIfCan(x, n) returns a complex approximation of x,
++ or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: Fraction Polynomial Complex S -> Union(Complex Float,"failed")
++ complexNumericIfCan(x) returns a complex approximation of x,
++ or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: (Fraction Polynomial Complex S, PositiveInteger) ->
Union(Complex Float,"failed")
++ complexNumericIfCan(x, n) returns a complex approximation of x
++ up to n decimal places, or "failed" if \axiom{x} is not a constant.
if S has OrderedSet then
numericIfCan: Expression S -> Union(Float,"failed")
++ numericIfCan(x) returns a real approximation of x,
++ or "failed" if \axiom{x} is not a constant.
numericIfCan: (Expression S, PositiveInteger) -> Union(Float,"failed")
++ numericIfCan(x, n) returns a real approximation of x up to n
++ decimal places, or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: Expression S -> Union(Complex Float,"failed")
++ complexNumericIfCan(x) returns a complex approximation of x,
++ or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: (Expression S, PositiveInteger) ->
Union(Complex Float,"failed")
++ complexNumericIfCan(x, n) returns a complex approximation of x
++ up to n decimal places, or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: Expression Complex S -> Union(Complex Float,"failed")
++ complexNumericIfCan(x) returns a complex approximation of x,
++ or "failed" if \axiom{x} is not a constant.
complexNumericIfCan: (Expression Complex S, PositiveInteger) ->
Union(Complex Float,"failed")
++ complexNumericIfCan(x, n) returns a complex approximation of x
++ up to n decimal places, or "failed" if \axiom{x} is not a constant.
== add
if S has CommutativeRing then
complexNumericIfCan(p:Polynomial Complex S) ==
p' : Union(Complex(S),"failed") := retractIfCan p
p' case "failed" => "failed"
complexNumeric(p')
complexNumericIfCan(p:Polynomial Complex S,n:PositiveInteger) ==
p' : Union(Complex(S),"failed") := retractIfCan p
p' case "failed" => "failed"
complexNumeric(p',n)
if S has Ring then
numericIfCan(p:Polynomial S) ==
p' : Union(S,"failed") := retractIfCan p
p' case "failed" => "failed"
numeric(p')
complexNumericIfCan(p:Polynomial S) ==
p' : Union(S,"failed") := retractIfCan p
p' case "failed" => "failed"
complexNumeric(p')
complexNumericIfCan(p:Polynomial S, n:PositiveInteger) ==
p' : Union(S,"failed") := retractIfCan p
p' case "failed" => "failed"
complexNumeric(p', n)
numericIfCan(p:Polynomial S, n:PositiveInteger) ==
old := digits(n)$Float
ans := numericIfCan p
digits(old)$Float
ans
if S has IntegralDomain then
numericIfCan(f:Fraction Polynomial S)==
num := numericIfCan(numer(f))
num case "failed" => "failed"
den := numericIfCan(denom f)
den case "failed" => "failed"
num/den
complexNumericIfCan(f:Fraction Polynomial S) ==
num := complexNumericIfCan(numer f)
num case "failed" => "failed"
den := complexNumericIfCan(denom f)
den case "failed" => "failed"
num/den
complexNumericIfCan(f:Fraction Polynomial S, n:PositiveInteger) ==
num := complexNumericIfCan(numer f, n)
num case "failed" => "failed"
den := complexNumericIfCan(denom f, n)
den case "failed" => "failed"
num/den
numericIfCan(f:Fraction Polynomial S, n:PositiveInteger) ==
old := digits(n)$Float
ans := numericIfCan f
digits(old)$Float
ans
complexNumericIfCan(f:Fraction Polynomial Complex S) ==
num := complexNumericIfCan(numer f)
num case "failed" => "failed"
den := complexNumericIfCan(denom f)
den case "failed" => "failed"
num/den
complexNumericIfCan(f:Fraction Polynomial Complex S, n:PositiveInteger) ==
num := complexNumericIfCan(numer f, n)
num case "failed" => "failed"
den := complexNumericIfCan(denom f, n)
den case "failed" => "failed"
num/den
if S has OrderedSet then
numericIfCan(x:Expression S) ==
retractIfCan(map(convert, x)$ExpressionFunctions2(S, Float))
--s2cs(u:S):Complex(S) == complex(u,0)
complexNumericIfCan(x:Expression S) ==
complexNumericIfCan map(coerce, x)$ExpressionFunctions2(S,Complex S)
numericIfCan(x:Expression S, n:PositiveInteger) ==
old := digits(n)$Float
x' : Expression Float := map(convert, x)$ExpressionFunctions2(S, Float)
ans : Union(Float,"failed") := retractIfCan x'
digits(old)$Float
ans
complexNumericIfCan(x:Expression S, n:PositiveInteger) ==
old := digits(n)$Float
x' : Expression Complex S := map(coerce, x)$ExpressionFunctions2(S, Complex S)
ans : Union(Complex Float,"failed") := complexNumericIfCan(x')
digits(old)$Float
ans
if S has RealConstant then
complexNumericIfCan(x:Expression Complex S) ==
retractIfCan(map(convert, x)$ExpressionFunctions2(Complex S,Complex Float))
complexNumericIfCan(x:Expression Complex S, n:PositiveInteger) ==
old := digits(n)$Float
x' : Expression Complex Float :=
map(convert, x)$ExpressionFunctions2(Complex S,Complex Float)
ans : Union(Complex Float,"failed") := retractIfCan x'
digits(old)$Float
ans
else
convert(x:Complex S):Complex(Float)==map(convert,x)$ComplexFunctions2(S,Float)
complexNumericIfCan(x:Expression Complex S) ==
retractIfCan(map(convert, x)$ExpressionFunctions2(Complex S,Complex Float))
complexNumericIfCan(x:Expression Complex S, n:PositiveInteger) ==
old := digits(n)$Float
x' : Expression Complex Float :=
map(convert, x)$ExpressionFunctions2(Complex S,Complex Float)
ans : Union(Complex Float,"failed") := retractIfCan x'
digits(old)$Float
ans
numeric(s:S) == convert(s)@Float
if S has ConvertibleTo Complex Float then
complexNumeric(s:S) == convert(s)@Complex(Float)
complexNumeric(s:S, n:PositiveInteger) ==
old := digits(n)$Float
ans := complexNumeric s
digits(old)$Float
ans
else
complexNumeric(s:S) == convert(s)@Float :: Complex(Float)
complexNumeric(s:S,n:PositiveInteger) ==
numeric(s, n)::Complex(Float)
if S has CommutativeRing then
complexNumeric(p:Polynomial Complex S) ==
p' : Union(Complex(S),"failed") := retractIfCan p
p' case "failed" =>
error "Cannot compute the numerical value of a non-constant polynomial"
complexNumeric(p')
complexNumeric(p:Polynomial Complex S,n:PositiveInteger) ==
p' : Union(Complex(S),"failed") := retractIfCan p
p' case "failed" =>
error "Cannot compute the numerical value of a non-constant polynomial"
complexNumeric(p',n)
if S has RealConstant then
complexNumeric(s:Complex S) == convert(s)$Complex(S)
complexNumeric(s:Complex S, n:PositiveInteger) ==
old := digits(n)$Float
ans := complexNumeric s
digits(old)$Float
ans
else if Complex(S) has ConvertibleTo(Complex Float) then
complexNumeric(s:Complex S) == convert(s)@Complex(Float)
complexNumeric(s:Complex S, n:PositiveInteger) ==
old := digits(n)$Float
ans := complexNumeric s
digits(old)$Float
ans
else
complexNumeric(s:Complex S) ==
s' : Union(S,"failed") := retractIfCan s
s' case "failed" =>
error "Cannot compute the numerical value of a non-constant object"
complexNumeric(s')
complexNumeric(s:Complex S, n:PositiveInteger) ==
s' : Union(S,"failed") := retractIfCan s
s' case "failed" =>
error "Cannot compute the numerical value of a non-constant object"
old := digits(n)$Float
ans := complexNumeric s'
digits(old)$Float
ans
numeric(s:S, n:PositiveInteger) ==
old := digits(n)$Float
ans := numeric s
digits(old)$Float
ans
if S has Ring then
numeric(p:Polynomial S) ==
p' : Union(S,"failed") := retractIfCan p
p' case "failed" => error
"Can only compute the numerical value of a constant, real-valued polynomial"
numeric(p')
complexNumeric(p:Polynomial S) ==
p' : Union(S,"failed") := retractIfCan p
p' case "failed" =>
error "Cannot compute the numerical value of a non-constant polynomial"
complexNumeric(p')
complexNumeric(p:Polynomial S, n:PositiveInteger) ==
p' : Union(S,"failed") := retractIfCan p
p' case "failed" =>
error "Cannot compute the numerical value of a non-constant polynomial"
complexNumeric(p', n)
numeric(p:Polynomial S, n:PositiveInteger) ==
old := digits(n)$Float
ans := numeric p
digits(old)$Float
ans
if S has IntegralDomain then
numeric(f:Fraction Polynomial S)==
numeric(numer(f)) / numeric(denom f)
complexNumeric(f:Fraction Polynomial S) ==
complexNumeric(numer f)/complexNumeric(denom f)
complexNumeric(f:Fraction Polynomial S, n:PositiveInteger) ==
complexNumeric(numer f, n)/complexNumeric(denom f, n)
numeric(f:Fraction Polynomial S, n:PositiveInteger) ==
old := digits(n)$Float
ans := numeric f
digits(old)$Float
ans
complexNumeric(f:Fraction Polynomial Complex S) ==
complexNumeric(numer f)/complexNumeric(denom f)
complexNumeric(f:Fraction Polynomial Complex S, n:PositiveInteger) ==
complexNumeric(numer f, n)/complexNumeric(denom f, n)
if S has OrderedSet then
numeric(x:Expression S) ==
x' : Union(Float,"failed") :=
retractIfCan(map(convert, x)$ExpressionFunctions2(S, Float))
x' case "failed" => error
"Can only compute the numerical value of a constant, real-valued Expression"
x'
complexNumeric(x:Expression S) ==
x' : Union(Complex Float,"failed") := retractIfCan(
map(complexNumeric, x)$ExpressionFunctions2(S,Complex Float))
x' case "failed" =>
error "Cannot compute the numerical value of a non-constant expression"
x'
numeric(x:Expression S, n:PositiveInteger) ==
old := digits(n)$Float
x' : Expression Float := map(convert, x)$ExpressionFunctions2(S, Float)
ans : Union(Float,"failed") := retractIfCan x'
digits(old)$Float
ans case "failed" => error
"Can only compute the numerical value of a constant, real-valued Expression"
ans
complexNumeric(x:Expression S, n:PositiveInteger) ==
old := digits(n)$Float
x' : Expression Complex Float :=
map(complexNumeric, x)$ExpressionFunctions2(S,Complex Float)
ans : Union(Complex Float,"failed") := retractIfCan x'
digits(old)$Float
ans case "failed" =>
error "Cannot compute the numerical value of a non-constant expression"
ans
complexNumeric(x:Expression Complex S) ==
x' : Union(Complex Float,"failed") := retractIfCan(
map(complexNumeric, x)$ExpressionFunctions2(Complex S,Complex Float))
x' case "failed" =>
error "Cannot compute the numerical value of a non-constant expression"
x'
complexNumeric(x:Expression Complex S, n:PositiveInteger) ==
old := digits(n)$Float
x' : Expression Complex Float :=
map(complexNumeric, x)$ExpressionFunctions2(Complex S,Complex Float)
ans : Union(Complex Float,"failed") := retractIfCan x'
digits(old)$Float
ans case "failed" =>
error "Cannot compute the numerical value of a non-constant expression"
ans
)abbrev package DRAWHACK DrawNumericHack
++ Author: Manuel Bronstein
++ Date Created: 21 Feb 1990
++ Date Last Updated: 21 Feb 1990
++ Basic Operations: coerce
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description: Hack for the draw interface. DrawNumericHack provides
++ a "coercion" from something of the form \spad{x = a..b} where \spad{a}
++ and b are
++ formal expressions to a binding of the form \spad{x = c..d} where c and d
++ are the numerical values of \spad{a} and b. This "coercion" fails if
++ \spad{a} and b contains symbolic variables, but is meant for expressions
++ involving %pi.
++ NOTE: This is meant for internal use only.
DrawNumericHack(R:Join(OrderedSet,IntegralDomain,ConvertibleTo Float)):
with coerce: SegmentBinding Expression R -> SegmentBinding Float
++ coerce(x = a..b) returns \spad{x = c..d} where c and d are the
++ numerical values of \spad{a} and b.
== add
coerce s ==
map(numeric$Numeric(R),s)$SegmentBindingFunctions2(Expression R, Float)
|