cat2:= (a,b) -> 10*a+b; cat3:= (a,b,c) -> 100*a+10*b+c: cat4:= (a,b,c,d) -> 1000*a+100*b+10*c+d: `r-`:= (a,b) -> b-a: `r/`:= (a,b) -> b/a: `r^`:= (a,b) -> b^a: pdigs:= {2,3,5,7}: R:= {}: for p in combinat:-permute(pdigs) do a:= p[1]; b:= p[2]; c:= p[3]; d:= p[4]; v:= cat4(op(p)); if isprime(v) then R:= R union {v}; fi; for e in [`+`,`-`,`*`,`/`,`^`] do v:= e(cat3(a,b,c),d); if v::integer and isprime(v) then R:= R union {v} fi od; for e in [`-`,`/`,`^`] do v:= e(a,cat3(b,c,d)); if v::integer and isprime(v) then R:= R union {v} fi od; for e in [`+`,`-`,`*`,`/`,`^`,cat2] do vab:= e(a,b); for f in [`+`,`-`,`*`,`/`,`^`,cat2] do vcd:= f(c,d); for g in [`+`,`-`,`*`,`/`,`^`] do if g = `/` and vcd = 0 then next fi; if g = `^` and vab = 0 then next fi; v:= g(vab,vcd); if v::integer and isprime(v) then R:= R union {v} fi; od od; for f in {`+`,`-`,`*`,`/`,`^`,`r-`,`r/`,`r^`} do if (f = `/` and vcd = 0) or (f = `r^` and vcd = 0) then next fi; vcab:= f(c,vab); for g in {`+`,`-`,`*`,`/`,`^`,`r-`,`r/`} do if (g = `/` and vcab = 0) or (g = `^` and vbcd <> 1) then next fi; v:= g(d,vcab); if v::integer and isprime(v) then R:= R union {v} fi od od od od: sort(convert(R,list));