How to make software voltage divider?

Any system you use except by switching between separate efficient power supplies at different voltages will involve interposing a resistance of some sort between the power supply and your motor.

1/ below a certain value of voltage your motor won't work at all.

2/ the resistance will itself dissipate power, and so won't save much overall power.

so

don't do it.

unless you interpose eg an efficient voltage controllable buck convertor. and you will have to know the load before you choose the voltage unless you detect motor movement.

This isn't quite trivial. Unless desperate I wouldn't bother.

Electric bikes, buggies etc use a detector of motor position via usually hall effect sensors on their 3-phase motors, to choose the coils to drive, and adjust the power by PWM of their driver waveforms . I'm not sure how you'd achieve this with a standard stepper motor - which doesn't give you feedback of it's position - but it might be possible.

Not trivial.

But for your application a BLDC motor might be a better approach.

Allan