## real analysis – Is there a functional equation for \$sum_{n=1}^{infty}(-1)^{n-1} exp left(-n^{2} pi xright)\$?

It is known that
$$psi(x)=sum_{n=1}^{infty} exp left(-n^{2} pi xright)$$

has the funcyional equation
$$frac{1+2 psi(x)}{1+2 psi(1 / x)}=frac{1}{sqrt{x}}$$

$$sum_{n=1}^{infty} (-1)^{n-1}exp left(-n^{2} pi xright)$$
does this function has a functional equation of its own?

Thanks.

## General class of functions satisfying growth condition on a given functional :

Consider analytic function $$f$$ which is positive real valued for positive real domain .

I want to know if there’s a general class of function $$f$$ which satisfies the following growth of given functional :

$$int_0^infty frac{f(x + iy) − f(x − iy)}{e^{2πy}-1} dy=oleft(int_1^x f(t) dtright)$$ ?

(Sorry for such a generality and straight-forwardness of the question )

## functional programming – What’s the value of IO Monad?

When I’m writing code in the form of IO Monad, I wonder what’s real value of it.For example I have a function as `def something(in: In): IO(Out)`; my function is a `pure function` that **returns an impure recepie(just another function) which could be composed with other receipes, and finally triggered.

Is postponing the side-effects the best I get? In other words, what’s the difference in the value between a function with side-effects, and a pure function which return an impure function? In my eyes both approches could be testable, trackable, debugable (the IO version could be harder, as stacktraces are not as helpful as simple stack-calls).

## functional analysis – Is the composition of closed operators closed?

Let $$K,G,H$$ be Hilbert spaces with $$D_A subseteq K$$, $$D_B subseteq G$$ (possibly not dense) subspaces and let $$A: D_A rightarrow K$$ and $$B:D_B rightarrow H$$ be closed linear operators.

Then is the linear operator $$B circ A: A^{-1}(D_B) rightarrow H$$ a closed linear operator? where $$A^{-1}(D_B)$$ denotes the preimage of the domain of $$B$$.

Claim: This is the case when $$D_A$$ is complete and $$A$$ is bounded (see e.g. here). More generally, this is true when for any convergent sequence $$(x_n)_{n in mathbb{N}}$$ with $$x_n rightarrow x in K$$ we have $$Ax_n rightarrow y$$ for some $$y in G$$.

Proof of claim: Let $$x_n rightarrow x$$ and $$BAx_n rightarrow y’$$ for some $$y’ in K$$. Then by assumption $$Ax_n rightarrow y$$. So since $$A$$ is closed, $$x in D_A$$ and $$Ax = y$$. But now since $$B$$ is closed and $$Ax_n rightarrow y$$ and $$BAx_n rightarrow y’$$ we have $$y in D_B$$ and $$y’ = By = B A x$$, which proves the claim.

So I suspect that the answer to the original question is negative, but I have not been able to construct a counter example.

Partial answers and pointers to literature are very welcome. Thank you very much in advance.

## functional programming – JavaScript — Convert decimal to another base

Source code is maintained on GitHub and may be cloned via…

``````mkdir -vp ~/git/hub/javascript-utilities

cd ~/git/hub/javascript-utilities

git clone git@github.com:javascript-utilities/decimal-to-base.git
``````

… and a Live demo is hosted thanks to GitHub Pages.

The build target is ECMAScript version 6, and so far both manual tests and automated JestJS tests show that the `decimalToBase` function functions as intended, both for Browser and NodeJS environments.

Aware of `(_number_).toString(_radix_)` for converting numbers to another base I am, however, the built-in `Number.toString()` method doesn’t seem to have options for prefixing Binary, Octal, or Heximal bases, among other features that I’m implementing.

Example Usage

``````decimalToBase(540, 16);
//> "0x21C"
``````

I am concerned with improving the JavaScript, and TypeScript that builds the JavaScript; ie. the HTML and CSS are intended to be simple and functional.

Please direct suggestions, and point out any mistakes that I’ve made, in regards to JavaScript. If anyone has a clean way of handling floating point numbers that’d be super, because at this time the current implementation only handles integers.

``````"use strict";

