programming:maxima,python:combine scalar product and vector product,version 2.0
peter.vlasschaert@gmail.com, 17/08/2023

rem : python use sympy 
          maxima use definition

kill(all)$

→ remove extra output don't need.

ratprint :false$

method :  vector product
-----------------------------------

/* Levi-Civita symbol definition */
epsilon(i, j, k):= 
    if (i=j or j=k or k=i) then 0 
    elseif (i=1 and j=2 and k=3) then 1 
    elseif (i=2 and j=3 and k=1) then 1 
    elseif (i=3 and j=1 and k=2) then 1 
    else -1;

/* Vector cross product using Levi-Civita symbol */
cross_product(a, b):= 
    block([c: makelist(0, i, 1, 3)],
        for i:1 thru 3 do 
            (c[i]: sum(sum(epsilon(i, j, k) * a[j] * b[k], j, 1, 3), k, 1, 3)),
        return(c));

/* Symbolic Example */
a: [a1, a2, a3];
b: [b1, b2, b3];
c: cross_product(a, b)$
print(c)$
d1:makelist([c[i]],i,1,3);
d2:flatten(d1);

check :c and d2

is(c=d2);

rem : block statement then use return statement

kill(all)$
ratprint:false$

method : combination → scalar product and vector product
---------------------------------------------------------------------------------

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

/* Levi-Civita symbol definition */
epsilon(i, j, k) := 
    if (i=j or j=k or k=i) then 0 
    elseif (i=1 and j=2 and k=3) then 1 
    elseif (i=2 and j=3 and k=1) then 1 
    elseif (i=3 and j=1 and k=2) then 1 
    else -1;

/* Scalar (dot) product using Kronecker delta */
dot_product(a, b) := sum(a[i] * b[i] * delta(i, i), i, 1, 3);

/* Vector (cross) product using Levi-Civita symbol */
cross_product(a, b) := 
    makelist(sum(sum(epsilon(i, j, k) * a[j] * b[k], j, 1, 3), k, 1, 3), i, 1, 3);

/* Define symbolic vectors */
a: [a1, a2, a3];
b: [b1, b2, b3];
d: [d1, d2, d3];

/* Compute scalar product of d with the cross product of a and b */
combined_result: dot_product(d, cross_product(a, b));
print("final result : scalar value")$
print("------------------------------------")$
print("Result: ", combined_result)$
print("use : expand  →")$
print("Result: ", expand(combined_result))$

rem : 
-----------------------------------------------------------------------
outproduct = vector product  → cross_product(a, b)
  inproduct  =scalar product   → dot_product(a, b)
-----------------------------------------------------------------------

python code : same result :combined_result: dot_product(d, cross_product(a, b));
==========

-----------------------------------------------------------------------------------------------------------------------------------------
from sympy import symbols, KroneckerDelta, LeviCivita

# Define symbolic components for vectors a, b, and d
a1, a2, a3, b1, b2, b3, d1, d2, d3 = symbols('a1 a2 a3 b1 b2 b3 d1 d2 d3')

a = [a1, a2, a3]
b = [b1, b2, b3]
d = [d1, d2, d3]

# Define the dot product using Kronecker delta
def dot_product(vec1, vec2):
    return sum(vec1[i] * vec2[i] * KroneckerDelta(i, i) for i in range(3))

# Define the cross product using Levi-Civita symbol
def cross_product(vec1, vec2):
    return [sum(LeviCivita(i, j, k) * vec1[j] * vec2[k] for j in range(3) for k in range(3)) for i in range(3)]

# Compute scalar product of d with the cross product of a and b
combined_result = dot_product(d, cross_product(a, b))

print("Result:", combined_result)
--------------------------------------------------------------------------------------------------------------------------------------
output : python in console , from (Th)onny use for python
=====
%Run -c $EDITOR_CONTENT
Result: d1*(a2*b3 - a3*b2) + d2*(-a1*b3 + a3*b1) + d3*(a1*b2 - a2*b1)
--------------------------------------------------------------------------------------------------------------------------------------
→ Result: d1*(a2*b3 - a3*b2) + d2*(-a1*b3 + a3*b1) + d3*(a1*b2 - a2*b1)
--------------------------------------------------------------------------------------------------------------------------------------

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