Z25997

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z25997"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z25985",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z610",
            "Z16K2": "def Z25985(Z25985K1, Z25985K2):\n\t\n\t#round natural number function Z27778\n\tdef round_natural(Z27778K1, Z27778K2):\n\t\tdigits = len(str(Z27778K1))\n\t\tif digits\u003C=Z27778K2:\n\t\t\treturn Z27778K1\n\t\telse:\n\t\t\tzeroes = digits - Z27778K2\n\t\t\tpowerten = 10**zeroes\n\t\t\tprefix = Z27778K1//powerten\n\t\t\tif ((Z27778K1%powerten)*2 \u003C powerten):\n\t\t\t\treturn prefix*powerten\n\t\t\telif ((Z27778K1%powerten)*2 \u003E powerten):\n\t\t\t\treturn (prefix+1)*powerten\n\t\t\telse:\n\t\t\t\tif (prefix%2==0):\n\t\t\t\t\treturn prefix*powerten\n\t\t\t\telse:\n\t\t\t\t\treturn (prefix+1)*powerten\n\t\n\t#simplify and round return quantity numerator and quantity denominator separately\n\tdef multiply_simplify_and_round(quantity_numerator, quantity_denominator, multiplier_numerator, multiplier_denominator):\n\t\t# find out if the multiplier can be expressed as a decimal (i.e. its denominator has only factors of 2 and 5)\n\t\tdenominator_power_of_2 = 1\n\t\tdenominator_power_of_5 = 1\n\t\twhile (multiplier_denominator%(2**denominator_power_of_2)==0):\n\t\t\tdenominator_power_of_2 += 1\n\t\twhile (multiplier_denominator%(5**denominator_power_of_5)==0):\n\t\t\tdenominator_power_of_5 += 1\n\t\tdenominator_power_of_2 -= 1\n\t\tdenominator_power_of_5 -= 1\n\t\t\n\t\t# if the multiplier can be expressed as a decimal, do so\n\t\tif (2**denominator_power_of_2 * 5**denominator_power_of_5 == multiplier_denominator):\t\n\t\t\tif (denominator_power_of_2 \u003E denominator_power_of_5):\n\t\t\t\tscale_to_decimal_factor = 5**(denominator_power_of_2 - denominator_power_of_5)\n\t\t\telse:\n\t\t\t\tscale_to_decimal_factor = 2**(denominator_power_of_5 - denominator_power_of_2)\n\t\t\tmultiplier_numerator *= scale_to_decimal_factor\n\t\t\tmultiplier_denominator *= scale_to_decimal_factor\n\t\t\t\n\t\tWikifunctions.Debug(str(multiplier_numerator))\n\t\tWikifunctions.Debug(str(multiplier_denominator))\n\t\t\n\t\tsignificant_figures_amount = len(str(abs(quantity_numerator)))\n\n\t\tWikifunctions.Debug(str(significant_figures_amount))\n\n\t\tquantity_numerator *= multiplier_numerator\n\t\tquantity_denominator *= multiplier_denominator\n\t\texcess_significant_figures = len(str(abs(quantity_numerator))) - significant_figures_amount\n\t\twhile (excess_significant_figures\u003E0):\n\t\t\tif (quantity_numerator%10 == 0) and (quantity_denominator%10 == 0):\n\t\t\t\tquantity_numerator //= 10\n\t\t\t\tquantity_denominator //= 10\n\t\t\t\texcess_significant_figures -= 1\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\tif (quantity_denominator//10 == 0):\n\t\t\t\t\t#denominator is already down to less than 10, so numerator should be rounded.\n\t\t\t\t\t#this should work well for common case of denominator=1, but may not for other cases\n\t\t\t\t\tWikifunctions.Debug(str(quantity_denominator))\n\t\t\t\t\tquantity_numerator = round_natural(quantity_numerator, significant_figures_amount)\n\t\t\t\t\tbreak\n\t\t\t\telse:\n\t\t\t\t\t#the denominator has to be rounded too??\n\t\t\t\t\tquantity_numerator = round_natural(quantity_numerator, significant_figures_amount)\n\t\t\t\t\tquantity_denominator = 10*(quantity_denominator//10)\n\t\t\texcess_significant_figures = len(str(abs(quantity_numerator))) - significant_figures_amount\n\t\treturn quantity_numerator, quantity_denominator\n\n\t\n\t#multiplier numerator and denominator will be multiplied into into all three quantity fractions\n\tnumerator = Z25985K2.numerator\n\tdenominator = Z25985K2.denominator\n\tsymmetric = False\n\n\tif ((Z25985K1['K2'] is not None) and (Z25985K1['K3'] is not None)):\n\t\tfrom fractions import Fraction\n\t\tif (Fraction(Z25985K1['K1']['K1'],Z25985K1['K1']['K2'])-Fraction(Z25985K1['K2']['K1'],Z25985K1['K2']['K2']))==(Fraction(Z25985K1['K3']['K1'],Z25985K1['K3']['K2'])-Fraction(Z25985K1['K1']['K1'],Z25985K1['K1']['K2'])):\n\t\t\tsymmetric = True\n\n\tZ25985K1['K1']['K1'] , Z25985K1['K1']['K2'] = multiply_simplify_and_round(Z25985K1['K1']['K1'], Z25985K1['K1']['K2'], numerator, denominator)\n\n\tif Z25985K1['K3'] is not None:\n\t\tZ25985K1['K3']['K1'] , Z25985K1['K3']['K2'] = multiply_simplify_and_round(Z25985K1['K3']['K1'], Z25985K1['K3']['K2'], numerator, denominator)\n\n\tif Z25985K1['K2'] is not None:\n\t\tif symmetric:\n\t\t\tZ25985K1['K2']['K1'] = Z25985K1['K1']['K1']*2 - Z25985K1['K3']['K1']\n\t\t\tZ25985K1['K2']['K2'] = Z25985K1['K1']['K2']\n\t\telse:\n\t\t\tZ25985K1['K2']['K1'] , Z25985K1['K2']['K2'] = multiply_simplify_and_round(Z25985K1['K2']['K1'], Z25985K1['K2']['K2'], numerator, denominator)\n\n\t#negative multipliers need to switch the upper and lower bounds\n\tif (numerator\u003C0):\n\t\tif Z25985K1['K3'] is None:\n\t\t\tif Z25985K1['K2'] is not None:\n\t\t\t\tZ25985K1['K3'] = Z25985K1['K2']\n\t\t\t\tZ25985K1['K2'] = None\n\t\telif Z25985K1['K2'] is None:\n\t\t\tZ25985K1['K2'] = Z25985K1['K3']\n\t\t\tZ25985K1['K3'] = None\n\t\telse:\n\t\t\tZ25985K1['K2']['K1'], Z25985K1['K3']['K1'] = Z25985K1['K3']['K1'], Z25985K1['K2']['K1']\n\t\t\tZ25985K1['K2']['K2'], Z25985K1['K3']['K2'] = Z25985K1['K3']['K2'], Z25985K1['K2']['K2']\n\t\t\n\treturn Z25985K1"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "multiply Wikidata quantity by rational number, py "
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "If the multiplier can be expressed as a decimal, do that first, then multiply all components but maintain significant figures where possible. If components are equally separated, try to preserve this."
            }
        ]
    }
}