/**
* Converts decimal to another base, eg. hex, octal, or binary
* @function decimalToBase
* @param {number|string} decimal
* @param {number|string} radix - default `16`
* @param {boolean} verbose - default `false`
* @param {string()} symbols_list - default `(...'0123456789abcdefghijklmnopqrstuvwxyz')`
* @returns {string}
* @throws {SyntaxError|RangeError}
* @author S0AndS0
* @example
* decimalToBase(540, 16);
* //> "0x21C"
*/
const decimalToBase = (decimal, radix = 16, verbose = false, symbols_list = (...'0123456789abcdefghijklmnopqrstuvwxyz')) => {
decimal = Number(decimal);
const max_base = symbols_list.length;
if (isNaN(decimal)) {
throw new SyntaxError('First argument is Not a Number');
}
throw new SyntaxError('radix is Not a Number');
}
else if (radix > max_base) {
throw new RangeError(`radix must be less than max base -> \${max_base}`);
}
else if (radix < 2) {
throw new RangeError(`radix must be greater than 2`);
}

let prefix = '';
prefix = '0x';
break;
case 8: // Octal
prefix = '0o';
break;
case 2: // Binary
prefix = '0b';
break;
}

if (radix >= 10 && decimal < 10) {
return `\${prefix}\${symbols_list(decimal)}`;
}

let converted = '';
let dividend = decimal;
while (dividend > 0) {
const remainder = dividend % radix;
const quotient = (dividend - remainder) / radix;
/* istanbul ignore next */
if (verbose) {
console.log(`dividend -> \${dividend}`, `remainder -> \${remainder}`, `quotient -> \${quotient}`);
}
converted = `\${symbols_list(remainder)}\${converted}`;
dividend = quotient;
}

return `\${prefix}\${converted.toUpperCase()}`;
};

/* istanbul ignore next */
if (typeof module !== 'undefined') {
module.exports = decimalToBase;
}``````
``````*, *::before, *::after {
box-sizing: border-box;
}

.container {
max-width: 50%;
position: relative;
}

.row {
}

.row::after {
content: '';
position: absolute;
left: 0;
background-color: lightgrey;
height: 0.2rem;
width: 100%;
}

.label {
font-weight: bold;
font-size: 1.2rem;
width: 19%;
}

.text_input {
float: right;
width: 79%;
}``````
``````<!DOCTYPE html>
<html lang="en" dir="ltr">
<meta charset="utf-8">
<title>Tests Decimal to Base</title>

<!-- <script type="text/javascript" src="assets/js/modules/decimal-to-base/decimal-to-base.js"></script> -->
<script type="text/javascript">
function updateOutput(_event) {
const decimal = document.getElementById('decimal').value;
const output_element = document.getElementById('output');

let output_value = 'NaN';
try {
} catch (e) {
if (e instanceof SyntaxError) {
console.error(e);
} else if (e instanceof RangeError) {
console.error(e);
} else {
throw e;
}
}

output_element.value = output_value;
}

});
</script>
<body>
<div class="container">
<div class="row">
</div>
<br>

<div class="row">
<span class="label">Input: </span>
<input type="text" class="text_input" id="decimal">
</div>
<br>

<div class="row">
<span class="label">Output: </span>
</div>
</div>
</body>
</html>``````

For completeness here are the JestJS tests…

``````"use strict";
/**
* @author S0AndS0
* @example <caption>Jest Tests for decimalToBase</caption>
* // Initialize new class instance and run tests
* const test_decimalToBase = new decimalToBase_Test();
* test_decimalToBase.runTests();
*/
class decimalToBase_Test {
constructor() {
this.decimalToBase = require('../decimal-to-base.js');
this.decimal_limits = { min: 1, max: 16 };
this.base_configs = (
{
base: 2,
name: 'Binary'
},
{
base: 3,
name: 'Trinary'
},
{
base: 4,
name: 'Quaternary'
},
{
base: 5,
name: 'Quinary AKA Pental'
},
{
base: 6,
name: 'Senary AKA Heximal or Seximal'
},
{
base: 7,
name: 'Septenary'
},
{
base: 8,
name: 'Octal'
},
{
base: 9,
name: 'Nonary'
},
{
base: 10,
name: 'Decimal AKA Denary'
},
{
base: 11,
name: 'Undecimal'
},
{
base: 12,
name: 'Duodecimal AKA Dozenal or Uncial'
},
{
base: 13,
name: 'Tridecimal'
},
{
base: 14,
},
{
base: 15,
},
{
base: 16,
}
);
}

/**
* Runs all tests for this module
*/
runTests() {
this.testsErrors();
this.testsConversion();
}

/**
* Uses `(Number).toString()` to check conversions, note this will only work for radix between `2` though `36`, and default `symbols_list`
*/
decimal = Number(decimal);
let prefix = '';
case 2:
prefix = '0b';
break;
case 8:
prefix = '0o';
break;
case 16:
prefix = '0x';
break;
}
}

