Exp of sum of logs

Percentage Accurate: 92.2% → 100.0%
Time: 1.4s
Alternatives: 1
Speedup: 6.7×

Specification

?
\[e^{\log a + \log b} \]
(FPCore (a b)
  :precision binary64
  :pre TRUE
  (exp (+ (log a) (log b))))
double code(double a, double b) {
	return exp((log(a) + log(b)));
}
real(8) function code(a, b)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = exp((log(a) + log(b)))
end function
public static double code(double a, double b) {
	return Math.exp((Math.log(a) + Math.log(b)));
}
def code(a, b):
	return math.exp((math.log(a) + math.log(b)))
function code(a, b)
	return exp(Float64(log(a) + log(b)))
end
function tmp = code(a, b)
	tmp = exp((log(a) + log(b)));
end
code[a_, b_] := N[Exp[N[(N[Log[a], $MachinePrecision] + N[Log[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
f(a, b):
	a in [-inf, +inf],
	b in [-inf, +inf]
code: THEORY
BEGIN
f(a, b: real): real =
	exp(((ln(a)) + (ln(b))))
END code
e^{\log a + \log b}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 1 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 92.2% accurate, 1.0× speedup?

\[e^{\log a + \log b} \]
(FPCore (a b)
  :precision binary64
  :pre TRUE
  (exp (+ (log a) (log b))))
double code(double a, double b) {
	return exp((log(a) + log(b)));
}
real(8) function code(a, b)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = exp((log(a) + log(b)))
end function
public static double code(double a, double b) {
	return Math.exp((Math.log(a) + Math.log(b)));
}
def code(a, b):
	return math.exp((math.log(a) + math.log(b)))
function code(a, b)
	return exp(Float64(log(a) + log(b)))
end
function tmp = code(a, b)
	tmp = exp((log(a) + log(b)));
end
code[a_, b_] := N[Exp[N[(N[Log[a], $MachinePrecision] + N[Log[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
f(a, b):
	a in [-inf, +inf],
	b in [-inf, +inf]
code: THEORY
BEGIN
f(a, b: real): real =
	exp(((ln(a)) + (ln(b))))
END code
e^{\log a + \log b}

Alternative 1: 100.0% accurate, 6.7× speedup?

\[b \cdot a \]
(FPCore (a b)
  :precision binary64
  :pre TRUE
  (* b a))
double code(double a, double b) {
	return b * a;
}
real(8) function code(a, b)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = b * a
end function
public static double code(double a, double b) {
	return b * a;
}
def code(a, b):
	return b * a
function code(a, b)
	return Float64(b * a)
end
function tmp = code(a, b)
	tmp = b * a;
end
code[a_, b_] := N[(b * a), $MachinePrecision]
f(a, b):
	a in [-inf, +inf],
	b in [-inf, +inf]
code: THEORY
BEGIN
f(a, b: real): real =
	b * a
END code
b \cdot a
Derivation
  1. Initial program 92.2%

    \[e^{\log a + \log b} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \color{blue}{e^{\log a + \log b}} \]
    2. lift-+.f64N/A

      \[\leadsto e^{\color{blue}{\log a + \log b}} \]
    3. lift-log.f64N/A

      \[\leadsto e^{\color{blue}{\log a} + \log b} \]
    4. lift-log.f64N/A

      \[\leadsto e^{\log a + \color{blue}{\log b}} \]
    5. sum-logN/A

      \[\leadsto e^{\color{blue}{\log \left(a \cdot b\right)}} \]
    6. rem-exp-logN/A

      \[\leadsto \color{blue}{a \cdot b} \]
    7. *-commutativeN/A

      \[\leadsto \color{blue}{b \cdot a} \]
    8. lower-*.f64100.0%

      \[\leadsto \color{blue}{b \cdot a} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{b \cdot a} \]
  4. Add Preprocessing

Developer Target 1: 100.0% accurate, 6.7× speedup?

\[a \cdot b \]
(FPCore (a b)
  :precision binary64
  :pre TRUE
  (* a b))
double code(double a, double b) {
	return a * b;
}
real(8) function code(a, b)
use fmin_fmax_functions
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = a * b
end function
public static double code(double a, double b) {
	return a * b;
}
def code(a, b):
	return a * b
function code(a, b)
	return Float64(a * b)
end
function tmp = code(a, b)
	tmp = a * b;
end
code[a_, b_] := N[(a * b), $MachinePrecision]
f(a, b):
	a in [-inf, +inf],
	b in [-inf, +inf]
code: THEORY
BEGIN
f(a, b: real): real =
	a * b
END code
a \cdot b

Reproduce

?
herbie shell --seed 2025355 
(FPCore (a b)
  :name "Exp of sum of logs"
  :precision binary64

  :alt
  (! :herbie-platform c (* a b))

  (exp (+ (log a) (log b))))