[Question]
  [
## Introduction
Today we're gonna take care of the bane of first-year linear algebra students: matrix definiteness! Apparently this doesn't yet have a challenge so here we go:
## Input
* A \$n\times n\$ [symmetric](https://en.wikipedia.org/wiki/Symmetric_matrix) Matrix \$A\$ in any convenient format (you may also of course only take the upper or the lower part of the matrix)
* Optionally: the size of the matrix \$n\$
## What to do?
The challenge is simple: Given a real-valued matrix \$n\times n\$ Matrix decide whether it is positive definite by outputting a truthy value if so and a falsey value if not.
You may assume your built-ins to actually work precisely and thus don't have to account for numerical issues which could lead to the wrong behaviour if the strategy / code "provably" should yield the correct result.
## Who wins?
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes (per-language) wins!
---
## What is a positive-definite Matrix anyways?
There are apparently 6 equivalent formulations of when a symmetric matrix is positive-definite. I shall reproduce the three easier ones and reference you to [Wikipedia](https://en.wikipedia.org/wiki/Positive-definite_matrix#Characterizations) for the more complex ones.
* If \$\forall v\in\mathbb R^n\setminus \{0\}: v^T Av>0\$ then \$A\$ is positive-definite.   
This can be re-formulated as:  
 If for every non-zero vector \$v\$ the (standard) dot product of \$v\$ and \$Av\$ is positive then \$A\$ is positive-definite.
* Let \$\lambda\_i\quad i\in\{1,\ldots,n\}\$ be the [eigenvalues](https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors) of \$A\$, if now \$\forall i\in\{1,\ldots,n\}:\lambda\_i>0\$ (that is all eigenvalues are positive) then \$A\$ is positive-definite.   
If you don't know what eigenvalues are I suggest you use your favourite search engine to find out, because the explanation (and the needed computation strategies) is too long to be contained in this post.
* If the [Cholesky-Decomposition](https://en.wikipedia.org/wiki/Cholesky_decomposition) of \$A\$ exists, i.e. there exists a lower-triangular matrix \$L\$ such that \$LL^T=A\$ then \$A\$ is positive-definite. Note that this is equivalent to early-returning "false" if at any point the computation of the root during the algorithm fails due to a negative argument.
## Examples
### For truthy output
\begin{pmatrix}1&0&0\\0&1&0\\0&0&1\end{pmatrix}
\begin{pmatrix}1&0&0&0\\0&2&0&0\\0&0&3&0\\0&0&0&4\end{pmatrix}
\begin{pmatrix}5&2&-1\\2&1&-1\\-1&-1&3\end{pmatrix}
\begin{pmatrix}1&-2&2\\-2&5&0\\2&0&30\end{pmatrix}
\begin{pmatrix}7.15&2.45\\2.45&9.37\end{pmatrix}
### For falsey output
(at least one eigenvalue is 0 / positive semi-definite)
\begin{pmatrix}3&-2&2\\-2&4&0\\2&0&2\end{pmatrix}
(eigenvalues have different signs / indefinite)
\begin{pmatrix}1&0&0\\0&-1&0\\0&0&1\end{pmatrix}
(all eigenvalues smaller than 0 / negative definite)
\begin{pmatrix}-1&0&0\\0&-1&0\\0&0&-1\end{pmatrix}
(all eigenvalues smaller than 0 / negative definite)
\begin{pmatrix}-2&3&0\\3&-5&0\\0&0&-1\end{pmatrix}
(all eigenvalues smaller than 0 / negative definite)
\begin{pmatrix}-7.15&-2.45\\-2.45&-9.37\end{pmatrix}
(three positive, one negative eigenvalue / indefinite)
\begin{pmatrix}7.15&2.45&1.23&3.5\\2.45&9.37&2.71&3.14\\1.23&2.71&0&6.2\\3.5&3.14&6.2&0.56\end{pmatrix}
  
[Answer]
# C, 108 bytes
*-1 byte thanks to Logern*  
*-3 bytes thanks to ceilingcat*
```
f(M,n,i)double**M;{for(i=n*n;i--;)M[i/n][i%n]-=M[n][i%n]*M[i/n][n]/M[n][n];return M[n][n]>0&(!n||f(M,n-1));}
```
[Try it online!](https://tio.run/##rVO7csIwEKytr7iQISMZKfgRKgF/4DqFowL8IDdjZMaYJuBfjyMZD014uKDQSLq9vb2TZhOxSZK2zWnENUeWlod1kbluJI95WVFcaFdLFEKyKMapVjGOtRKLKO6Pbh/WatrFtJJVVh8qDf116b3RF306dQLCZ0w27SvqpDikGcz3dYrl@/eSoK5hu0JNGRyJc@4CTBuxgoWNOLTvLFZdxiXQ3QF8DuDZBQ3/j1rEv4t2GdAYsMt4oDYz2QEH4V@tF5zVrqOiQ0xGOFjNMmzN4Go9i8xuzhacZwu9wWrhQ7WPR2qWO3y2@/8mnvhv4glqYriafY3wZj37zrOhasRpJHGMI4Fap6AxhSfNNoc9/mSlMReD6eUce4oZdDJhhrurDCOno3H6pUccLIyKQ2CcSJzeq54kDWl/k7xYbfat@NSlwO2uwARrYdh/ "C (gcc) – Try It Online")
Performs Gaussian elimination and checks whether all diagonal elements are positive (Sylvester's criterion). Argument `n` is the size of the matrix minus one.
[Answer]
# MATLAB/[Octave](https://www.gnu.org/software/octave/), ~~19~~ ~~17~~ 12 bytes
```
@(A)eig(A)>0
```
[Try it online!](https://tio.run/##rZPPasMwDMbvfYrvUhofLPwnbihmY3uO0UNZnREY22i7vX4mC1PijR1qlsMnSzY/PiTl/fly@ErzeEdE80P3qNL0wnpv5mnsxu7JwsBEAyvKca9QfQrH6fzRbS6nz7RREen1nEppPPBZam9HYJ1frBZUIboSDXyJBv1eNVED07SNjs1y0Fnhl34bvWoHF1kCO8x@vama0EQdyLJd6kPMgh35oe7sjdSC9VezfTHrGrFYS76q10D/tQeNXP0LrG1bc39wnewTtyP8L1fmpmVwotD16Bq513WAJefhabEXXB94kcn2US4lNdiSi/xOLnICQ2F7y58j6fwN "Octave – Try It Online")
The function eig provides the eigenvalues in ascending order, so if the first eigenvalue is greater than zero, the other ones are too.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~11~~ 10 bytes
```
ṖṖ€$ƬÆḊṂ>0
```
Uses [Sylvester's criterion](https://en.wikipedia.org/wiki/Sylvester%27s_criterion "Sylvester's criterion - Wikipedia").
[Try it online!](https://tio.run/##jVBLDoIwEN1zilm4gKRDWgohbtx6CMLSjeECbllo4gE8BQeQNYn3wIvUmVJLQRNNpknfy3tvPsdD05yMGfsb1bPtNo9uOI/369i3O2mGC1FUe2PiOIoAqkoJkFS1IAQVfdUCMVETDLULQbYmqPSaoMp9ChQC2IbKaRhwW0@gBUTq2cQU67K3hgEnyTCFm0tvKlNFiizNC6fhr4BtqkurSYQ7Ak/8mZ5/SSdFOJKlvEa6sUPCvvmE@LcJAxM316GG5y1@mKbtMVgfp/1xPkDyAg "Jelly – Try It Online")
### How it works
```
ṖṖ€$ƬÆḊṂ>0  Main link. Argument: M (matrix)
   $Ƭ       Do the following until a fixed point is encountered.
Ṗ             Pop; remove the last row of the matrix.
 Ṗ€           Pop each; remove the last entry of each row.
     ÆḊ     Take the determinants of the resulting minors.
       Ṃ    Take the minimum.
        >0  Test if the least determinant is positive, i.e., if all determinants are.
```
[Answer]
# [R](https://www.r-project.org/), 29 bytes
```
function(m)all(eigen(m)$va>0)
```
[Try it online!](https://tio.run/##lVFBCsIwELznFQsKJrCB1Nqb@hIvMTYaaFNIU0HEt9etorShHlxyyAwzwywbervrbedNdI3ntdBVxUt3Lof/8qr3SvS1jsGZsoWtBFa5NnLGFjQQQxcvNxaOzp@44RkqVAIZvMZwhVmCiRGC4dcBBcIaZTYSEYZsSskBI@RTK5EkXY91hClQJWkKc0XWd2Wrq7a8jXPy2ZzNXA6pkgoDOdGpV9WEGt50cfmHVSZWqpInOtqh@Gml1W0TeA3Ow@eU4k5KoyO3dGZcHfxKsAfrnw "R – Try It Online")
---
Alternative using cholesky :
# [R](https://www.r-project.org/), ~~34~~ 33 bytes
```
function(m)is.array(try(chol(m)))
```
[Try it online!](https://tio.run/##lVFBCsIwELznFQse3MBGUqs3/YmXGBsMtCmk8VDEt9dtRWmDHlz2MsPMMMvGwR0Hdws2@TZgI323MTGaHlPs0V7bmjkph8ak6G3VwUGBqH2XUIgVD6R4S9dexLMPF7RYkCYtScA0FjUVGWZGSkEfB@wJtqSKmYgxFEtKjZigXFqZZOl2rmPMgTpL01Rqtr4qO1N3VT/PKb/m7L7lsCqrMJILnZ6qZtS4y8PVH1aVWblKmen4hv1PK5/u2ogN@ADvV8o7K61J6PjFtD6FtRQPMTwB "R – Try It Online")
-1 byte thanks to @Giuseppe
[Answer]
# [Haskell](https://www.haskell.org/), 56 bytes
```
f((x:y):z)=x>0&&f[zipWith(-)v$map(u/x*)y|u:v<-z]
f[]=1>0
```
[Try it online!](https://tio.run/##bVHLasMwEDxbX@FDCVJZuXrYhIg6f9BLLz0IUXSoiajjmMYOjum/u7IiRKA5zbCzO5pdHez5@6ttl6XBeFJXomZST3u22TR6dv2HGw6YksvT0fZ4fJmeyfV3VJdXOhvUaFPzPVtc14/DOVcq11q/28GdOtsaY1AU6lyjTGsODJgBzYBH9MwYSFqsisQYyMQYlLG38h2U@7LwRoHQFUEmLypArGUBVZhfHSWL8rbg3qEoq1XwALtCbqMm70bLNCruQ4Y49P8G9KFKkyziLv6J6oEcUtEYKyDQWzCUGYSO1nX@jv4T3j5x/@O6oWjI7bwoW/4A "Haskell – Try It Online")
Basically a port of [nwellnhof's answer](https://codegolf.stackexchange.com/a/172682/82619). Performs gaussian elimination and checks whether the elements on the main diagonal are positive.
~~Fails the first falsey output because of rounding errors, but it would theoretically work with infinite precision.~~ Thanks to [Curtis Bechtel's suggestion](https://codegolf.stackexchange.com/questions/172677/is-the-matrix-positive-definite#comment416654_172688), now the outputs are all correct.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 20 bytes
```
0<Min@Eigenvalues@#&
```
[Try it online!](https://tio.run/##dc7BCgIhEAbge08RBJ1GGMe8FXjpGPQKEm4JrYdyu4jPbrNJbS7s7cf/43d6G2@ut9FfbOkOBfcnH8zRX1142fvgnmazLeeHD9F0JiUJCJhhnRDkN3DMeTUZDQRCjh0xqkmMAVTj@ImAPi2BrmvEawobpv7ZbmI0G/sdJhYvEwtKzBiBqiX/rVtW3g "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 4 bytes
```
Yv0>
```
[Try it online!](https://tio.run/##y00syfmf8D@yzMDuv70CAqgqZKZxqZcUlZZkVKpz1aLIpOYUp3KppyUCKaBcLKpcXgqXS8j/aEMFAwUDayBhCKGAjFiuaFMFIwVdQ2sgaQimdUGUgjFQBsgwUjCyBpGmIB1GQB3GBkAJY4SECUzCCKwBaoEuig26WMR1wRJGCsYgAaB5pkgSAA "MATL – Try It Online")
I've noticed that for the `[3 -2 2; -2 4 0; 2 0 2]` test case, MATL calculates the `0` eigenvalue with a very small inaccuracy, computing something as low as about \$10^{-18}\$. This therefore fails the first falsy test case due to precision issues. Thanks to Luis Mendo for pointing out that a non-empty array is truthy iff all its entries differ from 0, saving 1 byte.
[Answer]
# Mathematica, ~~29~~ 28 bytes
```
AllTrue[Eigenvalues@#,#>0&]&
```
Definition 2.
[Answer]
# [Julia 1.0](http://julialang.org/), 28 bytes
```
using LinearAlgebra
isposdef
```
[Try it online!](https://tio.run/##yyrNyUw0rPj/v7Q4My9dwSczLzWxyDEnPTWpKJErs7ggvzglNe3/fwA "Julia 1.0 – Try It Online")
---
# [Julia 0.6](http://julialang.org/), 8 bytes
```
isposdef
```
[Try it online!](https://tio.run/##yyrNyUw0@/8/s7ggvzglNe3/fwA "Julia 0.6 – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 6 bytes
It is possible to do it using even less bytes, @Mr. Xcoder managed to find a [5 byte MATL answer](https://codegolf.stackexchange.com/a/172680/24877)!
```
YvX<0>
```
**Explanation**
```
Yv     compute eigenvalues
  X<   take the minimum
    0> check whether it is greather than zero
```
[Try it online!](https://tio.run/##ZY5BDkIhEEP3nqIXGDLMQH4MxnN8Y1y4153x@ljmo9G4acOjpdyvj1vvp@d60GPv5wyFNkUOpV92G4uzTVf4dEVhovJGcjPWaDIUHk0xWKNU5kfblXhJmY1UahuCffKF1D/hMsP2HueUfP9I/qgEtvgXH6o/OPYkBkMh2@QL "MATL – Try It Online")
[Answer]
## [Maple](https://www.maplesoft.com/support/help/maple/view.aspx?path=LinearAlgebra%2fIsDefinite), 33 bytes
(i.e. my 2 cents)
```
with(LinearAlgebra):
IsDefinite(A)
```
[Answer]
# JavaScript (ES6), ~~99 95~~ 88 bytes
Same method as [nwellnhof's answer](https://codegolf.stackexchange.com/a/172682/58563). Returns \$0\$ or \$1\$.
```
f=(m,n=0,R=m[n])=>R?f(m,n+1)&R[m.map((r,y)=>y<n&&R.map((v,x)=>r[x]-=v*r[n]/R[n])),n]>0:1
```
[Try it online!](https://tio.run/##lVLLboMwELzzFZx4tLZrGxzUB@mtH4B6QxxQGvoQmAhSFL6ernFDQaQkQT54xzvj8SxfaZPWm@pzt8eyfNt2XRY6BZIhRVFYxDJxw3X0nCnolrlWFBekSHeOU6EWTtonaVmRRhp0AKSKDwkOm5sKqHeR4rtIJmv6wLpNKesy35K8fHfs1@p7/9Ha7qMxhjMnNkz4YoZMCitBuoQ9m5YKSQxQXxaYkvgMgeXNEFj@krbolTA7snjv7q/GfQXKZwxiIPKBBIUYWdFePbqkERCmvBBfDCzYI/OeeMEvb0K0X9K8/j9074Qlf2aJXxD7KE985eDwRRJ4WYNPx6oeJq7V0OHicbpYx4tH@Z6ZCzyWcLjeI4LOZ6R6AvWjEOYfT3W/ximh4HNF@MBVQrpf46pHrLSX7gc "JavaScript (Node.js) – Try It Online")
]