Code for integer points on sphere...

I use Mathematica. This code finds integer points on the sphere

(x-2)^2 + (y-4)^2 + (c-6)^2 =15

and select two of them so that distance of two this points equal to 4.

ClearAll[a, b, r, c];
a = 2;
b = 4;
c = 6;
r = 15; ss =
Subsets[{x, y, z} /.
Solve[{(x \[Minus] a)^2 + (y \[Minus] b)^2 + (z \[Minus] c)^2 ==
r^2, x != a, y != b, z != c, x y z != 0}, {x, y, z},
Integers], {2}];
t = Select[ss, And @@ Unequal @@@ Subsets[Flatten[#], {2}] &];
Length[t]
Select[ss, Apply[EuclideanDistance, #] === 4 &]

and this code select four points on the shere so that none of three points make a right triangle

ClearAll[a, b, r, c];
a = 2;
b = 4;
c = 6;
r = 15;
ss = Subsets[{x, y, z} /.
Solve[{(x - a)^2 + (y - b)^2 + (z - c)^2 == r^2, x != a, y != b,
z != c, x y z != 0, x > y}, {x, y, z}, Integers], {4}];
nonright =
Pick[ss, (FreeQ[#, \[Pi]/2] &) /@ ({VectorAngle[#2 - #1, #3 - #1],
VectorAngle[#1 - #2, #3 - #2],
VectorAngle[#1 - #3, #2 - #3]} & @@@ ss)];
Select[nonright, (12 == Length[Union @@ #] &)]

I am looking for a  procedure in Maple.  I have some problems with this sphere. For example:

Choose four points so that 12 coordinates difference and it makes a square.

Can your code improve with sphere?

Problem with integer optimization...

When I use the option assume = nonnegint or integervariables = {...} in Optimization[Minimize], or Optimization[LPSolve] I've got the message "kernel connection lost'.

Thie even happens when I use the simple example from the Maple help:

with(Optimization):
LPSolve(2*x+5*y,{3*x-y=1,x-y<=5},assume={nonnegative,integer});

It says; mserver.exe has stopped working.

What's wrong?

How can I generate some n-tuple random list of int...

How can I generate some n-tuple random list of integers s.t. any component is between -30 and 50? For example if n=5 then four random of such 5-tuple are

[-1,2,8,7,9] , [0,-9,2,-3,-5] , [4,5,3,-8,-1] , [12, -5, 0, 6,8]

How do I generate a list of all possible products?...

Let x and y be 4-digit integers such that the last digit of x is 7 and the last digit of y is 1. That is, x = abc7 and y = rst1, where a,b,c,r,s,t all run from 0 to 9. There are 1000 possibilities for x and  1000 for y. What are all possible products x*y? I would like all possible products listed in increasing order. The first element of the list should be 7*1 = 7 (since 0007*0001 = 7). The last should be 9997*9991 = 99880027. Thank you!

Optimization problem...

How to find the maximum natural number n s. t. the sum of its cubed digits is greater than or equal to n? Of course, with Maple. The same question for the sum of the  digits to k-th power. Here are my unsuccessful attempts:
1.Optimization:-Maximize(n, {n <= convert(map(c ->c^3, convert(n, base, 10)), `+`)}, assume = integer);

Error, invalid input: `convert/base` expects its 1st argument, n, to be of type {integer, list(integer)}, but received n

2. for n while n <= convert(map(c ->c^3, convert(n, base, 10)), `+`) do print(n) end do;

1
2
3
4
5
6
7
8
9

How to efficiently write a formula in Maple...

Let M and K be given positive integers.

I struggle with how to write efficiently this formula in Maple,mainly because it sums over *pairs* of integers K1 and K2, with the given property that "K1+2*K2=K":

0<=K1<=K,

0<=K2<=K/2

sum { M!/(M-K1-K2)! * K!/(K1! * K2)! * 1/M^K * 1/2^K2 : such that K1 + 2*K2 = K}

The "!" means factorial.

how to find the pairs of solutions [x,y] for x^2+y...

I currently have a function quadsum(n) that determines the [x,y] solutions of the above equation for an integer n. :

local
k:= 0, mylist:= table(),
x:= isqrt(iquo(n,2)), y:= x, x2:= x^2, y2:= y^2;
if 2*x2 <> n then x:= x+1; x2:= x2+2*x-1; y:= x; y2:= x2; end if;
while x2 <= n do
y:= isqrt(n-x2); y2:= y^2;
if x2+y2 = n then k:= k+1; mylist[k]:= [x,y] end if;
x:= x+1; x2:= x2+2*x-1;
end do;
convert(mylist, list)
end proc:

How would I alter this so that I get [x,y] for n= (5^a).(13^b).(17^c)(29^d) for non-negative integers a,b,c,d?

writing procedures ...

1.  a procedure quadsumstats whose input is an integer n. This procedure should return a list of length

n whose kth  entry is the number of solutions to
x^2 + y^2 = k
for
1 <= k and k <= n

I am sort of confused as to how to construct that list of length n and how to obtain integer solutions to the equation in maple.

2.

a procedure firstCount(k) that finds the first integer
n
with
k
representations as
"x^2+y^2= n." What does it mean for an integer to have k representations?

Partition of an integer with restrictions

by:

The procedure  Partition  significantly generalizes the standard procedure  combinat[partition]  in several ways. The user specifies the number of parts of the partition, and can also set different limitations on parts partition.

Required parameters:  n - a nonnegative integer, - a positive integer or a range (k  specifies the number of parts of the partition). The parameter  res  is the optional parameter (by default  res is  ). If  res  is a number, all elements of  k-tuples must be greater than or equal  res .  If  res  is a range  a .. b ,   all elements of  k-tuples must be greater than or equal  a  and  less than or equal  b . The optional parameter  S  - set, which includes elements of the partition. By default  S = {\$ 0.. n} .

The code of the procedure:

Partition:=proc(n::nonnegint, k::{posint,range}, res::{range, nonnegint} := 1, S::set:={\$0..n})  # Generates a list of all partitions of an integer n into k parts

local k_Partition, n1, k1, L;

k_Partition := proc (n, k::posint, res, S)

local m, M, a, b, S1, It, L0;

m:=S[1]; M:=S[-1];

if res::nonnegint then a := max(res,m); b := min(n-(k-1)*a,M)  else a := max(lhs(res),m); b := min(rhs(res),M) fi;

S1:={\$a..b} intersect S;

if b < a or b*k < n or a*k > n  then return [ ] fi;

It := proc (L)

local m, j, P, R, i, N;

m := nops(L[1]); j := k-m; N := 0;

for i to nops(L) do

R := n-`+`(op(L[i]));

if R <= b*j and a*j <= R then N := N+1;

P[N] := [seq([op(L[i]), s], s = {\$ max(a, R-b*(j-1)) .. min(R, b)} intersect select(t->t>=L[i,-1],S1) )] fi;

od;

[seq(op(P[s]), s = 1 .. N)];

end proc;

if k=1 then [[b]] else (It@@(k-1))(map(t->[t],S1))  fi;

end proc;

if k::posint then return k_Partition(n,k,res,S) else n1:=0;

for k1 from lhs(k) to rhs(k) do

n1:=n1+1; L[n1]:=k_Partition(n,k1,res,S)

od;

L:=convert(L,list);

[seq(op(L[i]), i=1..n1)] fi;

end proc:

Examples of use:

Partition(15, 3);

Partition(15, 3..5, 1..5);  # The number of parts from 3 to 5, and each summand from 1 to 5

Partition(15, 5, {seq(2*n-1, n=1..8)});  # 5 summands and all are odd numbers

A more interesting example.
There are  k banknotes in possible denominations of 5, 10, 20, 50, 100 dollars. At what number of banknotes  k  the number of variants of exchange  \$140  will be maximum?

n:=0:

for k from 3 to 28 do

n:=n+1: V[n]:=[k, nops(Partition(140, k, {5,10,20,50,100}))];

od:

V:=convert(V, list);

max(seq(V[i,2], i=1..nops(V)));

select(t->t[2]=8, V);

Here are these variants:

Partition(140, 10, {5,10,20,50,100});

Partition(140, 13, {5,10,20,50,100});

Prime sum question ...

According to this site,"It is known that every even number can be written as a sum of at most six primes".

http://www.theage.com.au/national/education/christians-goldbachs-magic-sum-20140903-3es2t.html

i wanted to test this using maple.

restart:
> PF := proc (a::integer)

> local cst,obj,res;
> cst := add(x[i], i = 1 .. numtheory:-pi(prevprime(a))) <= 6;
> obj := add(x[i]*ithprime(i), i = 1 .. numtheory:-pi(prevprime(a)))-a;
> res := Optimization:-LPSolve(obj, {cst ,obj>=0}, assume={nonnegative,integer}); end proc:
> PF(30);
[0, [x[1] = 0, x[2] = 0, x[3] = 6, x[4] = 0, x[5] = 0, x[6] = 0,x[7] = 0, x[8] = 0, x[9] = 0, x[10] = 0]]

the third prime is 5 and 6 of them make 30. as an aside, it would be nice to know how to get maple to output "30 = 6x5".

this is obviously pretty limited, because 30 can be written as the sum of two primes (7+23 and 11+19) [GOLDBACH], but using DS's GlobalSearch for all solutions takes a long time to compute. also I have to nominate the highest prime.

any suggestions?

Which versions of Maple 18 (Personal, Academic, Co...

I'm interested in doing some experimental mathematics using the PSLQ integer relation algorithm.  The only third-party program for doing PSLQ problems I've been able to find is a GNU C++ program with a less-than-user-friendly command-line interface.  I've heard that Maple implements PSLQ and I like the symbolic input and presentation it offers as a CAS, but I can't find any information on which alternative types of Maple 18 make the PSLQ algorithm available.

Write a function that takes an integer and a boole...

so we have to Write a maple function with -> that takes an integer N and a boolean function

F: {(i,j) l 0<= i,j<= N} -> {true,false}

and returns a list containing all [i,j] such that F(i,j). A procedure that does this
would be

proc(N,F) local i, j, RV;
RV:=NULL;
for i from 1 to N do for j from 1 to N do
if F(i,j) then RV:=RV,[i,j] ; end if ;
end do ; end do ;
return RV ;
end proc ;

The problem is to do this inline, i.e. you have to write
(i,j)-> ...

"round" to 2 decimal places...

Hi

I have been trying to find a way to present results from engineering calcs to 2 decimal places (i.e.: 350.50) but the round function rounds to the nearest integer. Is there a specific statement for specifying the number of decimal places you want to present some results?

thanks

How to find 2013th term in this sequence?...

How to find 2013th term in the sequence

1, 2, 2, 3, 3, 3, 4, 4, 4, 4, ...?

in which the n-th positive integer appears n times.

I don't know how to start.

Perimeter and area of a triangle are integer numbe...

In geom3d. I want to find the vertices A(x1,y1,z1), B(x2,y2,z2), where x1, y1, z1, x2, y2, z2 are integer numbers so that the triangle OAB  (O is origin) and perimeter and area are integer numbers. I tried

> resrart:

N:=5:

L:=[]:

for x1 from -N to N do

for y1 from x1 to N do

for z1 from y1 to N do

for x2 from -N to N do

for y2 from -N to N do

for z2 from -N to N do

a:=sqrt(x1^2+y1^2+z1^2):b:=sqrt(x2^2+y2^2+z2^2):c:=sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2):

p:=(a+b+c)/2:

S:=sqrt(p*(p-a)*(p-b)*(p-c)):

if type(2*p, integer) and type(S, posint)

then L:=[op(L), [[0, 0, 0], [x1, y1, z1], [x2, y2, z2]]]: fi:

od: od: od: od: od: od:

nops(L);

But my computer runs too long. I can not receive the result. How to get the answer?

If I the length of the side are 6, 25, 29. I tried

DirectSearch:-SolveEquations([(x2-x1)^2+(y2-y1)^2+(z2-z1)^2 = 6^2, (x3-x2)^2+(y3-y2)^2+(z3-z2)^2 = 25^2,  (x3-x1)^2+(y3-y1)^2+(z3-z1)^2 = 29^2], {abs(x1) <= 30, abs(x2) <= 20, abs(x3) <= 20, abs(y1) <= 20, abs(y2) <= 20, abs(y3) <= 20, abs(z1) <= 20,abs(z2) <= 20, abs(z3) <= 20}, assume = integer, AllSolutions, solutions = 1);

 1 2 3 4 5 6 7 Last Page 2 of 23
﻿