You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

115 lines
3.2 KiB

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "acb06966-8cfa-4b28-9fa9-30286c33d20c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "203b80b6-7559-4861-ab9c-538885b8d223",
"metadata": {
"tags": []
},
"source": [
"## Inverse?"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "66031921-f6b4-4c32-bc8b-97a92ea935df",
"metadata": {
"jupyter": {
"source_hidden": true
},
"tags": []
},
"outputs": [],
"source": [
"# Q: If you compute the inverse of one of these matrixes and multiply it to the right of the position\n",
"# where it was originally multiplied it should \"delete\" that element as if the element was never added.\n",
"# I'm uncertain of the possibility and frequency of such inverse matrices over finite fields.\n",
"# If this scenario is possible to construct, I think we should \"define\" this operation as deletion.\n",
"\n",
"# See: https://en.wikipedia.org/wiki/Determinant#Properties_of_the_determinant\n",
"\n",
"def det2(mat, m=256):\n",
" ((a, b),\n",
" (c, c)) = mat\n",
" return (a*c - b*c) % m\n",
"\n",
"def det3(mat, m=256):\n",
" ((a, b, c),\n",
" (d, e, f),\n",
" (g, h, i)) = mat\n",
" return (a*e*i + b*f*g + c*d*h - c*e*g - b*d*i - a*f*h) % m\n",
"\n",
"def det(mat, m=256):\n",
" # I dislike having to round here, but it returns a float\n",
" # I wish it returned a native \"B\" type\n",
" return int(round(np.linalg.det(mat),0)) % m\n",
"\n",
"a = ((-2,2,-3),(-1,1,3),(2,0,-1))\n",
"assert_equal(det(a), 18)\n",
"assert_equal(det(a), det3(a))\n",
"\n",
"# ?\n",
"# assert that they didn't change since the last time I ran it\n",
"assert_equal(det(f1), 128)\n",
"assert_equal(det(f2), 160)\n",
"assert_equal(det(f3), 128)"
]
},
{
"cell_type": "markdown",
"id": "568ad4ed-7894-465b-9bf3-f19f2269c0f3",
"metadata": {
"tags": []
},
"source": [
"[This](https://math.stackexchange.com/questions/273054/how-to-find-matrix-inverse-over-finite-field) suggests to find the inverse matrix by first finding the adjugate then applying\n",
"\n",
"> (1/det(A))adj(A)=inv(A)\n",
"\n",
"Under mod p\n",
"\n",
"---\n",
"\n",
"The [adjugate](https://en.wikipedia.org/wiki/Adjugate_matrix) is the inverse of the cofactor matrix.\n",
"\n",
"---\n",
"\n",
"The cofactor matrix is made by multiplying the matrix minor of each (i,j) of the original matrix times a sign factor.\n",
"\n",
"---\n",
"\n",
"The (i,j)-minor of matrix A is the determinant of the matrix A with row i & column j removed."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}