/**
* Tests available error states
*/
testsErrors() {
test('Is a `SyntaxError` thrown, when `decimal` parameter is not a number?', () => {
expect(() => {
this.decimalToBase('spam!', 10);
}).toThrow(SyntaxError);
});
test('Is a `SyntaxError` thrown, when `radix` parameter is not a number?', () => {
expect(() => {
this.decimalToBase(42, 'ham');
}).toThrow(SyntaxError);
});
test('Is a `RangeError` thrown, when `symbols_list` is not long enough?', () => {
expect(() => {
this.decimalToBase(42, 37);
}).toThrow(RangeError);
});
test('Is a `RangeError` thrown, when `radix` parameter is less than `2`?', () => {
expect(() => {
this.decimalToBase(42, 1);
}).toThrow(RangeError);
});
}

/**
* Loops through `this.base_configs` and tests decimal integers between `this.decimal_limits('min')` and `this.decimal_limits('max')`
*/
testsConversion() {
const min = this.decimal_limits('min');
const max = this.decimal_limits('max');
this.base_configs.forEach((config) => {
const { base } = config;
const { name } = config;
for (let decimal = min; decimal <= max; decimal++) {
const expected_value = this.constructor.doubleChecker(decimal, base);
test(`Base \${base}, does \${decimal} equal "\${expected_value}" in \${name}?`, () => {
expect(this.decimalToBase(decimal, base)).toEqual(expected_value);
});
}
});
}
}
const test_decimalToBase = new decimalToBase_Test();
test_decimalToBase.runTests();
``````

## Questions

• Are there any mistakes?

• Have I missed any test cases?

• Any suggestions on expanding this implementation to handle floating point numbers?

• Any suggestions on making the code more readable?

• Are there any additional features that are wanted?

## functional analysis – Show an inequality for an integral of a curve constrained to an open ball

Let $$E$$ be a $$mathbb R$$-Banach space, $$v:Eto(1,infty)$$ be continuous and $$v_i:(0,infty)to(1,infty)$$ be continuous and nondecreasing with $$v_1(left|xright|_E)le v(x)le v_2(left|xright|_E);;;text{for all }xin E,tag1$$ $$v_1(a)xrightarrow{atoinfty}inftytag2$$ and $$av_2(a)le C_1v_1^theta(a);;;text{for all }a>0tag3$$ for some $$C_1ge0$$ and $$thetage1$$. Now, let $$rin(0,1)$$ and $$rho(x,y):=inf_{substack{gamma:in:C^1((0,:1),:E)\ gamma(0):=:x\ gamma(1):=:y}}int_0^1v^rleft(gamma(t)right)left|gamma'(t)right|_E:{rm d}t;;;text{for }x,yin E.$$

Let $$k>0$$ and $$B_k$$ denote the open ball around $$0in E$$ with radius $$k$$. Let $$x,yin E$$ and $$varepsilon>0$$. By definition of the infimum, there is a $$gammain C^1((0,1),E)$$ with $$gamma(0)=x$$, $$gamma(1)=y$$ and $$rho(x,y)leint_0^1v^rleft(gamma(t)right)left|gamma'(t)right|_E:{rm d}t

Question: Why can we conclude that $$int_0^11_{B_k}(gamma(t))left|gamma'(t)right|_E:{rm d}tle 2kleft(frac{v_2(k)}{v_1(0)}right)^r+varepsilon?tag5$$

The argument should be that we could otherwise replace the corresponding piece of curve by a straight line and obtain a value which differed from $$rho(x,y)$$ by more than $$varepsilon$$, but how can we show this rigorously?

