Question: Procedure testing types in list inputs

I am trying to test types inside lists on the input to a procedure. Sometimes I can get this concept to work. 

This is a sample to show the problem. I need to know if the list has [ list[ $3] , Vector[column]($3) ] , or [ Vector[row]($3] , Vector [column]($3) ]

restart

 


        test:=proc(l1::[{[algebraic $ 3],'Vector[row](3, algebraic)'},'Vector[column](3, algebraic)'],l2::[{[algebraic $ 3],'Vector[row](3, algebraic)'},'Vector[column](3,algebraic)'])
        
        print("inputs recognised");

        end proc;

        

proc (l1::[{'Vector[row](3, algebraic)', [`$`(algebraic, 3)]}, 'Vector[column](3, algebraic)'], l2::[{'Vector[row](3, algebraic)', [`$`(algebraic, 3)]}, 'Vector[column](3, algebraic)']) print("inputs recognised") end proc

 

 

#  3d lines

l1:= [<1 | 5 | 7>, <3, 7, 9>]

[Vector[row](3, {(1) = 1, (2) = 5, (3) = 7}), Vector(3, {(1) = 3, (2) = 7, (3) = 9})]

l2:=[<-4 | 2 | 1>, <3, 8, -9>]

[Vector[row](3, {(1) = -4, (2) = 2, (3) = 1}), Vector(3, {(1) = 3, (2) = 8, (3) = -9})]

test(l1,l2)

Error, invalid input: test expects its 1st argument, l1, to be of type [{'Vector[row](3,algebraic)', [algebraic $ 3]}, 'Vector[column](3,algebraic)'], but received [Vector[row](3, [1,5,7]), Vector(3, [3,7,9])]

l3:= [[1 , 5 , 7], <3, 7, 9>]

[[1, 5, 7], Vector(3, {(1) = 3, (2) = 7, (3) = 9})]

l4:=[[-4 , 2 , 1], <3, 2, -9>]

[[-4, 2, 1], Vector(3, {(1) = 3, (2) = 2, (3) = -9})]

test(l3,l4)

Error, invalid input: test expects its 1st argument, l1, to be of type [{'Vector[row](3,algebraic)', [algebraic $ 3]}, 'Vector[column](3,algebraic)'], but received [[1, 5, 7], Vector(3, [3,7,9])]

type(l3[1],[algebraic $ 3])

true

type(l1[1],[algebraic $ 3])  

false

type(l1[1],'Vector[row](3, algebraic)')

true

type(l1[2],'Vector[column](3, algebraic)')

true

 

Download Q_2023-03-06_Proc_types_in_list_inputs.mw

Please Wait...