#Rewriting a logarithm (log_b[x]) so it's just written arithmetically

159 messages · Page 1 of 1 (latest)

lapis anvil
#

Hi everyone, I've posted a few times in here before.

I'm coding in a very limited language in a Minecraft server, specifically Hypixel Housing, called HTSL, and I'm trying to simulate a Logarithm with only lines of arithmetic calculations.
For example:

test = 1000
test /= 10
test *= 10

So I can only do these types of calculations and no if/else statements or for loops or special recursive functions. With that in mind, I'm trying to find the closest graph that can be done with pure arithmetic math (respectively written as a mathematical formula) to match the actual logarithm function but I'm still very far (starting to think it's impossible).

You can use doubles and integers, as well as floor division and absolute value for this, but that's about it.
No for loops, no math.X functions, no if/else statements, no new functions, just pure, arithmetic code.

Anyone know how to do this? The closest I got to using grok ai is this formula in code skulptor, but it's still very far from the actual logarithm formula.
https://py3.codeskulptor.org/#user310_lWdBgHWwTi_0.py

Someone help me pls!
As title suggests, I'll PayPal you $10 if you help me find the best solution.

inner iglooBOT
lapis anvil
#

($10 BOUNTY) Rewriting a logarithm (log_b[x]) so it's just written arithmetically

#

If you guys have any questions about the constraints pls dm me, I'll write what's allowed based on what Housing allows me lol

mellow pelican
storm geyser
#

,w maclauren expansion ln(x)

storm geyser
#

$$\ln(x) = -\sum_{n = 1}^\infty \frac{(1 - x)^n}{n} \quad \forall x \in (0, 1)$$

snow ibexBOT
#

@storm geyser

storm geyser
storm geyser
snow ibexBOT
#

@storm geyser

storm geyser
#

Do not offer money for doing homework assignments, and vice versa.

red lintel
#

this doesn't seem like homework

mellow pelican
red lintel
#

yeah

#

but

#

if you can store log(10) in some variable

#

and then write the number x as a * 10^n, then you can find the log by doing log(a) + nlog(10)

#

The challenge comes in finding a and n

mellow pelican
#

Yeah I am thinking you would need loops to do that

red lintel
#

In numerical analysis, the Newton–Cotes formulas, also called the Newton–Cotes quadrature rules or simply Newton–Cotes rules, are a group of formulas for numerical integration (also called quadrature) based on evaluating the integrand at equally spaced points. They are named after Isaac Newton and Roger Cotes.
Newton–Cotes formulas can...

#

might be worth looking at

#

It is kinda accurate

#

and if you find a way to get a and n, you might be able to find all values very easily

#

If we can bound all the inputs below some number N

#

this can become much easier

lapis anvil
#

hey guys, didnt expect to get a response

lapis anvil
#

I'll only be passing 2 values, the b in log(b)_x and the x

#

both values need to be greater than 0

#

and less than the integer overflow limit which is like 2^32-1

lapis anvil
#

By the way for housing, if statements ARE allowed but for reference I'm trying to fit everything within a single "conditional" which in Housing terms, is a bag with a redstone icon that can carry a max of 25 actions (which in this case, are the arithmetic calculations)

#

This person made Exponentation in Housing using only arithmetic calculations and floor division, with the exception of if statements

#

If statements aren't allowed in this case, and I heard logarithms are much harder to be written arithmetically than exponentation, just something to think about

mellow pelican
#

@lapis anvil we need to know the domain though still

lapis anvil
#

how do I find the domain?

mellow pelican
#

Just what range of values for input do you expect

lapis anvil
#

ahhh ok

#

here i think i had it saved

#

// precise, range: log_b ∈ ℤ, log_b > 0, log_x ∈ ℤ, log_x > 0
// given "b" and "x", return its nearest integer of log_b(x)

#

ngl this is probably wrong, this was before I later realized u cant have zero or like 1 in one of the inputs

#

basically just what the typical range is for when inputting whole numbers in a logarithm, anything thats greater than 0 or 1 i forgot

#

sorry i dont really know lol

mellow pelican
#

So basically any number greater than 0 and less than the maximum possible double?

red lintel
#

@lapis anvil can you tell me the list of operations you can do

#

are you able to get the under lying bits of a number

#

then you can do IEE quake pro shenagins to get the log

#

is it JUST arithematic

#

and floor division?

fresh agate
#

Just do e^x and switch the x,y coordinates

lapis anvil
#

hey guys appreciate the responses

storm geyser
lapis anvil
#

no if/else statements, no for loops/while loops, no domain range etc, no special functions, no classes

storm geyser
lapis anvil
#

hmm could that work?

#

im not familiar with the taylor polynomial

#

but ill see

storm geyser
# lapis anvil no if/else statements, no for loops/while loops, no domain range etc, no special...
    chat {"This message has been sent " + (index + 1) + " time(s)!"}
}```Source: https://hypixel.net/threads/updated-guide-htsl.5555038/
lapis anvil
#

nono

storm geyser
lapis anvil
#

it will just carry the print message 10 times rather than it being a for loop i think

storm geyser
#
def lnTaylorSeries(x: float, n: int) -> float:
    approximation: float = 1.0
    for _ in range(n):
        approximation *= (1 - x)
    approximation /= n
    return -approximation

def sum(accuracy: int, x: float) -> float:
    sum: float = 0.0
    n: int = 1
    for _ in range(accuracy):
        sum += lnTaylorSeries(x, n)
        n += 1
    return sum

approximation: float = sum(100, 1.5)
print(approximation)```I was hoping something like this would work.
lapis anvil
#

