# Question:Seeking Optimization

## Question:Seeking Optimization

Maple
I've got two procedures set up that work, but I know there have to be better ways to accomplish the same goals. First, I've got a procedure that finds to how many digits two floats (`a` and `b`) agree. I had tried a few methods of examining the `SFloatMantissa` and `SFloatExponent` of the difference, but those methods would fail in unpredictable ways. My current method explodes the floats into lists and compares every entry in a `for` loop. The example below is basically the heart of my procedure (I do take into consideration things like the location of the decimal and trailing zeros): ```[> A:= StringTools:-Explode( convert(a,string) ); [> B:= StringTools:-Explode( convert(b,string) ); [> agreeto := min( nops(A), nops(B) ); [> for _i from 1 to min( nops(A), nops(B) ) do if A[_i]<>B[_i] then agreeto := _i-1; _i := nops(A) + 1; fi; od: ``` The second procedure I'd like to improve replaces certain strings in the options of nested functions. The strings to be replaced are always the first argument of a function, but the functions containing those strings could be any argument of any function in the nest, and not all strings need to be replaced. An example of what I'm looking at: ```[> AAA := F(f("A", options), f("R", options), g(f("a", options),m(f("Q", options), g("P", options), n("y", options), options),options), options); ``` I don't care anything about the options that appear in any of the functions; I only care about those strings. Using the example above, I want to convert any strings of upper-case letters to strings of lower-case letters ( "A" -> "a", etc. ) I have a list of substitutions ( `listofsubs := [ "A" = "a" ... ];` ) ready to be used. What I currently do is convert the nested functions to a string, then use a `for` loop to make any replacements, and finally parse the string after the loop to return a nested function. ```[> BBB:= convert(AAA, string); [> for _i in listofsubs do BBB:= StringTools:-SubstituteAll( BBB, lhs(_i), rhs(_i) ); od: [> AAA := parse( cat( BBB, ";" ) ); ``` I know there have to be better ways of doing either procedure. Any comments, suggestions, or insights? --Schivnorr ﻿