login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

spad
)abbrev domain RSPACE RealSpace
++ Author: kfp
++ Date Created: Thu Nov 06 03:51:56 CET 2014
++ License: BSD (same as Axiom)
++ Date Last Updated:
++ Basic Operations: 
++ Related Domains: 
++ Also See:
++ AMS Classifications:
++ Keywords: 
++ Examples:
++ References:
++
++ Description:
++ 
++
RealSpace(n) : Exports == Implementation where
NNI ==> NonNegativeInteger PI ==> PositiveInteger I ==> Integer R ==> Expression Integer -- Real n:NNI
Exports == Join(VectorSpace R , CoercibleTo OutputForm) with
coerce : % -> OutputForm coerce : List R -> % coerce : Vector R -> % coerce : List Symbol -> % coerce : R -> % coerce : % -> List R coerce : % -> Vector R
dot : (%,%) -> R dim : % -> NNI
"+" : (%,%) -> % "-" : (%,%) -> % "*" : (R,%) -> % "*" : (NNI,%) -> % "*" : (PI,%) -> % "*" : (I,%) -> % "/" : (%,R) -> %
"#" : % -> NNI "-" : % -> % "=" : (%,%) -> Boolean "~=": (%,%) -> Boolean
unitVector : PI -> % elt : (%,I) -> R
eval: (%, Equation R) -> % eval: (%, List Equation R) -> %
every?: (R -> Boolean, %) -> Boolean map: (R -> R, %) -> % -- strange, to check member?: (R, %) -> Boolean any?: (R -> Boolean, %) -> Boolean copy: % -> % D: (%, Symbol) -> % D: (%, Symbol, NonNegativeInteger) -> % D: (%, List Symbol) -> % D: (%, List Symbol, List NonNegativeInteger) -> %
dist : (%,%) -> R norm : % -> R tprod : (%,%) -> Matrix(R) -- tensor prod as Matrix Real -- _*_* : (%,%) -> RealSpace(n^2) cross : List(%) -> %
Implementation == DirectProduct(n,R) add
Rep := DirectProduct(n,R)
coerce(l:List R):% == #l=n => directProduct((vector l)::Vector(R))$Rep
coerce(l:Vector R):% == #l=n => directProduct(l)$Rep
coerce(l:List Symbol):% == #l=n => coerce([r::R for r in l])
coerce(x:R):% == x*unitVector(1)$Rep
coerce(v:%):List R == [v(j) for j in 1..#v]
coerce(v:%):Vector R == vector [v(j) for j in 1..#v]
dim(x:%):NNI == #(x::List R) -- n dist(x:%,y:%):R == sqrt dot(x-y,x-y) norm(x:%):R == sqrt dot(x,x)
tprod(x:%,y:%):Matrix(R) == matrix [[x.i*(y.j)::R for j in 1..n] for i in 1..n]
--wprod(x:%,y:%):Matrix(R) == (tprod(x,y)-tprod(y,x))/2::R
--_*_*(x:%,y:%):RealSpace(n^2) == -- X:List Real:=[] -- for i in 1..n repeat -- X:=append(X,[x.i*(y.j)::Real for j in 1..n]) -- X::RealSpace(n^2)
-- local ; better coerce in ??? vec2list(v:Vector(R)):List(R) == [v.j for j in 1..#v]
cross(X:List %):% == #X ~= n-1 => error "Wrong number of arguments." L:List(List R):=[r::List(R) for r in X] M:Matrix(R):= transpose matrix L S:List(List R):=[vec2list(row(M,i)) for i in 1..n] LS:List(Matrix R):=[matrix([S.i for i in 1..n | i~=j]) for j in 1..n] r:List R:=[(-1)^(i-1)::R*determinant(LS.i) for i in 1..n] r::Rep
)abbrev package INTVAL Interval ++ Author: kfp ++ Date Created: Thu Nov 06 02:46:09 CET 2014 ++ License: BSD (same as Axiom) ++ Date Last Updated: ++ Basic Operations: ++ Related Domains: ++ Also See: ++ AMS Classifications: ++ Keywords: ++ Examples: ++ References: ++ ++ Description: ++ ++ Interval(F:Field) : Exports == Implementation where
OF ==> OutputForm PI ==> PositiveInteger NNI ==> NonNegativeInteger Q ==> Fraction Integer
Exports == Join(CoercibleTo OutputForm) with
coerce : Tuple F -> % coerce : List F -> % coerce : % -> List F coerce : % -> OutputForm
closedInterval : (F,F) -> % openInterval : (F,F) -> % leftOpenInterval : (F,F) -> % rightOpenInterval : (F,F) -> %
lb : % -> F ub : % -> F topology : % -> OutputForm measure : % -> F
--"*" : (%,%) -> Cell(F,2) "*" : (F,%) -> % "+" : (F,%) -> %
Implementation == add
Rep:= Record(lb:F,ub:F,tp:String)
--check(x:%):% == --if number?(x.lb) and number?(x.ub) then --(x.ub)::Q < (x.lb)::Q => error "a>b" --x
coerce(l:Tuple F):% == -- does not work ???? length l ~=2 => error "Form expected: (a,b)" [select(l,0), select(l,1),"open"]::Rep
coerce(l:List F):% == #l ~=2 => error "Form expected: [a,b]" [l.1,l.2,"closed"]::Rep
coerce(x:%):List F == [x.lb,x.ub]
coerce(x:%):OF == x.tp = "closed" => hconcat ["[",x.lb::OF,",",x.ub::OF,"]"] x.tp = "open" => hconcat ["(",x.lb::OF,",",x.ub::OF,")"] x.tp = "leftOpen" => hconcat ["(",x.lb::OF,",",x.ub::OF,"]"] x.tp = "rightOpen" => hconcat ["[",x.lb::OF,",",x.ub::OF,")"]
lb(x) == x.lb ub(x) == x.ub topology(x:%):OF == x.tp::Symbol::OF measure(x:%):F == x.ub - x.lb
closedInterval(a,b) == [a,b,"closed"]::Rep openInterval(a,b) == [a,b,"open"]::Rep leftOpenInterval(a,b) == [a,b,"leftOpen"]::Rep rightOpenInterval(a,b) == [a,b,"rightOpen"]::Rep
--x:% * y:% == --m:Matrix(F):=matrix([[lb x,ub x],[lb y,ub y]]) --m::Cell(F,2)
a:F + x:% == [a+x.lb,a+x.ub,x.tp]::Rep a:F * x:% == [a*x.lb,a*x.ub,x.tp]::Rep
)abbrev domain CELL Cell ++ Author: kfp ++ Date Created: Thu Nov 06 02:39:44 CET 2014 ++ License: BSD (same as Axiom) ++ Date Last Updated: ++ Basic Operations: ++ Related Domains: ++ Also See: ++ AMS Classifications: ++ Keywords: ++ Examples: ++ References: ++ ++ Description: ++ ++ Cell(k,F) : Exports == Implementation where
NNI ==> NonNegativeInteger OF ==> OutputForm
F: Field k: NNI
Exports == Join(CoercibleTo OutputForm) with
coerce : Matrix F -> % coerce : % -> List Interval F -- ex. c::List(Interval RR) coerce : List Interval F -> % coerce : % -> OutputForm
measure : % -> F
Implementation == Matrix F add
Rep := Matrix F
coerce(c:%):List Interval F == lc:List(List F):=listOfLists(c) #lc ~= k => error "Wrong dimension" [i::Interval(F) for i in lc]
coerce(l:List Interval F):% == matrix [i::List(F) for i in l]
coerce(m:Matrix F):% == ncols m ~= 2 => error "Expecting (k x 2) matrix" nrows m ~= k => error "Expecting (k x 2) matrix" m
coerce(c:%):OF == (c::List Interval F)::OF
measure(c:%):F == L:=c::List Interval F mL:=[measure(v) for v in L] determinant(diagonalMatrix(mL))
-- pi:=%pi$RR
)abbrev domain SURF Surface ++ Author: kfp ++ Date Created: Tue Nov 11 21:57:52 CET 2014 ++ License: BSD (same as Axiom) ++ Date Last Updated: ++ Basic Operations: ++ Related Domains: ++ Also See: ++ AMS Classifications: ++ Keywords: ++ Examples: ++ References: ++ ++ Description: ++ k-surface ++ Surface(k,n) : Exports == Implementation where
PYI ==> Polynomial(Integer) NNI ==> NonNegativeInteger SYM ==> Symbol PI ==> PositiveInteger OF ==> OutputForm X ==> RealSpace(k) -> RealSpace(n) R ==> Expression Integer k:PI n:PI --V:Vectorspace(Real)
Exports == Join(CoercibleTo OutputForm) with
coerce : % -> OutputForm coerce : X -> % dim : % -> PI codim : % -> PI eval : (%, List R) -> RealSpace(n) eval : (%, List Symbol) -> RealSpace(n)
JacobianMatrix : (%, List Symbol) -> Matrix(R) TangentSpace : (%, List Symbol) -> List RealSpace(n) CoTangentSpace : (%, List Symbol) -> List RealSpace(n) normal : (%, List Symbol) -> RealSpace(n)
Implementation == add
Rep := Record(kk:PI,nn:PI,ff:X)
coerce(f:X):% == n>k and k>0 => [k,n,f]::Rep
coerce(S:%):OF == hconcat [S.kk::OF,"-surface in R^"::SYM::OF,S.nn::OF]
dim(S:%):PI == S.kk codim(S:%):PI == (S.nn - S.kk)::PI
eval(S:%,x:List R) == (S.ff)(x::RealSpace(k)) eval(S:%,x:List Symbol) == (S.ff)(x::RealSpace(k))
JacobianMatrix(S:%, x:List Symbol):Matrix(R) == transpose matrix [D((S.ff)(x::RealSpace(k)),u)::List(R) for u in x]
-- local ; better coerce in ??? vec2list(v:Vector(R)):List(R) == [v.j for j in 1..#v]
TangentSpace(S:%, x:List Symbol):List RealSpace(n) == J:=JacobianMatrix(S,x) [vec2list(column(J,j))::RealSpace(n) for j in 1..ncols(J)]
CoTangentSpace(S:%, x:List Symbol):List RealSpace(n) == ts:=TangentSpace(S,x) rd:=[[0::R for i in 1..n]::RealSpace(n) for j in k+1..n] Q:=append(ts,rd) QR:=[v::List R for v in Q] M:=(matrix QR)::Matrix(R) [vec2list(y)::RealSpace(n) for y in nullSpace(M)]
normal(S:%, x:List Symbol):RealSpace(n) == cs:=CoTangentSpace(S,x) #cs ~= 1 => error "Not a hypersurface" v:=cs.1 r:= sqrt(dot(v,v)) r = 0 => error "No normal; zero vector" v/r
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6605988090913086661-25px001.spad
      using old system compiler.
   RSPACE abbreviates domain RealSpace 
------------------------------------------------------------------------
   initializing NRLIB RSPACE for RealSpace 
   compiling into NRLIB RSPACE 
****** comp fails at level 1 with expression: ******
((|VectorSpace| (|Expression| (|Integer|))))
****** level 1  ******
$x:= (VectorSpace (Expression (Integer)))
$m:= $EmptyMode
$f:=
((((|n| # . #1=#) (|RealSpace| #) (|n| . #1#) (* #) ...)))
>> Apparent user error: cannot compile (VectorSpace (Expression (Integer)))

fricas
R ==> EXPR INT
Type: Void
fricas
R2 ==> RealSpace(2)
Type: Void
fricas
R3 ==> RealSpace(3)
Type: Void
fricas
f: R2 -> R3
RealSpace is an unknown constructor and so is unavailable. Did you mean to use -> but type something different instead?

Example Möbius strip as 2-surface

fricas
f([u,v::Symbol]::R2)
RealSpace is an unknown constructor and so is unavailable. Did you mean to use -> but type something different instead?

Cross product in R^n

fricas
X:=[a,b,c,d::R]::RealSpace(4)
RealSpace is an unknown constructor and so is unavailable. Did you mean to use -> but type something different instead?




  Subject:   Be Bold !!
  ( 14 subscribers )  
Please rate this page: