Post Reply 
Equation or not?
03-01-2017, 04:04 PM (This post was last modified: 03-01-2017 04:05 PM by Han.)
Post: #12
RE: Equation or not?
I took the liberty of optimizing some of the programs above where I could. Basically, first three test whether or not to exclude <= and >= when searching for =. As EdDereDdE pointed out, these are really the only tests that are necessary. The last program converts all the equations, which can be time consuming when searching through a large list. The were renamed findeq, findeq2, findeq3, and findeq4 in the order that they were posted.

To test (even on the emulator), type: fetime(3000)

This will create a random list in L0 of size 3000 (you will need large lists to test on the emulator). Then each program is timed in the same manner. Use a smaller value on the actual calculator (e.g. 100)

Here is the "test kit":

PHP Code:
export randL0(k)
begin
  local j
nm;
  
local ineq:={ "=""<"">""<="">=""<>""≠""≤""≥" };
  
L0:={};

  for 
j from 1 to k do
    
n:=ip(random*9)+1;
    
m:=string(ip(random*9)+1,1,0);
    
L0(0):="x + " "y" ineq(n) + m
  
end
end;

// *********************************
export findeq()
begin

local j
,m,p;

m:=size(L0);
p:={};

for 
j from 1 to m do
  if 
instring(L0(j),">") OR instring(L0(j),"<"then continue; end;
  
// now check for = symbol
  
if instring(L0(j),"="then p(0):=jend;
end;

return(
p);

end

// *********************************
export findeq2()
begin
L1
:={"<",">"};
remove(0,IFTE(ΣLIST(EXECON("INSTRING(L0,&1)",L1))+NOT(INSTRING(L0,"=")),0,L0));
end;

// *********************************
export findeq3()
begin
LOCAL eq
:="=",ls:="<",gt:=">";
RETURN 
CAS("
remove((x)→((INSTRING(x,gt))),
remove((x)→((INSTRING(x,ls))),
remove((x)→(0==(INSTRING(x,eq))),L0)
))
"
);
end;

// *********************************
EXPORT findeq4()
BEGIN
local m
,p,j;

m:=size(L0);
p:={};

for 
j from 1 to m do

L0(j):=CAS.expr(L0(j));
IF (
CAS.part(L0(j),0) == "=="THEN p:= CAS.Concat(p,j);END;

end;

return(
p);

END

// *********************************
export fetime(k)
begin
  local t1
t2t3t4;
  
randL0(k);

  
// some programs modify L0
  
L9:=L0;
  
t1:=teval(findeq());

  
L0:=L9;
  
t2:=teval(findeq2());

  
L0:=L9;
  
t3:=teval(findeq3());

  
L0:=L9;
  
t4:=teval(findeq4());

  return({
t1,t2,t3,t4});
end

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Equation or not? - DrD - 02-24-2017, 02:50 PM
RE: Equation or not? - Han - 02-24-2017, 03:59 PM
RE: Equation or not? - DrD - 02-24-2017, 04:22 PM
RE: Equation or not? - Han - 02-24-2017, 04:37 PM
RE: Equation or not? - Didier Lachieze - 02-24-2017, 08:02 PM
RE: Equation or not? - EdDereDdE - 02-24-2017, 11:34 PM
RE: Equation or not? - Didier Lachieze - 02-25-2017, 09:31 AM
RE: Equation or not? - DrD - 02-25-2017, 11:03 AM
RE: Equation or not? - Arno K - 02-28-2017, 10:32 PM
RE: Equation or not? - Han - 03-01-2017, 12:23 AM
RE: Equation or not? - Arno K - 03-01-2017, 08:01 AM
RE: Equation or not? - Han - 03-01-2017 04:04 PM
RE: Equation or not? - Arno K - 03-01-2017, 07:15 PM
RE: Equation or not? - Han - 03-01-2017, 07:22 PM
RE: Equation or not? - parisse - 03-02-2017, 07:35 AM
RE: Equation or not? - DrD - 03-02-2017, 12:31 PM



User(s) browsing this thread: 1 Guest(s)