## Functional Decomposition Java – Stack Overflow

My professor graded my assignment and said that it needed something called functional decomposition. What is this and how would it look in this program i have for palindromes.

``````import java.util.Scanner;
public class Palindrome {

public static void main(String() args) {
String word;
/**
* create scanner for input and ask user for phrase/word
*/
Scanner kb = new Scanner(System.in);
System.out.println("Enter a word to see if its a palindrome.");
word = kb.nextLine();

/**
* this just removes spaces. For a palindrome like "race car"
*/
String newWord = word.replace(" ", "");
/**
* this removes commas like in given lab examples
*/
String newWord1 = newWord.replace(",", "");

System.out.println(isPalindrome(newWord1));

}
/**
*
* @param word
* @return true or false
*/
public static boolean isPalindrome(String word) {
/**
* if the word is 1 or 2 characters long its automatically a palindrome
*/
if(word.length() == 0 || word.length() == 1) {
return true;
}
/**
* use recursion to keep checking the first and last characters of each substring until result
*/
if (word.charAt(0) == word.charAt(word.length() - 1)) {
return isPalindrome(word.substring(1, word.length() - 1));
}
return false;
}
}
``````

As a quick side note, he said that i needed to have 2 java files for this. What would the second java file be for this if all i had to do was make a method. I use separate files for like making classes, constructors, inheritance, etc. Certainly i didn’t need to make two files for something small like this? I asked him in an email anyway but so its fine if you don’t know. Thank you for your time.

## Basic functional programming understanding in GO

I’m new GO coder (stared this Sunday) coming from different backgrounds, I wrote the below code based on my understanding of Go within these couple of days, and impacted of my experience in other languages, I like to share for Go experts review/comments and feedback.

``````package main

import (
"fmt"
"log"
"sort"
"time"
)

const (
layoutISO = "2006-01-02"
layoutUS  = "January 2, 2006"
custom    = "1/2/2006"
)

type Inventories ()Inventory
type Inventory struct { //instead of: map(string)map(string)Pairs
Warehouse string
Item      string
Batches   Lots
}
type Lots ()Lot
type Lot struct {
Date  time.Time
Key   string
Value float64
}

func main() {
fmt.Println("Hello, 世界")
date := "12/31/19" // "1999-12-31"
t, _ := time.Parse(custom, date)
var inventories = new(Inventories)
var inventory = new(Inventory) // Or = Inventory{} both are working //warehouse(item(batch, qty))
inventory.Warehouse = "DMM"
inventory.Item = "Helmet"
inventory.Batches = append(inventory.Batches, Lot{t, "Jan", 10})
inventory.InsertBatch(Lot{time.Now(), "Jan", 30})
inventory.Batches.Insert(Lot{time.Now(), "Feb", 30})
fmt.Printf("nBefore grouping: %v %Tn", inventory, inventory)

x := Inventory{
Warehouse: "DMM",
Item:      "Gloves",
Batches: Lots{
Lot{mustTime(time.Parse(custom, "1/7/2020")), "Jan", 50},
Lot{mustTime(time.Parse(custom, "2/1/2020")), "Feb", 20},
Lot{mustTime(time.Parse(custom, "1/5/2020")), "Jan", 40},
Lot{mustTime(time.Parse(custom, "2/9/2020")), "Feb", 60},
},
}
fmt.Printf("nBefore grouping: %v %Tn", x, x)

// Below can be used for grouping batches in each warehouse seperatly, this can be combined in the lines under
//  inventory.Batches.Group()
//  x.GroupBatches()
//  fmt.Printf("nAfter grouping: %v %Tn", inventory, inventory)
//  fmt.Printf("nAfter grouping: %v %Tn", x, x)

// Above can be replaced by below
inventories.Insert(*inventory)
inventories.Insert(x)
inventories.GroupBatches()

fmt.Printf("nInventories after gouping batches: %v %Tn", inventories, inventories)

inventories.SortBatches()

fmt.Printf("nInventories after sorting batches: %v %Tn", inventories, inventories)
}

func (i *Inventories) Insert(x Inventory) {
*i = append(*i, x)
}
func (i *Inventories) GroupBatches() {
inv := new(Inventories)
for _, el := range *i {
el.GroupBatches()
inv.Insert(el)
}
(*i).ReplaceBy(inv)
}

