Question: typeset check for value of 1 insde it

I need to check inside typeset to see is something evaluates to 1. I can find if something contains 1 and have been using that. But got caught out last night because I forgot my work around. e.g. 1+H contains 1 and my work around is `1+H` so the check doesn't see the 1. The typeset is always the first item in the list.

restart

 

 

foo:=proc(a,{S::list:=[]})
local i,perp::boolean;
if S<>NULL then
  if (S[1])=1 or S[1]::function and has(`or`(seq (op(S[1]),i=1..nops([op(S[1])]))),1)  then
   #if (S[1])=1 or S[1]::function and `or`(seq (is(op(S[1][i]),1),i=1..nops([op(S[1])])))  then  ;#  not working
   
     perp:=true;print(perp);
    else
     perp:=false;print(perp);
  end if;
end if;
end proc:

foo(6,S=["cat"]);

 

false

(1)

foo(6,S=[1]);

true

(2)

foo(6,S=[typeset("cat=",H/H),align={above,left},color=green]); #good

true

(3)

foo(6,S=[typeset("cat=",H),align={above,left}])

false

(4)

foo(6,S=[typeset("cat=",1+H)],align={above,left},color=green);#want to fix this

 

 

true

(5)

foo(6,S=[typeset("cat=",`1+H`)]); #work around

false

(6)

foo(6,S=[typeset("cat=",`B/(H+1)`)]); #work around

false

(7)

foo(6,S=[typeset("cat=",`B/(H+1)`,"  height =",1)]); #correct

true

(8)

foo(6,S=[typeset("cat=",H^2/((2*H-H)*H),"  height =",`B/(H+1)`)]); #correct

true

(9)

op(typeset("cat=",B/(H+1)));# this would be false

 

"cat=", B/(1+H)

(10)

op(typeset("cat=",H^2/((2*H-H)*H),"  height =",`B/(H+1)`)) ;  # this would be true

 

 

"cat=", 1, "  height =", `B/(H+1)`

(11)
 

 

Download 2024-06-27_Q_check_inside_typeset.mw

Please Wait...