Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

One possibility that comes to mind is using UpValues (nice SE post explaining it)UpValues (nice SE post explaining it).

If I understand you right, you basically want this:

phi /: phi[a__] * phi[b__] = psi[a, b]
phi /: phi[a__]^2 = psi[a, a]

where you basically tell Mathematica that if phi appears anywhere, it should look in what context it is -- i.e., in a product or a square -- and replace it by the appropriate expression on the right side of the assignment.

This will be global, so anytime you write phi, Mathematica will check for context (which introduces an overhead) but you won't have to think about applying rules. (Which can also be dangerous if you use phi for different functions).

One possibility that comes to mind is using UpValues (nice SE post explaining it).

If I understand you right, you basically want this:

phi /: phi[a__] * phi[b__] = psi[a, b]
phi /: phi[a__]^2 = psi[a, a]

where you basically tell Mathematica that if phi appears anywhere, it should look in what context it is -- i.e., in a product or a square -- and replace it by the appropriate expression on the right side of the assignment.

This will be global, so anytime you write phi, Mathematica will check for context (which introduces an overhead) but you won't have to think about applying rules. (Which can also be dangerous if you use phi for different functions).

One possibility that comes to mind is using UpValues (nice SE post explaining it).

If I understand you right, you basically want this:

phi /: phi[a__] * phi[b__] = psi[a, b]
phi /: phi[a__]^2 = psi[a, a]

where you basically tell Mathematica that if phi appears anywhere, it should look in what context it is -- i.e., in a product or a square -- and replace it by the appropriate expression on the right side of the assignment.

This will be global, so anytime you write phi, Mathematica will check for context (which introduces an overhead) but you won't have to think about applying rules. (Which can also be dangerous if you use phi for different functions).

Routine clean-up
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

One possibility that comes to mind is using [UpValues (nice SE post explaining it)][1]UpValues (nice SE post explaining it). If

If I understand you right, you basically want this:

phi /: phi[a__] * phi[b__] = psi[a, b]
phi /: phi[a__]^2 = psi[a, a]

where you basically tell MathematicaMathematica that if phiphi appears anywhere, it should look in what context it is - ie- i.e., in a product or a square -- and replace it by the appropriate expression on the right side of the assignment.

This will be global, so anytime you write phi Mathematica, Mathematica will check for context (which introduces an overhead) but you won't have to think about applying rules. (Which can also be dangerous if you use phi for different functions). [1]: Do people actually use UpValues?

One possibility that comes to mind is using [UpValues (nice SE post explaining it)][1]. If I understand you right, you basically want this:

phi /: phi[a__] * phi[b__] = psi[a, b]
phi /: phi[a__]^2 = psi[a,a]

where you basically tell Mathematica that if phi appears anywhere, it should look in what context it is - ie in a product or a square - and replace it by the appropriate expression on the right side of the assignment.

This will be global so anytime you write phi Mathematica will check for context (which introduces an overhead) but you won't have to think about applying rules. (Which can also be dangerous if you use phi for different functions). [1]: Do people actually use UpValues?

One possibility that comes to mind is using UpValues (nice SE post explaining it).

If I understand you right, you basically want this:

phi /: phi[a__] * phi[b__] = psi[a, b]
phi /: phi[a__]^2 = psi[a, a]

where you basically tell Mathematica that if phi appears anywhere, it should look in what context it is -- i.e., in a product or a square -- and replace it by the appropriate expression on the right side of the assignment.

This will be global, so anytime you write phi, Mathematica will check for context (which introduces an overhead) but you won't have to think about applying rules. (Which can also be dangerous if you use phi for different functions).

changed link
Source Link
AndreasP
  • 608
  • 5
  • 10

One possibility that comes to mind is using [UpValues][1][UpValues (nice SE post explaining it)][1]. If I understand you right, you basically want this:

phi /: phi[a__] * phi[b__] = psi[a, b]
phi /: phi[a__]^2 = psi[a,a]

where you basically tell Mathematica that if phi appears anywhere, it should look in what context it is - ie in a product or a square - and replace it by the appropriate expression on the right side of the assignment.

This will be global so anytime you write phi Mathematica will check for context (which introduces an overhead) but you won't have to think about applying rules. (Which can also be dangerous if you use phi for different functions). [1]: https://reference.wolfram.com/language/ref/UpValues.htmlDo people actually use UpValues?

One possibility that comes to mind is using [UpValues][1]. If I understand you right, you basically want this:

phi /: phi[a__] * phi[b__] = psi[a, b]
phi /: phi[a__]^2 = psi[a,a]

where you basically tell Mathematica that if phi appears anywhere, it should look in what context it is - ie in a product or a square - and replace it by the appropriate expression on the right side of the assignment.

This will be global so anytime you write phi Mathematica will check for context (which introduces an overhead) but you won't have to think about applying rules. (Which can also be dangerous if you use phi for different functions). [1]: https://reference.wolfram.com/language/ref/UpValues.html

One possibility that comes to mind is using [UpValues (nice SE post explaining it)][1]. If I understand you right, you basically want this:

phi /: phi[a__] * phi[b__] = psi[a, b]
phi /: phi[a__]^2 = psi[a,a]

where you basically tell Mathematica that if phi appears anywhere, it should look in what context it is - ie in a product or a square - and replace it by the appropriate expression on the right side of the assignment.

This will be global so anytime you write phi Mathematica will check for context (which introduces an overhead) but you won't have to think about applying rules. (Which can also be dangerous if you use phi for different functions). [1]: Do people actually use UpValues?

Source Link
AndreasP
  • 608
  • 5
  • 10
Loading