func (i *Inventories) SortBatches() {
inv := new(Inventories)
for _, el := range *i {
sort.Sort(Lots(el.Batches))
inv.Insert(el)
}
(*i).ReplaceBy(inv)
}

func (i *Inventories) ReplaceBy(x *Inventories) {
*i = *x
}

func (i *Inventory) InsertBatch(x Lot) {
(*i).Batches = append((*i).Batches, x)
}

func (i *Inventory) GroupBatches() {
(*i).Batches.Group()
}

func (p *Lots) Group() {
lots := new(Lots)
lots.FromMap(p.Map())
p.ReplaceBy(lots)
}

func (p *Lots) FromMap(m map(string)float64) {
for k, v := range m {
(*p).Insert(Lot{time.Now(), k, v})
}
}

// Below to enable sorting: sort.Sort(Lots(lots))
func (l Lots) Len() int           { return len(l) }
func (l Lots) Less(i, j int) bool { return (l(i).Date).Before(l(j).Date) } // { return l(i).Key < l(j).Key }
func (l Lots) Swap(i, j int)      { l(i), l(j) = l(j), l(i) }

func (p *Lots) Insert(x Lot) {
*p = append(*p, x)
}

func (p *Lots) ReplaceBy(x *Lots) {
*p = *x
}

func (p *Lots) Map() map(string)float64 {
sum := make(map(string)float64)
for _, el := range *p {
sum(el.Key) = sum(el.Key) + el.Value
}
return sum
}

type Interface interface {
// Len is the number of elements in the collection.
Len() int
// Less reports whether the element with
// index i should sort before the element with index j.
Less(i, j int) bool
// Swap swaps the elements with indexes i and j.
Swap(i, j int)
}

func mustTime(t time.Time, err error) time.Time {
failOnError(err)
return t
}

func failOnError(err error) {
if err != nil {
log.Fatal("Error:", err)
panic(err)
}
}
``````

The above code is fully functioning, and give the results as below:

``````(Running) go run "d:goplaygrouping.go"
Hello, 世界

Before grouping: &{DMM Helmet ({0001-01-01 00:00:00 +0000 UTC Jan 10} {2020-06-05 00:26:16.9165066 +0300 +03 m=+0.006981101 Jan 30} {2020-06-05 00:26:16.9165066 +0300 +03 m=+0.006981101 Feb 30})} *main.Inventory

Before grouping: {DMM Gloves ({2020-01-07 00:00:00 +0000 UTC Jan 50} {2020-02-01 00:00:00 +0000 UTC Feb 20} {2020-01-05 00:00:00 +0000 UTC Jan 40} {2020-02-09 00:00:00 +0000 UTC Feb 60})} main.Inventory

Inventories after gouping batches: &({DMM Helmet ({2020-06-05 00:26:16.9175045 +0300 +03 m=+0.007979001 Jan 40} {2020-06-05 00:26:16.9175045 +0300 +03 m=+0.007979001 Feb 30})} {DMM Gloves ({2020-06-05 00:26:16.9175045 +0300 +03 m=+0.007979001 Jan 90} {2020-06-05 00:26:16.9175045 +0300 +03 m=+0.007979001 Feb 80})}) *main.Inventories

Inventories after sorting batches: &({DMM Helmet ({2020-06-05 00:26:16.9175045 +0300 +03 m=+0.007979001 Jan 40} {2020-06-05 00:26:16.9175045 +0300 +03 m=+0.007979001 Feb 30})} {DMM Gloves ({2020-06-05 00:26:16.9175045 +0300 +03 m=+0.007979001 Jan 90} {2020-06-05 00:26:16.9175045 +0300 +03 m=+0.007979001 Feb 80})}) *main.Inventories

