This file is indexed.

/usr/share/axiom-20170501/src/algebra/FINAALG.spad is in axiom-source 20170501-3.

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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
)abbrev category FINAALG FiniteRankNonAssociativeAlgebra
++ Author: J. Grabmeier, R. Wisbauer
++ Date Created: 01 March 1991
++ Date Last Updated: 12 June 1991
++ References:
++   R.D. Schafer: An Introduction to Nonassociative Algebras
++   Academic Press, New York, 1966
++
++   R. Wisbauer: Bimodule Structure of Algebra
++   Lecture Notes Univ. Duesseldorf 1991
++ Description:
++ A FiniteRankNonAssociativeAlgebra is a non associative algebra over
++ a commutative ring R which is a free \spad{R}-module of finite rank.

FiniteRankNonAssociativeAlgebra(R) : Category == SIG where
  R : CommutativeRing

  SIG ==> NonAssociativeAlgebra R with

    someBasis : () -> Vector %
      ++ someBasis() returns some \spad{R}-module basis.

    rank : () -> PositiveInteger
      ++ rank() returns the rank of the algebra as \spad{R}-module.

    conditionsForIdempotents : Vector % -> List Polynomial R
      ++ conditionsForIdempotents([v1,...,vn]) determines a complete list
      ++ of polynomial equations for the coefficients of idempotents
      ++ with respect to the \spad{R}-module basis \spad{v1},...,\spad{vn}.

    structuralConstants : Vector % -> Vector Matrix R
      ++ structuralConstants([v1,v2,...,vm]) calculates the structural
      ++ constants \spad{[(gammaijk) for k in 1..m]} defined by
      ++ \spad{vi * vj = gammaij1 * v1 + ... + gammaijm * vm},
      ++ where \spad{[v1,...,vm]} is an \spad{R}-module basis
      ++ of a subalgebra.

    leftRegularRepresentation : (% , Vector %) -> Matrix R
      ++ leftRegularRepresentation(a,[v1,...,vn]) returns the matrix of
      ++ the linear map defined by left multiplication by \spad{a}
      ++ with respect to the \spad{R}-module basis \spad{[v1,...,vn]}.

    rightRegularRepresentation : (% , Vector %) -> Matrix R
      ++ rightRegularRepresentation(a,[v1,...,vn]) returns the matrix of
      ++ the linear map defined by right multiplication by \spad{a}
      ++ with respect to the \spad{R}-module basis \spad{[v1,...,vn]}.

    leftTrace : %  -> R
      ++ leftTrace(a) returns the trace of the left regular representation
      ++ of \spad{a}.

    rightTrace : %  -> R
      ++ rightTrace(a) returns the trace of the right regular representation
      ++ of \spad{a}.

    leftNorm : %  -> R
      ++ leftNorm(a) returns the determinant of the left regular 
      ++ representation of \spad{a}.

    rightNorm : %  -> R
      ++ rightNorm(a) returns the determinant of the right regular
      ++ representation of \spad{a}.

    coordinates : (%, Vector %) -> Vector R
      ++ coordinates(a,[v1,...,vn]) returns the coordinates of \spad{a}
      ++ with respect to the \spad{R}-module basis \spad{v1},...,\spad{vn}.

    coordinates : (Vector %, Vector %) -> Matrix R
      ++ coordinates([a1,...,am],[v1,...,vn]) returns a matrix whose
      ++ i-th row is formed by the coordinates of \spad{ai}
      ++ with respect to the \spad{R}-module basis \spad{v1},...,\spad{vn}.

    represents : (Vector R, Vector %) -> %
      ++ represents([a1,...,am],[v1,...,vm]) returns the linear
      ++ combination \spad{a1*vm + ... + an*vm}.

    leftDiscriminant : Vector % -> R
      ++ leftDiscriminant([v1,...,vn]) returns  the determinant of the
      ++ \spad{n}-by-\spad{n} matrix whose element at the \spad{i}-th row
      ++ and \spad{j}-th column is given by the left trace of the product
      ++ \spad{vi*vj}. Note that this is the same as 
      ++ \spad{determinant(leftTraceMatrix([v1,...,vn]))}.

    rightDiscriminant : Vector % -> R
      ++ rightDiscriminant([v1,...,vn]) returns  the determinant of the
      ++ \spad{n}-by-\spad{n} matrix whose element at the \spad{i}-th row
      ++ and \spad{j}-th column is given by the right trace of the product
      ++ \spad{vi*vj}. Note that this is the same as 
      ++ \spad{determinant(rightTraceMatrix([v1,...,vn]))}.

    leftTraceMatrix : Vector % -> Matrix R
      ++ leftTraceMatrix([v1,...,vn]) is the \spad{n}-by-\spad{n} matrix
      ++ whose element at the \spad{i}-th row and \spad{j}-th column is given
      ++ by the left trace of the product \spad{vi*vj}.

    rightTraceMatrix : Vector % -> Matrix R
      ++ rightTraceMatrix([v1,...,vn]) is the \spad{n}-by-\spad{n} matrix
      ++ whose element at the \spad{i}-th row and \spad{j}-th column is given
      ++ by the right trace of the product \spad{vi*vj}.

    leftCharacteristicPolynomial : % -> SparseUnivariatePolynomial R
      ++ leftCharacteristicPolynomial(a) returns the characteristic
      ++ polynomial of the left regular representation of \spad{a}
      ++ with respect to any basis.

    rightCharacteristicPolynomial : % -> SparseUnivariatePolynomial R
      ++ rightCharacteristicPolynomial(a) returns the characteristic
      ++ polynomial of the right regular representation of \spad{a}
      ++ with respect to any basis.

    --we not necessarily have a unit
    --if R has CharacteristicZero then CharacteristicZero
    --if R has CharacteristicNonZero then CharacteristicNonZero

    commutative? : ()-> Boolean
      ++ commutative?() tests if multiplication in the algebra
      ++ is commutative.

    antiCommutative? : ()-> Boolean
      ++ antiCommutative?() tests if \spad{a*a = 0}
      ++ for all \spad{a} in the algebra.
      ++ Note that this implies \spad{a*b + b*a = 0} for all 
      ++ \spad{a} and \spad{b}.

    associative? : ()-> Boolean
      ++ associative?() tests if multiplication in algebra
      ++ is associative.

    antiAssociative? : ()-> Boolean
      ++ antiAssociative?() tests if multiplication in algebra
      ++ is anti-associative, that is, \spad{(a*b)*c + a*(b*c) = 0}
      ++ for all \spad{a},b,c in the algebra.

    leftAlternative? : ()-> Boolean
      ++ leftAlternative?() tests if \spad{2*associator(a,a,b) = 0}
      ++ for all \spad{a}, b in the algebra.
      ++ Note that we only can test this; in general we don't know
      ++ whether \spad{2*a=0} implies \spad{a=0}.

    rightAlternative? : ()-> Boolean
      ++ rightAlternative?() tests if \spad{2*associator(a,b,b) = 0}
      ++ for all \spad{a}, b in the algebra.
      ++ Note that we only can test this; in general we don't know
      ++ whether \spad{2*a=0} implies \spad{a=0}.

    flexible? : ()->  Boolean
      ++ flexible?() tests if \spad{2*associator(a,b,a) = 0}
      ++ for all \spad{a}, b in the algebra.
      ++ Note that we only can test this; in general we don't know
      ++ whether \spad{2*a=0} implies \spad{a=0}.

    alternative? : ()-> Boolean
      ++ alternative?() tests if
      ++ \spad{2*associator(a,a,b) = 0 = 2*associator(a,b,b)}
      ++ for all \spad{a}, b in the algebra.
      ++ Note that we only can test this; in general we don't know
      ++ whether \spad{2*a=0} implies \spad{a=0}.

    powerAssociative? : ()-> Boolean
      ++ powerAssociative?() tests if all subalgebras
      ++ generated by a single element are associative.

    jacobiIdentity? : () -> Boolean
      ++ jacobiIdentity?() tests if \spad{(a*b)*c + (b*c)*a + (c*a)*b = 0}
      ++ for all \spad{a},b,c in the algebra. For example, this holds
      ++ for crossed products of 3-dimensional vectors.

    lieAdmissible? : () -> Boolean
      ++ lieAdmissible?() tests if the algebra defined by the commutators
      ++ is a Lie algebra, that is, satisfies the Jacobi identity.
      ++ The property of anticommutativity follows from definition.

    jordanAdmissible? : () -> Boolean
      ++ jordanAdmissible?() tests if 2 is invertible in the
      ++ coefficient domain and the multiplication defined by
      ++ \spad{(1/2)(a*b+b*a)} determines a
      ++ Jordan algebra, that is, satisfies the Jordan identity.
      ++ The property of \spadatt{commutative("*")}
      ++ follows from by definition.

    noncommutativeJordanAlgebra? : () -> Boolean
      ++ noncommutativeJordanAlgebra?() tests if the algebra
      ++ is flexible and Jordan admissible.

    jordanAlgebra? : () -> Boolean
      ++ jordanAlgebra?() tests if the algebra is commutative,
      ++ characteristic is not 2, and \spad{(a*b)*a**2 - a*(b*a**2) = 0}
      ++ for all \spad{a},b,c in the algebra (Jordan identity).
      ++ Example:
      ++ for every associative algebra \spad{(A,+,@)} we can construct a
      ++ Jordan algebra \spad{(A,+,*)}, where \spad{a*b := (a@b+b@a)/2}.

    lieAlgebra? : () -> Boolean
      ++ lieAlgebra?() tests if the algebra is anticommutative
      ++ and \spad{(a*b)*c + (b*c)*a + (c*a)*b = 0}
      ++ for all \spad{a},b,c in the algebra (Jacobi identity).
      ++ Example:
      ++ for every associative algebra \spad{(A,+,@)} we can construct a
      ++ Lie algebra \spad{(A,+,*)}, where \spad{a*b := a@b-b@a}.

    if R has IntegralDomain then

      -- we not neccessarily have a unit, hence we don't inherit
      -- the next 3 functions and hence copy them from MonadWithUnit:

      recip : % -> Union(%,"failed")
        ++ recip(a) returns an element, which is both a left and a right
        ++ inverse of \spad{a},
        ++ or \spad{"failed"} if there is no unit element, if such an
        ++ element doesn't exist or cannot be determined (see unitsKnown).

      leftRecip : % -> Union(%,"failed")
        ++ leftRecip(a) returns an element, which is a left inverse of 
        ++ \spad{a}, or \spad{"failed"} if there is no unit element, if such
        ++ an element doesn't exist or cannot be determined (see unitsKnown).

      rightRecip : % -> Union(%,"failed")
        ++ rightRecip(a) returns an element, which is a right inverse of
        ++ \spad{a},
        ++ or \spad{"failed"} if there is no unit element, if such an
        ++ element doesn't exist or cannot be determined (see unitsKnown).

      associatorDependence : () -> List Vector R
        ++ associatorDependence() looks for the associator identities, that
        ++ is, finds a basis of the solutions of the linear combinations of the
        ++ six permutations of \spad{associator(a,b,c)} which yield 0,
        ++ for all \spad{a},b,c in the algebra.
        ++ The order of the permutations is \spad{123 231 312 132 321 213}.

      leftMinimalPolynomial : % -> SparseUnivariatePolynomial R
        ++ leftMinimalPolynomial(a) returns the polynomial determined by the
        ++ smallest non-trivial linear combination of left powers of 
        ++ \spad{a}. Note that the polynomial never has a constant term as in 
        ++ general the algebra has no unit.

      rightMinimalPolynomial : % -> SparseUnivariatePolynomial R
        ++ rightMinimalPolynomial(a) returns the polynomial determined by the
        ++ smallest non-trivial linear
        ++ combination of right powers of \spad{a}.
        ++ Note that the polynomial never has a constant term as in general
        ++ the algebra has no unit.

      leftUnits : () -> Union(Record(particular: %, basis: List %), "failed")
        ++ leftUnits() returns the affine space of all left units of the
        ++ algebra, or \spad{"failed"} if there is none.

      rightUnits : () -> Union(Record(particular: %, basis: List %), "failed")
        ++ rightUnits() returns the affine space of all right units of the
        ++ algebra, or \spad{"failed"} if there is none.

      leftUnit : () -> Union(%, "failed")
        ++ leftUnit() returns a left unit of the algebra
        ++ (not necessarily unique), or \spad{"failed"} if there is none.

      rightUnit : () -> Union(%, "failed")
        ++ rightUnit() returns a right unit of the algebra
        ++ (not necessarily unique), or \spad{"failed"} if there is none.

      unit : () -> Union(%, "failed")
        ++ unit() returns a unit of the algebra (necessarily unique),
        ++ or \spad{"failed"} if there is none.

      -- we not necessarily have a unit, hence we can't say anything
      -- about characteristic
      -- if R has CharacteristicZero then CharacteristicZero
      -- if R has CharacteristicNonZero then CharacteristicNonZero

      unitsKnown
        ++ unitsKnown means that \spadfun{recip} truly yields reciprocal
        ++ or \spad{"failed"} if not a unit,
        ++ similarly for \spadfun{leftRecip} and
        ++ \spadfun{rightRecip}. The reason is that we use left, respectively
        ++ right, minimal polynomials to decide this question.
   add

      --n := rank()
      --b := someBasis()
      --gamma : Vector Matrix R := structuralConstants b
      -- here is a problem: there seems to be a problem having local
      -- variables in the capsule of a category, furthermore
      -- see the commented code of conditionsForIdempotents, where
      -- we call structuralConstants, which also doesn't work
      -- at runtime, is not properly inherited, hence for
      -- the moment we put the code for
      -- conditionsForIdempotents, structuralConstants, unit, leftUnit,
      -- rightUnit into the domain constructor ALGSC
      V  ==> Vector
      M  ==> Matrix
      REC  ==> Record(particular: Union(V R,"failed"),basis: List V R)
      LSMP ==> LinearSystemMatrixPackage(R,V R,V R, M R)
  
  
      SUP ==>  SparseUnivariatePolynomial
      NNI ==>  NonNegativeInteger
      -- next 2 functions: use a general characteristicPolynomial

      leftCharacteristicPolynomial a ==
         n := rank()$%
         ma : Matrix R := leftRegularRepresentation(a,someBasis()$%)
         mb : Matrix SUP R := zero(n,n)
         for i in 1..n repeat
           for j in 1..n repeat
             mb(i,j):=
               i=j => monomial(ma(i,j),0)$SUP(R) - monomial(1,1)$SUP(R)
               monomial(ma(i,j),1)$SUP(R)
         determinant mb
  
      rightCharacteristicPolynomial a ==
         n := rank()$%
         ma : Matrix R := rightRegularRepresentation(a,someBasis()$%)
         mb : Matrix SUP R := zero(n,n)
         for i in 1..n repeat
           for j in 1..n repeat
             mb(i,j):=
               i=j => monomial(ma(i,j),0)$SUP(R) - monomial(1,1)$SUP(R)
               monomial(ma(i,j),1)$SUP(R)
         determinant mb
  
      leftTrace a ==
        t : R := 0
        ma : Matrix R := leftRegularRepresentation(a,someBasis()$%)
        for i in 1..rank()$% repeat
          t := t + elt(ma,i,i)
        t
  
      rightTrace a ==
        t : R := 0
        ma : Matrix R := rightRegularRepresentation(a,someBasis()$%)
        for i in 1..rank()$% repeat
          t := t + elt(ma,i,i)
        t
  
      leftNorm a == determinant leftRegularRepresentation(a,someBasis()$%)
  
      rightNorm a == determinant rightRegularRepresentation(a,someBasis()$%)
  
      antiAssociative?() ==
        b := someBasis()
        n := rank()
        for i in 1..n repeat
          for j in 1..n repeat
            for k in 1..n repeat
              not zero? ( (b.i*b.j)*b.k + b.i*(b.j*b.k) )  =>
                messagePrint("algebra is not anti-associative")$OutputForm
                return false
        messagePrint("algebra is anti-associative")$OutputForm
        true
  
      jordanAdmissible?() ==
        b := someBasis()
        n := rank()
        recip(2 * 1$R) case "failed" =>
          messagePrint("this algebra is not Jordan admissible, " _
           "as 2 is not invertible in the ground ring")$OutputForm
          false
        for i in 1..n repeat
         for j in 1..n repeat
          for k in 1..n repeat
           for l in 1..n repeat
             not zero? ( _
               antiCommutator(antiCommutator(b.i,b.j),_
                              antiCommutator(b.l,b.k)) + _
               antiCommutator(antiCommutator(b.l,b.j),_
                              antiCommutator(b.k,b.i)) + _
               antiCommutator(antiCommutator(b.k,b.j),_
                              antiCommutator(b.i,b.l))   _
                        ) =>
                 messagePrint(_
                           "this algebra is not Jordan admissible")$OutputForm
                 return false
        messagePrint("this algebra is Jordan admissible")$OutputForm
        true
  
      lieAdmissible?() ==
        n := rank()
        b := someBasis()
        for i in 1..n repeat
         for j in 1..n repeat
          for k in 1..n repeat
            not zero? (commutator(commutator(b.i,b.j),b.k) _
                    + commutator(commutator(b.j,b.k),b.i) _
                    + commutator(commutator(b.k,b.i),b.j))   =>
              messagePrint("this algebra is not Lie admissible")$OutputForm
              return false
        messagePrint("this algebra is Lie admissible")$OutputForm
        true
  
      structuralConstants b ==
        --n := rank()
        -- be careful with the possibility that b is not a basis
        m : NonNegativeInteger := (maxIndex b) :: NonNegativeInteger
        sC : Vector Matrix R := [new(m,m,0$R) for k in 1..m]
        for i in 1..m repeat
          for j in 1..m repeat
            covec : Vector R := coordinates(b.i * b.j, b)
            for k in 1..m repeat
               setelt( sC.k, i, j, covec.k )
        sC
  
      if R has IntegralDomain then
  
        leftRecip x ==
          zero? x => "failed"
          lu := leftUnit()
          lu case "failed" => "failed"
          b := someBasis()
          xx : % := (lu :: %)
          k  : PositiveInteger := 1
          cond : Matrix R := coordinates(xx,b) :: Matrix(R)
          listOfPowers : List % := [xx]
          while rank(cond) = k repeat
            k := k+1
            xx := xx*x
            listOfPowers := cons(xx,listOfPowers)
            cond := horizConcat(cond, coordinates(xx,b) :: Matrix(R) )
          vectorOfCoef : Vector R := (nullSpace(cond)$Matrix(R)).first
          invC := recip vectorOfCoef.1
          invC case "failed" => "failed"
          invCR : R :=  - (invC :: R)
          reduce(_+,[(invCR*vectorOfCoef.i)*power for i in _
           2..maxIndex vectorOfCoef for power in reverse listOfPowers])
  
        rightRecip x ==
          zero? x => "failed"
          ru := rightUnit()
          ru case "failed" => "failed"
          b := someBasis()
          xx : % := (ru :: %)
          k  : PositiveInteger := 1
          cond : Matrix R := coordinates(xx,b) :: Matrix(R)
          listOfPowers : List % := [xx]
          while rank(cond) = k repeat
            k := k+1
            xx := x*xx
            listOfPowers := cons(xx,listOfPowers)
            cond := horizConcat(cond, coordinates(xx,b) :: Matrix(R) )
          vectorOfCoef : Vector R := (nullSpace(cond)$Matrix(R)).first
          invC := recip vectorOfCoef.1
          invC case "failed" => "failed"
          invCR : R :=  - (invC :: R)
          reduce(_+,[(invCR*vectorOfCoef.i)*power for i in _
           2..maxIndex vectorOfCoef for power in reverse listOfPowers])
  
        recip x ==
          lrx := leftRecip x
          lrx case "failed" => "failed"
          rrx := rightRecip x
          rrx case "failed" => "failed"
          (lrx :: %) ^= (rrx :: %)  => "failed"
          lrx :: %
  
        leftMinimalPolynomial x ==
          zero? x =>  monomial(1$R,1)$(SparseUnivariatePolynomial R)
          b := someBasis()
          xx : % := x
          k  : PositiveInteger := 1
          cond : Matrix R := coordinates(xx,b) :: Matrix(R)
          while rank(cond) = k repeat
            k := k+1
            xx := x*xx
            cond := horizConcat(cond, coordinates(xx,b) :: Matrix(R) )
          vectorOfCoef : Vector R := (nullSpace(cond)$Matrix(R)).first
          res : SparseUnivariatePolynomial R := 0
          for i in 1..k repeat
            res:=res+monomial(vectorOfCoef.i,i)$(SparseUnivariatePolynomial R)
          res
  
        rightMinimalPolynomial x ==
          zero? x =>  monomial(1$R,1)$(SparseUnivariatePolynomial R)
          b := someBasis()
          xx : % := x
          k  : PositiveInteger := 1
          cond : Matrix R := coordinates(xx,b) :: Matrix(R)
          while rank(cond) = k repeat
            k := k+1
            xx := xx*x
            cond := horizConcat(cond, coordinates(xx,b) :: Matrix(R) )
          vectorOfCoef : Vector R := (nullSpace(cond)$Matrix(R)).first
          res : SparseUnivariatePolynomial R := 0
          for i in 1..k repeat
            res:=res+monomial(vectorOfCoef.i,i)$(SparseUnivariatePolynomial R)
          res
  
        associatorDependence() ==
          n := rank()
          b := someBasis()
          cond : Matrix(R) := new(n**4,6,0$R)$Matrix(R)
          z : Integer := 0
          for i in 1..n repeat
           for j in 1..n repeat
            for k in 1..n repeat
             a123 : Vector R := coordinates(associator(b.i,b.j,b.k),b)
             a231 : Vector R := coordinates(associator(b.j,b.k,b.i),b)
             a312 : Vector R := coordinates(associator(b.k,b.i,b.j),b)
             a132 : Vector R := coordinates(associator(b.i,b.k,b.j),b)
             a321 : Vector R := coordinates(associator(b.k,b.j,b.i),b)
             a213 : Vector R := coordinates(associator(b.j,b.i,b.k),b)
             for r in 1..n repeat
              z:= z+1
              setelt(cond,z,1,elt(a123,r))
              setelt(cond,z,2,elt(a231,r))
              setelt(cond,z,3,elt(a312,r))
              setelt(cond,z,4,elt(a132,r))
              setelt(cond,z,5,elt(a321,r))
              setelt(cond,z,6,elt(a213,r))
          nullSpace(cond)
  
      jacobiIdentity?()  ==
        n := rank()
        b := someBasis()
        for i in 1..n repeat
         for j in 1..n repeat
          for k in 1..n repeat
            not zero? ((b.i*b.j)*b.k + (b.j*b.k)*b.i + (b.k*b.i)*b.j) =>
              messagePrint("Jacobi identity does not hold")$OutputForm
              return false
        messagePrint("Jacobi identity holds")$OutputForm
        true
  
      lieAlgebra?()  ==
        not antiCommutative?() =>
          messagePrint("this is not a Lie algebra")$OutputForm
          false
        not jacobiIdentity?() =>
          messagePrint("this is not a Lie algebra")$OutputForm
          false
        messagePrint("this is a Lie algebra")$OutputForm
        true
  
      jordanAlgebra?()  ==
        b := someBasis()
        n := rank()
        recip(2 * 1$R) case "failed" =>
          messagePrint("this is not a Jordan algebra, as 2 is not " _
           "invertible in the ground ring")$OutputForm
          false
        not commutative?() =>
          messagePrint("this is not a Jordan algebra")$OutputForm
          false
        for i in 1..n repeat
         for j in 1..n repeat
          for k in 1..n repeat
           for l in 1..n repeat
             not zero? (associator(b.i,b.j,b.l*b.k)+_
                 associator(b.l,b.j,b.k*b.i)+associator(b.k,b.j,b.i*b.l)) =>
               messagePrint("not a Jordan algebra")$OutputForm
               return false
        messagePrint("this is a Jordan algebra")$OutputForm
        true
  
      noncommutativeJordanAlgebra?() ==
        b := someBasis()
        n := rank()
        recip(2 * 1$R) case "failed" =>                             
         messagePrint("this is not a noncommutative Jordan algebra,_
   as 2 is not invertible in the ground ring")$OutputForm
         false
        not flexible?()$% =>
         messagePrint("this is not a noncommutative Jordan algebra,_
   as it is not flexible")$OutputForm
         false
        not jordanAdmissible?()$% =>
         messagePrint("this is not a noncommutative Jordan algebra,_
   as it is not Jordan admissible")$OutputForm
         false
        messagePrint("this is a noncommutative Jordan algebra")$OutputForm
        true
  
      antiCommutative?() ==
        b := someBasis()
        n := rank()
        for i in 1..n repeat
          for j in i..n repeat
            not zero? (i=j => b.i*b.i; b.i*b.j + b.j*b.i) =>
              messagePrint("algebra is not anti-commutative")$OutputForm
              return false
        messagePrint("algebra is anti-commutative")$OutputForm
        true
  
      commutative?() ==
        b := someBasis()
        n := rank()
        for i in 1..n repeat
         for j in i+1..n repeat
           not zero? commutator(b.i,b.j) =>
             messagePrint("algebra is not commutative")$OutputForm
             return false
        messagePrint("algebra is commutative")$OutputForm
        true
  
      associative?() ==
        b := someBasis()
        n := rank()
        for i in 1..n repeat
         for j in 1..n repeat
          for k in 1..n repeat
           not zero? associator(b.i,b.j,b.k) =>
             messagePrint("algebra is not associative")$OutputForm
             return false
        messagePrint("algebra is associative")$OutputForm
        true
  
      leftAlternative?() ==
        b := someBasis()
        n := rank()
        for i in 1..n repeat
         for j in 1..n repeat
          for k in 1..n repeat
           not zero? (associator(b.i,b.j,b.k) + associator(b.j,b.i,b.k)) =>
             messagePrint("algebra is not left alternative")$OutputForm
             return false
        messagePrint("algebra satisfies 2*associator(a,a,b) = 0")$OutputForm
        true
  
      rightAlternative?() ==
        b := someBasis()
        n := rank()
        for i in 1..n repeat
         for j in 1..n repeat
          for k in 1..n repeat
           not zero? (associator(b.i,b.j,b.k) + associator(b.i,b.k,b.j)) =>
             messagePrint("algebra is not right alternative")$OutputForm
             return false
        messagePrint("algebra satisfies 2*associator(a,b,b) = 0")$OutputForm
        true
  
      flexible?() ==
        b := someBasis()
        n := rank()
        for i in 1..n repeat
         for j in 1..n repeat
          for k in 1..n repeat
           not zero? (associator(b.i,b.j,b.k) + associator(b.k,b.j,b.i)) =>
             messagePrint("algebra is not flexible")$OutputForm
             return false
        messagePrint("algebra satisfies 2*associator(a,b,a) = 0")$OutputForm
        true
  
      alternative?() ==
        b := someBasis()
        n := rank()
        for i in 1..n repeat
         for j in 1..n repeat
          for k in 1..n repeat
           not zero? (associator(b.i,b.j,b.k) + associator(b.j,b.i,b.k)) =>
             messagePrint("algebra is not alternative")$OutputForm
             return false
           not zero? (associator(b.i,b.j,b.k) + associator(b.i,b.k,b.j)) =>
             messagePrint("algebra is not alternative")$OutputForm
             return false
        messagePrint("algebra satisfies 2*associator(a,b,b) = 0 " _
                     "=  2*associator(a,a,b) = 0")$OutputForm
        true
  
      leftDiscriminant v == determinant leftTraceMatrix v
      rightDiscriminant v == determinant rightTraceMatrix v
  
      coordinates(v:Vector %, b:Vector %) ==
        m := new(#v, #b, 0)$Matrix(R)
        for i in minIndex v .. maxIndex v for j in minRowIndex m .. repeat
          setRow_!(m, j, coordinates(qelt(v, i), b))
        m
  
      represents(v, b) ==
        m := minIndex v - 1
        reduce(_+,[v(i+m) * b(i+m) for i in 1..maxIndex b])
  
      leftTraceMatrix v ==
        matrix [[leftTrace(v.i*v.j) for j in minIndex v..maxIndex v]$List(R)
                 for i in minIndex v .. maxIndex v]$List(List R)
  
      rightTraceMatrix v ==
        matrix [[rightTrace(v.i*v.j) for j in minIndex v..maxIndex v]$List(R)
                 for i in minIndex v .. maxIndex v]$List(List R)
  
      leftRegularRepresentation(x, b) ==
        m := minIndex b - 1
        matrix
         [parts coordinates(x*b(i+m),b) for i in 1..rank()]$List(List R)
  
      rightRegularRepresentation(x, b) ==
        m := minIndex b - 1
        matrix
         [parts coordinates(b(i+m)*x,b) for i in 1..rank()]$List(List R)