maxima : programming  scalairproduct :dot and delta function,version 1.0
peter.vlasschaert@gmail.com, 16/08/2023

kill(all)$

1e) method : dot operator
------------------------------------

/* Declare the variables as scalars */
declare(r, scalar);
declare(t, scalar);
declare(f, scalar);
declare(z, scalar);
declare(u, scalar);

/* Define the unit vectors */
e1 : [1, 0, 0];
e2 : [0, 1, 0];

/* Define the vectors */
v1 : r*t*e1;
v3 : f*f*e2 + z*u*e1;

/* Compute the dot product */
scalar_product : v1.v3;

/* Display the result */
print(scalar_product);

-------------------------------------------------------------------------------------------------------------------------------------------------------

2e) method : delta function
--------------------------------------

kill(all)$

/* Declare the variables as scalars */
declare(r, scalar);
declare(t, scalar);
declare(f, scalar);
declare(z, scalar);
declare(u, scalar);

/* Define the Kronecker delta function */
delta(i, j) := if i=j then 1 else 0;

/* Define the vectors */
v1 : [r*t, 0, 0];
v3 : [z*u, f^2, 0];

/* Define scalar function for dot product using Kronecker delta */
dot_product_fn(A, B) := sum(sum(A[i] * B[j] * delta(i,j), i, 1, 3), j, 1, 3);

/* Use the function to compute the scalar product of v1 and v3 */
scalar_result : dot_product_fn(v1, v3);

/* Display the result */
print(scalar_result);

→ first update

kill(all)$

/* Declare multiple variables as scalars using list notation */
declare([r, t, f, z, u], scalar);

/* Define the Kronecker delta function */
delta(i, j) := if i=j then 1 else 0;

/* Define the vectors */
v1 : [r*t, 0, 0];
v3 : [z*u, f^2, 0];

/* Define scalar function for dot product using Kronecker delta */
dot_product_fn(A, B) := sum(sum(A[i] * B[j] * delta(i,j), i, 1, 3), j, 1, 3);

/* Use the function to compute the scalar product of v1 and v3 */
scalar_result : dot_product_fn(v1, v3);

/* Display the result */
print(scalar_result);

→ second update.

kill(all)$

/* Declare multiple variables as scalars using list notation */
declare([r, t, f, z, u], scalar);

/* Define the Kronecker delta function */
delta(i, j) := if i=j then 1 else 0;
/* Declare v1 and v3 as lists */
matchdeclare(v1, list);
matchdeclare(v3, list);
print ("v1 →properties :")$
properties(v1);
/* Define the vectors */
v1 : [r*t, 0, 0];
v3 : [z*u, f^2, 0];
print ("v1 →properties ")$
properties(v1);

/* Define scalar function for dot product using Kronecker delta */
dot_product_fn(A, B) := sum(sum(A[i] * B[j] * delta(i,j), i, 1, 3), j, 1, 3)$

/* Use the function to compute the scalar product of v1 and v3 */
scalar_result : dot_product_fn(v1, v3);

/* Display the result */
print("scalar_result = ",scalar_result)$

rem :analog properties :v3

---------------------------------------------------------------------------------------------

math : scalair product (= inproduct)
-----------------------------------------------

----------------------------------------------------------------------------------------------

rem : without load of vect packages
→ load(vect)

a:[a1,a2,a3];
b:[b1,b2,c3];
x1:print( "a.b =",a.b)$

x1a:lhs(x1);

x2:print("'sum(a[i] * b[i], i, 1, 3) ='",sum(a[i] * b[i] , i, 1, 3))$

x2a:lhs(x2);

→ check x1a ? x2a

result will be :true or false.

x3:is(x1a=x2a);

----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------