Your goal is to multiply two numbers using only a very limited set of arithmetic operations and variable assignment.
x,y -> x+y
x -> 1/x(not division
x,y -> x/y)
x -> -x(not subtraction
x,y -> x-y, though you can do it as two operations
x + (-y))
- The constant
1(no other constants allowed, except as produced by operations from
- Variable assignment
[variable] = [expression]
Scoring: The values start in variables
b. Your goal is to save their product
a*b into the variable
c using as few operations as possible. Each operation and assignment
+, -, /, = costs a point (equivalently, each use of (1), (2), (3), or (4)). Constants
1 are free. The fewest-point solution wins. Tiebreak is earliest post.
Allowance: Your expression has to be arithmetically correct for "random" reals
b. It can fail on a measure-zero subset of R2, i.e. a set that has no area if plotted in the
b Cartesian plane. (This is likely to be needed due to reciprocals of expressions that might be
This is an atomic-code-golf. No other operations may be used. In particular, this means no functions, conditionals, loops, or non-numerical data types. Here's a grammar for the allowed operations (possibilities are separated by
|). A program is a sequence of
<statement>s, where a
<statement> is given as following.
<statement>: <variable> = <expr> <variable>: a | b | c | [string of letters of your choice] <expr>: <arith_expr> | <variable> | <constant> <arith_expr>: <addition_expr> | <reciprocal_expr> | <negation_expr> <addition_expr>: <expr> + <expr> <reciprocal_expr>: 1/(<expr>) <negation_expr>: -<expr> <constant>: 1
You don't actually have to post code in this exact grammar, as long as it's clear what you're doing and your operation count is right. For example, you can write
a+(-b) and count it as two operations, or define macros for brevity.
(There was a previous question Multiply without Multiply, but it allowed a much looser set of operations.)
I will give a bounty of 300 rep to the first person to post an optimal solution with proof of optimality. The proof must show that no lower-operation solution exists. If the current best 23-operation solution is optimal, a proof of that would suffice and be given the bounty. A brute force search can be a proof if you explain how it checks everything needed.
An optimal result restricted not to use variable assignment will be given 150 rep. Other partial bounties may be given for partial results.
To avoid wasting rep if the bounty isn't collected, I'm announcing it unofficially. If someone meets the criteria, I'll post the bounty and award to them. Redeemable
until Jan 1, 2016 for as long as I'm active.