\\ Kevin Ryde, November 2021. \\ \\ Usage: gp >1 + 3, \\ over-estimate of log_phi(n) f=fibonacci(k), g=fibonacci(k-1)); \\ reduce f,g to where f is the largest Zeckendorf term in n while(f>n, [f,g]=[g,f-g]); \\ Fibonacci step down my(rev_f=1, rev_g=1, \\ pair of Fibonacci, working upwards ret=0); while(n, if(n>=f, n-=f; ret+=rev_f); \\ Zeckendorf 1 digit [f,g] = [g,f-g]; \\ step down [rev_f, rev_g] = [rev_f+rev_g, rev_f]); \\ step up ret; } A349239_Zeckendorf_reverse_add(n) = n + A349238_Zeckendorf_reverse(n); A349240_Zeckendorf_reverse_sub(n) = n - A349238_Zeckendorf_reverse(n); { print("A349238_Zeckendorf_reverse(n) for n>=0"); print1(" = "); for(n=0,21, print1(A349238_Zeckendorf_reverse(n),",")); print("..."); } { print("A349239_Zeckendorf_reverse_add(n) for n>=0"); print1(" = "); for(n=0,17, print1(A349239_Zeckendorf_reverse_add(n),",")); print("..."); } { print("A349240_Zeckendorf_reverse_sub(n) for n>=0"); print1(" = "); for(n=0,20, print1(A349240_Zeckendorf_reverse_sub(n),",")); print("..."); } \\ In A349238_Zeckendorf_reverse(), the Zeckendorf reprsentation is found by \\ a logarithm for an over-estimate of the greatest Fibonacci number \\ required, then successive comparing and subtract for the terms (A035516) \\ in the required "greedy" way. \\ \\ Each Fibonacci term at the most significant end reverses to a Fibonacci \\ term at the least significant end. \\ \\ The initial f,g could be calculated together by polmod powering, but that \\ measures no speedup. (Perhaps in the future fibonacc() will have an \\ option to get a pair of values.) \\ \\ A349239_Zeckendorf_reverse_add() would be as easy as starting "ret = n" \\ within the reversal, but doing a separate addition is enough. Similarly \\ A349240_Zeckendorf_reverse_sub() could be ret = n and then subtract the \\ low Fibonacci terms but again a separate subtract is enough. print("end");