## 15077 Reputation

12 years, 24 days

## Many thanks...

for the detected error and improving of the algorithm! After correcting my code, I got the same result. Now there are no duplicates:

`Routes(4, 6);nops({op(T)});`

68272

68272

## Many thanks...

for the detected error and improving of the algorithm! After correcting my code, I got the same result. Now there are no duplicates:

`Routes(4, 6);nops({op(T)});`

68272

68272

## Re...

Check the specification of your equation!

You also did not answer these questions: "What means your dual equality? The system of equations?"

## Re...

Check the specification of your equation!

You also did not answer these questions: "What means your dual equality? The system of equations?"

## Comment...

Your code does not work, if the list  r  contains several  elements with the same maximum frequency:

r := [3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 4, 3, 1\$13];

with(Statistics):

T := Tally(r);

lhs(op(select(c-> is(rhs(c) = max(map(rhs, T))), T)));

r := [3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

T := [1 = 13, 2 = 1, 3 = 13, 4 = 4]

Error, invalid input: lhs expects 1 argument, but received 2

## Comment...

Your code does not work, if the list  r  contains several  elements with the same maximum frequency:

r := [3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 4, 3, 1\$13];

with(Statistics):

T := Tally(r);

lhs(op(select(c-> is(rhs(c) = max(map(rhs, T))), T)));

r := [3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

T := [1 = 13, 2 = 1, 3 = 13, 4 = 4]

Error, invalid input: lhs expects 1 argument, but received 2

## Explanation...

When I add a new vertex to the already created route, I always check that the new vertex is not the same as the previous vertices of this route (in this fragment of the code):

if convert([seq(r[i]<>p, i=1..k-1)], `and`) then M:=[op(M),[op(r), p]]:  fi:

## Explanation...

When I add a new vertex to the already created route, I always check that the new vertex is not the same as the previous vertices of this route (in this fragment of the code):

if convert([seq(r[i]<>p, i=1..k-1)], `and`) then M:=[op(M),[op(r), p]]:  fi:

@Markiyan Hirnyk

The subprocedure  Rule  is of fundamental importance in procedure  Routes. It allows you to extend the already created list of routes  K   one more step. Applying  Rule  to the list of all the vertices , we get a list of all routes of length 1. Applying the procedure  Rule  to the previous list, we get all routes of length 2, and so on.

@Markiyan Hirnyk

The subprocedure  Rule  is of fundamental importance in procedure  Routes. It allows you to extend the already created list of routes  K   one more step. Applying  Rule  to the list of all the vertices , we get a list of all routes of length 1. Applying the procedure  Rule  to the previous list, we get all routes of length 2, and so on.

## Explanation...

nops(L1)  means the number of elements of the list  L1

Fragment of the code

for i from 1 to n do

U[1, i]:=L1[i]; U[2, i]:=L2[i]; U[i, 1]:=M1[i]; U[i, 2]:=M2[i];

od;

specifies the first two lines and columns of the matrix  U .

## Explanation...

nops(L1)  means the number of elements of the list  L1

Fragment of the code

for i from 1 to n do

U[1, i]:=L1[i]; U[2, i]:=L2[i]; U[i, 1]:=M1[i]; U[i, 2]:=M2[i];

od;

specifies the first two lines and columns of the matrix  U .

## Comment...

Axel Vogt, I do not understand this statement :

"I think for that example over the _Reals_ the solution is

piecewise(x < 0, 4-4/365*(-11315*x+133225)^(1/2), 0<=x, 0) ;"

A number or set of numbers  are  the roots of the equation, but you write a function that depends on x.

Your example in the real domain can be easily solved as above by the change:

restart;

eq1:= 2-2*(-31/365*x+1)^(1/2)-2*(2-2*(-31/365*x+1)^(1/2)-31/365*x)^(1/2)=0:

eq2:=-31/365*x+1=t^2:

simplify(algsubs(eq2, eq1)) assuming t>=0;

sol:=solve(%, useassumptions) assuming t>=0;

L:=convert(sol, list);

x:=unapply(solve(eq2, x), t);

'RealRange'(x(L[2]), x(L[1]));  # All roots of the equation eq1 in real domain

This equation can be solved by hand, if you select a perfect square under external root. If the variable  x  does not belong to the segment from 0 to 365/31, the complex numbers (in particular negative numbers) will be under the roots. If we keep in mind the principal value of the square root, it is easy to check that any number  x>=0  (in particular, x=12) is the root. Any other numbers (real or complex, including negative numbers) are not roots.

## Comment...

Axel Vogt, I do not understand this statement :

"I think for that example over the _Reals_ the solution is

piecewise(x < 0, 4-4/365*(-11315*x+133225)^(1/2), 0<=x, 0) ;"

A number or set of numbers  are  the roots of the equation, but you write a function that depends on x.

Your example in the real domain can be easily solved as above by the change:

restart;

eq1:= 2-2*(-31/365*x+1)^(1/2)-2*(2-2*(-31/365*x+1)^(1/2)-31/365*x)^(1/2)=0:

eq2:=-31/365*x+1=t^2:

simplify(algsubs(eq2, eq1)) assuming t>=0;

sol:=solve(%, useassumptions) assuming t>=0;

L:=convert(sol, list);

x:=unapply(solve(eq2, x), t);

'RealRange'(x(L[2]), x(L[1]));  # All roots of the equation eq1 in real domain

This equation can be solved by hand, if you select a perfect square under external root. If the variable  x  does not belong to the segment from 0 to 365/31, the complex numbers (in particular negative numbers) will be under the roots. If we keep in mind the principal value of the square root, it is easy to check that any number  x>=0  (in particular, x=12) is the root. Any other numbers (real or complex, including negative numbers) are not roots.

## Yes...

VolMike ,

you are right!

 First 100 101 102 103 104 105 106 Last Page 102 of 112
﻿