(Done) exited with code=0 in 3.624 seconds
$$```$$
``````

## functional programming – Node.js ws server: global or local functions?

I’m working on a Node.js chat app project using the `ws` library. I have it up and running but I’m still making improvements and adding stuff like authentication, etc. Before I get too far, I am wondering what the best functional approach to handling messages (and other events) is. For example, right now I have the following code to handle a message from the client (I cut out most of it, just keeping in one function to use as an example):

``````wss.on('connection', (ws, req) => {
// Give them the funtions (uses local ws)
function handleMessage(msgJSON) {
let incMsg = {};
try {
incMsg = JSON.parse(msgJSON); // message from client
} catch {
console.error("Could not parse sent JSON");
return;
}
switch (incMsg.type) {
case "message":
ws.send("Message sent.");
// send the message to other clients:
wss.clients.forEach(client => {
// send message to all open clients but not this client
if (client !== ws && client.readyState === WebSocket.OPEN) {
}
}
// some more cases, like for "meta"
}
}

// more functions ...

ws.on('message', message => {
handleMessage(message);
});
}
``````

This strategy takes advantage of having the `ws` variable inside the inner function, but this makes the `wss.on('connection')` handler full of a lot of functions. Is it better practice to use this approach or to make a global sort of function that you then pass the client into? My alternate idea looks like this:

``````function handleMessage(msgJSON, ws) { // accepts the current client
let incMsg = {};
try {
incMsg = JSON.parse(msgJSON); // message from client
} catch {
console.error("Could not parse sent JSON");
return;
}
switch (incMsg.type) {
case "message":
ws.send("Message sent.");
// send the message to other clients:
wss.clients.forEach(client => {
// send message to all open clients but not this client
if (client !== ws && client.readyState === WebSocket.OPEN) {
}
}
break;
// some more cases, like for "meta" ...
}
}

// more functions ...

wss.on('connection', (ws, req) => {
ws.on('message', message => {
handleMessage(message, ws); // pass along the ws client
});
}
$$```$$
``````

## looping – How can I replace a set of Nested For Loops with a Functional Code Alternative?

Despite having looked over various posts concerning optimizing nested For loop expressions into a functional programming equivalent I still can not figure out how to actually to do this. Such constructs are inefficient in Mathematica and hence, I seek to find a more efficient approach. Sadly, having started with programming with FORTRAN (prior to IV), some ideas die hard in an aging brain.

I have a very large array that I must evaluate. This array m, is 31×2754, but for purposes of example I have down-sampled so that it is only a 30 x 32 matrix. It produces a square matrix whose order is the size of the columns (here 32, when downsampled, but 2754×2754 when fully sampled). Although a doubly nested set of For loops provides the answer I seek and is relatively efficient when the matrix is only 32×32, it’s efficiency degrades rapidly as n approaches 2754. I am at a loss to how to convert the following procedural code snippet into a functional programming equivalent that is more efficient.

The test input (ignoring how I get there, which itself is rather complicated) is:

``````m = {{0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1,
0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0,
0}, {1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0,
0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1}}

Dimensions(m)

{30, 32}
``````

Although not essential, to be sure that the output is properly created I create
a constant array and fill the matrix c, which will be the eventual output matrix
with a value that WILL NOT be present in the matrix upon completion, so that by
quick observation I can be sure that the matrix has been properly populated.

This is done as follows and establishes the order of the square matrix, where the length of columnlabels for this snippet is 32 (the actual column labels are irrelevant
here):

`````` c = ConstantArray(3, {Length(columnlabels), Length(columnlabels)});

{characterrows, charactercolumns} = Dimensions(c)
``````

The loop construct I wish to replace with a functional approach effectively compares two column of m, each of which has only two distinct values (either 0 or 1), and for which their product partial order potentially generates 4 distinct possibilities (vertices) ({0,0},{1,0},{0,1},{1,1}} and for which I want to assign to the each pair of columns a 1 if less than 4 of these possibilities are actually present in the comparison and a 0 if all 4 possibilities are present when comparing the two columns). This construct is as follows:

`````` t0 = AbsoluteTime();

For(i = 1, i <= Length(columnlabels), i++,
For(j = 1, j <= Length(columnlabels), j++,
f = m((All, i));
g = m((All, j));
c((i, j)) = If(Length(Tally(Table({g((n)), f((n))}, {n, 1, Length(g)}))) < 4, 1, 0);
)
)

t1 = AbsoluteTime();
timeelapsed = UnitConvert(Quantity(t1 - t0, "Seconds"), "Minutes")
``````

What is the most efficient functional programming expression needed to replace this nested set of For loops?