Python Mathematics Series ③ Determinant (replacement)

About this series

I am proceeding with the understanding while implementing it in python to deepen my understanding of mathematics. For the time being, I will do linear algebra. I didn't like math so much, but I may have come to like it lately. The table of contents of the series is here. Feel free to comment if you have any mistakes or better ways.

Determinant and permutation

The determinant is defined by the following formula. Reference source Screenshot from 2021-01-05 23-00-30.png Suddenly, I didn't have enough knowledge to implement the determinant, so I'll try to replace it first. The replacement is defined as follows: Reference source Screenshot from 2021-01-06 22-33-49.png (1, 2, 3) and (3, 1, 2) are examples of replacements. There are a total of n! Ways to replace n characters. This time I will implement the product of permutations. The product of permutations is expressed as: Reference source Screenshot from 2021-01-06 22-42-51.png Here article says that the correspondence between two permutations ("A → B" and "B → C") is put together in a three-stage rationale ("A → C"). It seems to be a feeling. If you take a closer look, I'm likely to get stuck in a swamp, so I'll keep this image. This time I will implement the product of this permutation.

Product of permutations

I couldn't find a python library that can be replaced, so I'm worried if my implementation is correct. Please let me know if you have a library. I implemented it like below. I simply tried it as defined.

def permutation(list1, list2):
	list_len = len(list2[1])
	final_list = []
	first_list = []
	ans_list = []
	for i in range(list_len):
		a = list2[1][i]
		ans = list1[1][a - 1]
		if list1[0][i] != ans:
			first_list.append(list1[0][i])
			ans_list.append(ans)
	final_list.append(first_list)
	final_list.append(ans_list)
	return final_list

def main():
	print("~~permutation_test~~")
	pm1 = [[1, 2, 3], [2, 3, 1]]
	pm2 = [[1, 2, 3], [3, 2, 1]]
	print("my_answer:", permutation(pm1, pm2))
    #Output result
    # ~~permutation_test~~
    # my_answer: [[2, 3], [3, 2]]

There seems to be a lot of room for improvement, but for the time being, I tried it this time.

Summary

A good theory with a video of a university math class and a preliminary glue.

Recommended Posts

Python Mathematics Series ③ Determinant (replacement)
Python Mathematics Series ① Transpose
Python: Time Series Analysis
Python time series question
#Python DeepLearning Basics (Mathematics 1/4)
Python Math Series ② Matrix Multiplication
Python application: Pandas Part 2: Series
Python 2 series and 3 series (Anaconda edition)
Python 3 series installation for mac
[Python] Plot time series data
About installing Pwntools and Python2 series
Python: Time Series Analysis: Preprocessing Time Series Data
[Python] How to use Pandas Series
Division of timedelta in Python 2.7 series
String replacement with Python regular expression
Difference between python2 series and python3 series dict.keys ()
Python Math Series ⓪ Table of Contents
Time series plot started ~ python edition ~
[High school mathematics + python] Logarithmic problem