sursumCorda

1174 Reputation

13 Badges

2 years, 70 days

MaplePrimes Activity


These are answers submitted by sursumCorda

A subtle point: You have to use [algebraic, algebraic, algebraic] rather than [algebraic $ 3]. Alternatively, 

restart;

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

proc (l1::[{satisfies(proc (s) options operator, arrow; type(s, [`$`(algebraic, 3)]) end proc), ('Vector[row]')(3, algebraic)}, ('Vector[column]')(3, algebraic)], l2::[{satisfies(proc (s) options operator, arrow; type(s, [`$`(algebraic, 3)]) end proc), ('Vector[row]')(3, algebraic)}, ('Vector[column]')(3, algebraic)]) print("inputs recognised") end proc

(1)

l1 := [`<|>`(1, 5, 7), `<,>`(3, 7, 9)] = [Vector[row](3, {(1) = 1, (2) = 5, (3) = 7}), Vector(3, {(1) = 3, (2) = 7, (3) = 9})]NULL

l2 := [`<|>`(-4, 2, 1), `<,>`(3, 8, -9)] = [Vector[row](3, {(1) = -4, (2) = 2, (3) = 1}), Vector(3, {(1) = 3, (2) = 8, (3) = -9})]NULL

test(l1, l2)

"inputs recognised"

(2)

l3 := [[1, 5, 7], `<,>`(3, 7, 9)] = [[1, 5, 7], Vector(3, {(1) = 3, (2) = 7, (3) = 9})]NULL

l4 := [[-4, 2, 1], `<,>`(3, 2, -9)] = [[-4, 2, 1], Vector(3, {(1) = 3, (2) = 2, (3) = -9})]NULL

test(l3, l4)

"inputs recognised"

(3)

NULL


 

Download Procedure_testing_types_in_list_inputs.mw

X:=(eval@@2)(foldl(''SubstituteAll'',s,''op''([L1[k],L2[k]])$k=1..numelems(L1)));
 = 
  X := "{ {0, 1}, {1, 2}, {1, 10}, {2, 3}, {3, 4}, {4, 5},

    {4, 9}, {5, 6}, {6, 7}, {7, 8},{8, 9}, {10, 11}, {11, 12},

    {11, 16}, {12, 13}, {13, 14}, {14, 15}, {15, 16}}"


Besides, if we don't know StringTools[CharacterMap]

Subs(convert(L1, list) =~ convert(L2, list), s); # also works
 = 
  "{ {0, 1}, {1, 2}, {1, 10}, {2, 3}, {3, 4}, {4, 5},

    {4, 9}, {5, 6}, {6, 7}, {7, 8},{8, 9}, {10, 11}, {11, 12},

    {11, 16}, {12, 13}, {13, 14}, {14, 15}, {15, 16}}"


 


 

restart;

bigList := RandomTools:-Generate(listlist(integer(range = -10^3 .. 10^3), 10^4, 10^2))

s1 := CodeTools:-Usage(subsindets(bigList, list, convert, set))

memory used=27.62MiB, alloc change=8.00MiB, cpu time=703.00ms, real time=560.00ms, gc time=281.25ms

 

s2 := CodeTools:-Usage(convert(map(convert, bigList, set, nested), set, nested))

memory used=20.30MiB, alloc change=0 bytes, cpu time=375.00ms, real time=382.00ms, gc time=0ns

 

s3 := CodeTools:-Usage(convert(convert(bigList, Array, fill = NULL), set, nested))

memory used=32.15MiB, alloc change=35.63MiB, cpu time=859.00ms, real time=788.00ms, gc time=203.12ms

 

is(s1 = s2 and s2 = s3) = trueNULL


 

Download nested_convert_to_set.mw

More or less useful: 

with(VectorCalculus):
B := piecewise(0 <= r < a, <0, mu[0]*r^3*i/(2*Pi*a^4), 0>, a <= r <= b, <0, mu[0]*i/((1 + r)*r*Pi), 0>);
 B :=  /                  3                                    
       |         &mu;[0] r  i                                  
       |  0 e  + ------------ e  + 0 e        0 <= r and r < a 
       |     x            4    y      z                        
      <           2 &pi; a                                     
       |                                                       
       |          &mu;[0] i                                    
       | 0 e  + -------------- e  + 0 e       a <= r and r <= b
       \    x   (1 + r) r &pi;  y      z                       

n := <0, 1, 0>:
PIECEWISE(map(x -> [x[2] . n, x[1]], PiecewiseTools:-ToList(B))[]);
 = 
              /         3                          
              |  mu[0] r  i                        
              |  ----------       0 <= r and r < a 
              |         4                          
             <    2 Pi a                           
              |                                    
              |   mu[0] i                          
              | ------------      a <= r and r <= b
              \ (1 + r) r Pi                       

 

Find a satisfying assignment using SMTLIB:-Satisfy