unfortunately housing doesnt have a built in for loop which sucks so it cant be possible

lapis anvil
#

nope i wish that worked

#

lambda expression looks cool but idk how that would be written arithmetically

storm geyser
lapis anvil
#

is the -> lambda?

#

i was taught for java it is that symbol

storm geyser
lapis anvil
#

ohhhh ok

#

mb

storm geyser
#
def function(arguments) -> dataType:``````java
public static dataType function (arguments)```Here's a "translation" of sorts to understand it.
mellow pelican
#

What does this mean

This does not ACTUALLY loop your actions, it will simply duplicate them.

#

Are they trying to say it doesnt loop forever?

#

Very next example they give is
loop 10 index {
chat {"This message has been sent " + (index + 1) + " time(s)!"}
}

So you can index the loop

storm geyser
#

@lapis anvil
Can you give me your Minecraft name? I'd like to see your House and potentially find a better method than logarithms.

slim rock
storm geyser
#

Is it possible for me to remove the <@&830347221085061141> role?

slim rock
#

If you set a variable in the loop, it will set it 10 times, but it won't update it 10 times, it just does the first step 10 times.

slim rock
storm geyser
slim rock
#

For instance, if you did

out = 0
loop 10 index {
  out += index
}

You would expect to get out set to 55, but I believe it would set it to 10

#

All of the other changes occur independently and are thrown away.

red lintel
#

I have an idea

#

$\operatorname{floor}\left(\frac{\left(n-10^{1+m}\operatorname{floor}\left(\frac{n}{10^{1+m}}\right)\right)}{10^{\left(m\right)}}\right)$

snow ibexBOT
#

TimesZeroed

red lintel
#

this formula allows you to get the mth digit of the number n

#

now it does use the powers 10^m

#

but if you only wanted the first digit, then you could just plug in 0

storm geyser
red lintel
#

yeah but you don't need to

#

for simplicity

#

let us just say the maximum number we would need to take the log of is

#

100000

red lintel
#

and get all those digits

#

we could then do

#

y = (10^-1) digit 1 + (10^-2) digit 2...

#

again, we will hard code 10^-stuff so we don't have to do any exponents

#

lastly we use some log approximation of log between 0 to 1, such as one from simpsons rule

#

to get something very accurate

red lintel
#

and log(10) can just become a magic constnat

slim rock
#

@lapis anvil may I request that you retract your bounty offer please?

red lintel
#

not the money 😭

lapis anvil
#

hey im back sorry

red lintel
#

alternatively, you can use the pade aproximation

lapis anvil
red lintel
red lintel
red lintel
#

exponents don't need to be coded as you can just do

#

multiplication

lapis anvil
#

woahhh this is really cool

#

wait

#

but im taking 2 inputs though

#

did i mess u up? lmao

red lintel
#

what

red lintel
#

b and x?

lapis anvil
#

sorry im taking a shower rn half teaponding

lapis anvil
red lintel
#

so whatever formula i have

#

divided by log ( whatever base you want)

#

I have another idea

#

if you can get a log formula to work really accurately between 0 and 1

#

you can do -log(1/x) for x>1

lapis anvil
#

duuude i dont know

#

check dms

lapis anvil
twilit swift
#

Rewriting a logarithm (log_b[x]) so it's just written arithmetically

red lintel
#

I read through the rules and it seems like it only applies to hw and assignments

storm geyser
red lintel
#

that makes sense

slim rock
# red lintel I read through the rules and it seems like it only applies to hw and assignments

It does specifically call out hw and assignments, but it was not intended to be limited to just hw and assignments. Facilitating the transfer of money opens the server up to a lot of potential liability and so on, and imo it would probably be bad to have help threads that promise monetary bounties because they would attract a bunch of (potentially low quality) contributors looking to make a quick buck, and so on.

red lintel
#

oh ok, I think it should be stated in the rules then

slim rock
#

The rules aren't intended to be a complete enumeration of every single thing that you can possibly do wrong

#

Besides, the only action taken was asking politely that the title of the thread be changed, and then when ignored twice, a senior mod just changing the title.

red lintel
#

alright

red lintel
#

nah it's fine