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

Edit detail for QuadraticForm revision 1 of 4

1 2 3 4
Editor: Bill Page
Time: 2008/09/25 21:22:50 GMT-7
Note: coerce to InputForm

changed:
-
\begin{spad}
QuadraticForm(n, K): T == Impl where
    n: PositiveInteger
    K: Field
    SM ==> SquareMatrix
    V  ==> DirectProduct

    T ==> AbelianGroup with
        quadraticForm: SM(n, K) -> %
            ++ quadraticForm(m) creates a quadratic form from a symmetric,
            ++ square matrix m.
        matrix: % -> SM(n, K)
            ++ matrix(qf) creates a square matrix from the quadratic form qf.
        elt: (%, V(n, K)) -> K
            ++ elt(qf,v) evaluates the quadratic form qf on the vector v,
            ++ producing a scalar.
        coerce: % -> InputForm

    Impl ==> SM(n,K) add
        Rep := SM(n,K)

        import List InputForm

        coerce(q:%):InputForm ==
            convert(['quadraticForm,algCoerceInteractive(q,SM(n,K),InputForm)$Lisp pretend InputForm])

        quadraticForm m ==
            not symmetric? m =>
                error "quadraticForm requires a symmetric matrix"
            m::%
        matrix q == q pretend SM(n,K)
        elt(q,v) == dot(v, (matrix q * v))
\end{spad}

\begin{axiom}
)show QuadraticForm
\end{axiom}

Test
\begin{axiom}
parse(s:String):InputForm == ncParseFromString(s)$Lisp pretend InputForm
parse("Integer")
\end{axiom}
\begin{axiom}
qf := quadraticForm matrix [[1,2],[2,-1]]
qf::InputForm
unparse %
parse %
interpret(%)$INFORM1(QuadraticForm(2,Fraction Integer))
\end{axiom}

fricas
(1) -> <spad>
QuadraticForm(n, K): T == Impl where
    n: PositiveInteger
    K: Field
    SM ==> SquareMatrix
    V  ==> DirectProduct
T ==> AbelianGroup with quadraticForm: SM(n, K) -> % ++ quadraticForm(m) creates a quadratic form from a symmetric, ++ square matrix m. matrix: % -> SM(n, K) ++ matrix(qf) creates a square matrix from the quadratic form qf. elt: (%, V(n, K)) -> K ++ elt(qf,v) evaluates the quadratic form qf on the vector v, ++ producing a scalar. coerce: % -> InputForm
Impl ==> SM(n,K) add Rep := SM(n,K)
import List InputForm
coerce(q:%):InputForm == convert(['quadraticForm,algCoerceInteractive(q,SM(n,K),InputForm)$Lisp pretend InputForm])
quadraticForm m == not symmetric? m => error "quadraticForm requires a symmetric matrix" m::% matrix q == q pretend SM(n,K) elt(q,v) == dot(v, (matrix q * v))</spad>
fricas
Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1043127575028836965-25px001.spad
      using old system compiler.
------------------------------------------------------------------------
   initializing NRLIB QFORM for QuadraticForm 
   compiling into NRLIB QFORM 
   importing List InputForm
   compiling exported coerce : % -> InputForm
****** comp fails at level 3 with expression: ******
error in function coerce 
(|convert| (|construct| '|quadraticForm| | << | (|pretend| ((|Sel| |Lisp| |algCoerceInteractive|) |q| (|SquareMatrix| |n| K) (|InputForm|)) (|InputForm|)) | >> |)) ****** level 3 ****** x:= (pretend ((Sel Lisp algCoerceInteractive) q (SquareMatrix n K) (InputForm)) (InputForm)) m:= (Symbol) f:= ((((|q| # #) (|#| #) (< #) (<= #) ...)))
>> Apparent user error: Cannot coerce (algCoerceInteractive q (SquareMatrix n K) (InputForm)) of mode (InputForm) to mode (Symbol)

fricas
)show QuadraticForm
QuadraticForm(n: PositiveInteger,K: Field) is a domain constructor Abbreviation for QuadraticForm is QFORM This constructor is exposed in this frame. ------------------------------- Operations --------------------------------
?*? : (Integer, %) -> % ?*? : (PositiveInteger, %) -> % ?+? : (%, %) -> % ?-? : (%, %) -> % -? : % -> % ?=? : (%, %) -> Boolean 0 : () -> % coerce : % -> OutputForm latex : % -> String matrix : % -> SquareMatrix(n,K) opposite? : (%, %) -> Boolean sample : () -> % zero? : % -> Boolean ?~=? : (%, %) -> Boolean ?*? : (NonNegativeInteger, %) -> % convert : % -> InputForm if SquareMatrix(n,K) has KONVERT(INFORM) elt : (%, DirectProduct(n,K)) -> K quadraticForm : SquareMatrix(n,K) -> % subtractIfCan : (%, %) -> Union(%,"failed")

Test

fricas
parse(s:String):InputForm == ncParseFromString(s)$Lisp pretend InputForm
Function declaration parse : String -> InputForm has been added to workspace.
Type: Void
fricas
parse("Integer")
fricas
Compiling function parse with type String -> InputForm

\label{eq1}\hbox{\axiomType{Integer}\ }(1)
Type: InputForm?

fricas
qf := quadraticForm matrix [[1,2],[2,-1]]

\label{eq2}\left[ 
\begin{array}{cc}
1 & 2 
\
2 & - 1 
(2)
Type: QuadraticForm?(2,Fraction(Integer))
fricas
qf::InputForm

\label{eq3}\left({quadraticForm \ {\left({squareMatrix \ {\left({matrix \ {\left({
\begin{array}{@{}l}
\displaystyle
construct \  \cdot 
\
\
\displaystyle
{\left({
\begin{array}{@{}l}
\displaystyle
construct \  \cdot 
\
\
\displaystyle
1 \  \cdot 
\
\
\displaystyle
2 
(3)
Type: InputForm?
fricas
unparse %

\label{eq4}\verb#"quadraticForm(squareMatrix(matrix([[1,2],[2,-1]])))"#(4)
Type: String
fricas
parse %

\label{eq5}\left({quadraticForm \ {\left({squareMatrix \ {\left({matrix \ {\left({
\begin{array}{@{}l}
\displaystyle
construct \  \cdot 
\
\
\displaystyle
{\left({
\begin{array}{@{}l}
\displaystyle
construct \  \cdot 
\
\
\displaystyle
1 \  \cdot 
\
\
\displaystyle
2 
(5)
Type: InputForm?
fricas
interpret(%)$INFORM1(QuadraticForm(2,Fraction Integer))

\label{eq6}\left[ 
\begin{array}{cc}
1 & 2 
\
2 & - 1 
(6)
Type: QuadraticForm?(2,Fraction(Integer))