SMTLIB:-Satisfy({2*c2 + c0 = 1, 3*c2 + 12*c4 = 1, 6*c3 + 2*c1 = 2});
 = 
           /                             1       1 \ 
          { c0 = 1, c1 = 0, c2 = 0, c3 = -, c4 = -- }
           \                             3       12/ 

And you can try another solver cvc5 online (cf. SMTLIB:-ToString).

Incidentally, the algorithms used by MMA's FindInstance are described here

Much convenient: 
 

restart;

"applyrule(f(_A::anything)+f(_B::anything)=f(_A+_B),((e)^(f(a)-f(c)+2 (f(b)+f(c))+f(10*d)))/((e)^(f(b)+f(NULL)+f(``)))+((e)^(f(a)-f(c)+2*(f(b)+f(c))+f(10 d)))/((e)^(f(b)+f(NULL)+f(``)))+e/(f(f(""))+f(f(g))+f(f(h))+f^(1)(""))+e/(f(f(""))+f(f(g))+f(f(h))+f^(-1)("")))"
 =
exp(f(a+10*d)-f(c)+2*`&InvisibleTimes;`(f(b+c)))/exp(f(``+b)+f())+exp(f(10*d*`&InvisibleTimes;`+a+c)+2*f(b))/exp(f(``+b)+f())+e/f(""+f("")+f(g)+f(h))+e/(f(f(h+""+g))+(f@@(-1))(""))

redefine(f, ['multilinear'])%

exp(f(a)+10*f(d)-f(c)+2*`&InvisibleTimes;`(f(b)+f(c)))/exp(f(``)+f(b))+exp(10*f(`&InvisibleTimes;`*d)+f(a)+f(c)+2*f(b))/exp(f(``)+f(b))+e/(f(f(""))+f(f(g))+f(f(h))+f(""))+e/(f(f(""))+f(f(g))+f(f(h))+(f@@(-1))(""))

(1)

NULL


 

Download possibleMatch.mw

Maybe Physics/diff
 

p := (m1*a1 + m2*(a123 + z(t)))*sin(theta(t))*g + m3*(sin(theta(t))*(a1234 + z(t)) + cos(theta(t))*a5)*g; = (m1*a1+m2*(a123+z(t)))*sin(theta(t))*g+m3*(sin(theta(t))*(a1234+z(t))+cos(theta(t))*a5)*gNULL

diff((m1*a1+m2*(a123+z))*sin(theta)*g+m3*(sin(theta)*(a1234+z)+cos(theta)*a5)*g, theta) = (m1*a1+m2*(a123+z))*cos(theta)*g+m3*(cos(theta)*(a1234+z)-sin(theta)*a5)*g

Physics[diff](p, theta(t))

(m1*a1+m2*(a123+z(t)))*cos(theta(t))*g+m3*(cos(theta(t))*(a1234+z(t))-sin(theta(t))*a5)*g

(1)

NULL


 

Download Fundiff.mw

@lcz How about g[1].txt? But for some unexplained reason, certain data cannot be read: 

restart;

currentdir(homedir):

g := GraphTheory:-ImportGraph("Desktop\\g[1].gml", graphlet)

g := `Graph 1: an undirected unweighted graph with 15 vertices and 30 edge(s)`

(1)

GraphTheory:-DrawGraph(g)

%?

 

%?

Download test_g.mws

You need 

Export("E:\\M.txt", String(M)); # not the same

or

Export("E:/M.csv", M):
Export("E:\\M.txt", Import("E:/M.csv", format = "Text"));
fremove("E:/M.csv");

Note that .csv is a text-based format, so you can simply rename M.csv to M.txt (using FileTools[Rename]) in fact.

How about PCA_1.mw?

simplify(solve({(BD + CD)^2 = AB^2 + AC^2 - 2*AB*AC*cos(Pi/9 + (4*Pi)/9), BD/CD = 4/3, AB*sin(Pi/9)/BD = AC*sin((4*Pi)/9)/CD, AB^2*CD + AC^2*BD = (BD + CD)*(4^2 + BD*CD), (AB, AC, BD, CD, AB + AC - (BD + CD), AC + (BD + CD) - AB, AB + (BD + CD) - AC) >~ 0}));

 gives AB = 28/3, but 

solve({BD^2 = AB^2 + 4^2 - 2*AB*4*cos(Pi/9), CD^2 = AC^2 + 4^2 - 2*AC*4*cos((4*Pi)/9), (BD + CD)^2 = AB^2 + AC^2 - 2*AB*AC*cos(Pi/9 + (4*Pi)/9), BD/CD = 4/3, (AB, AC, BD, CD, AB + AC - (BD + CD), AC + (BD + CD) - AB, AB + (BD + CD) - AC) >~ 0});

gives an error ...

1 2 3 4 5 Page 5 of 5