# Permutation of arguments of product of functions

Given a function, g, which is symmetric in its argument, g(a,b)=g(b,a), consider the product g(a,b)*g(c,d)*g(e,f). I would like to get all the permutations of this product with respect to the arguments, that is, terms such as g(a,c)*g(b,d)*g(e,f), which respect the symmetry so that g(c,a)*g(b,d)*g(e,f) would not be among the generated terms. Is there a way to get Mathematica to do this?

Many thanks for any help.

-
g(a,b)^3 counts? –  Kuba Aug 15 '13 at 20:57
That's a good question by @Kuba, my answer supposes we cannot reuse elements. –  Pickett Aug 15 '13 at 20:59
Since I don't know what exactly we are looking for, I'm just going to leave here this comment :) Times @@@ Apply[g, Tuples[Subsets[l, {2}], 3], {2}], where l = {a, b, c, d, e, f} –  Kuba Aug 15 '13 at 21:00

I'm working with four variables instead of six but the same would work for six. The strategy is to find a list of suitable permutations of possible arguments and then apply that to a helper function that encapsulates the product you're looking for.

h[a1_, a2_, a3_, a4_] := g[a1, a2] g[a3, a4];
permutations =
DeleteDuplicates[
Permutations[{a1, a2, a3, a4}], (#[[1 ;; 2]] == #2[[1 ;; 2]] || #[[1 ;; 2]] ==
Reverse[#2[[1 ;; 2]]]) && (#[[3 ;; 4]] == #2[[3 ;;
4]] || #[[3 ;; 4]] == Reverse[#2[[3 ;; 4]]]) &];
DeleteDuplicates[h @@ # & /@ permutations]


{g[a1, a2] g[a3, a4], g[a1, a3] g[a2, a4], g[a1, a4] g[a2, a3]}

After thinking for a while I also came up with this method, which is a bit prettier:

Clear[h,g]; SetAttributes[g, Orderless]
h[{a1_, a2_, a3_, a4_}] := g[a1, a2] g[a3, a4]
DeleteDuplicates[h /@ Permutations[{a1, a2, a3, a4}]]


{g[a1, a2] g[a3, a4], g[a1, a3] g[a2, a4], g[a1, a4] g[a2, a3]}

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.4310300052165985, "perplexity": 7188.558925352581}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-23/segments/1405997893907.95/warc/CC-MAIN-20140722025813-00195-ip-10-33-131-23.ec2.internal.warc.gz"}