Dan Piponi on Nostr: In Mathematica you can define a function via pattern matching f[x_]:=x+1 and freely ...
In Mathematica you can define a function via pattern matching
f[x_]:=x+1
and freely redefine it
f[x_]:=x+2
or write a function as a lambda
f = Function[{x},x+3]
But woe betide you if you redefine it using pattern matching after defining it as a lambda
f[x_]:=x+4
as it'll substitute(!!!)
Function[{x},x+3][x_]:=x+4
In reality what happens is you accidentally do this in code to invert a 1000x1000 matrix and now a simple numerical computation becomes the attempt to invert a symbolic matrix with unevaluated subexpressions and it runs out of memory and you lose all your work...
Published at
2024-10-20 15:13:25Event JSON
{
"id": "9ad5e925e1d375a80bc5fe0c662ab118761fdd428af9e18e6cb5afe80dbe47e1",
"pubkey": "378fb8535da3c841fdebd0966e5a16f3d21d4e988b925e471f2d8fdf2345d2e9",
"created_at": 1729437205,
"kind": 1,
"tags": [
[
"proxy",
"https://mathstodon.xyz/@dpiponi/113340396704715925",
"web"
],
[
"proxy",
"https://mathstodon.xyz/users/dpiponi/statuses/113340396704715925",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://mathstodon.xyz/users/dpiponi/statuses/113340396704715925",
"pink.momostr"
],
[
"-"
]
],
"content": "In Mathematica you can define a function via pattern matching\n\nf[x_]:=x+1\n\nand freely redefine it\n\nf[x_]:=x+2\n\nor write a function as a lambda\n\nf = Function[{x},x+3]\n\nBut woe betide you if you redefine it using pattern matching after defining it as a lambda\n\nf[x_]:=x+4\n\nas it'll substitute(!!!)\n\nFunction[{x},x+3][x_]:=x+4\n\nIn reality what happens is you accidentally do this in code to invert a 1000x1000 matrix and now a simple numerical computation becomes the attempt to invert a symbolic matrix with unevaluated subexpressions and it runs out of memory and you lose all your work...",
"sig": "6cb06ed5450188ec3eb0118aa228b9eb565404ed941f77d1af59332d76f1f1cfbe2cd0e463c773e8c51975d9d49bb2f7d9c9410b8b760e89dc7eb3038ed056fe"
}