Data.Number.Erf:$dmerfcx from erf-2.0.0.0

Percentage Accurate: 100.0% → 100.0%
Time: 1.6s
Alternatives: 6
Speedup: 1.0×

Specification

?
\[x \cdot e^{y \cdot y} \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* x (exp (* y y))))
double code(double x, double y) {
	return x * exp((y * y));
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x * exp((y * y))
end function
public static double code(double x, double y) {
	return x * Math.exp((y * y));
}
def code(x, y):
	return x * math.exp((y * y))
function code(x, y)
	return Float64(x * exp(Float64(y * y)))
end
function tmp = code(x, y)
	tmp = x * exp((y * y));
end
code[x_, y_] := N[(x * N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	x * (exp((y * y)))
END code
x \cdot e^{y \cdot y}

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 6 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: 100.0% accurate, 1.0× speedup?

\[x \cdot e^{y \cdot y} \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* x (exp (* y y))))
double code(double x, double y) {
	return x * exp((y * y));
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x * exp((y * y))
end function
public static double code(double x, double y) {
	return x * Math.exp((y * y));
}
def code(x, y):
	return x * math.exp((y * y))
function code(x, y)
	return Float64(x * exp(Float64(y * y)))
end
function tmp = code(x, y)
	tmp = x * exp((y * y));
end
code[x_, y_] := N[(x * N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	x * (exp((y * y)))
END code
x \cdot e^{y \cdot y}

Alternative 1: 100.0% accurate, 0.5× speedup?

\[x \cdot {\left(\sqrt{e^{\left|y\right|}}\right)}^{\left(\left|y\right| + \left|y\right|\right)} \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* x (pow (sqrt (exp (fabs y))) (+ (fabs y) (fabs y)))))
double code(double x, double y) {
	return x * pow(sqrt(exp(fabs(y))), (fabs(y) + fabs(y)));
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x * (sqrt(exp(abs(y))) ** (abs(y) + abs(y)))
end function
public static double code(double x, double y) {
	return x * Math.pow(Math.sqrt(Math.exp(Math.abs(y))), (Math.abs(y) + Math.abs(y)));
}
def code(x, y):
	return x * math.pow(math.sqrt(math.exp(math.fabs(y))), (math.fabs(y) + math.fabs(y)))
function code(x, y)
	return Float64(x * (sqrt(exp(abs(y))) ^ Float64(abs(y) + abs(y))))
end
function tmp = code(x, y)
	tmp = x * (sqrt(exp(abs(y))) ^ (abs(y) + abs(y)));
end
code[x_, y_] := N[(x * N[Power[N[Sqrt[N[Exp[N[Abs[y], $MachinePrecision]], $MachinePrecision]], $MachinePrecision], N[(N[Abs[y], $MachinePrecision] + N[Abs[y], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	x * ((sqrt((exp((abs(y)))))) ^ ((abs(y)) + (abs(y))))
END code
x \cdot {\left(\sqrt{e^{\left|y\right|}}\right)}^{\left(\left|y\right| + \left|y\right|\right)}
Derivation
  1. Initial program 100.0%

    \[x \cdot e^{y \cdot y} \]
  2. Step-by-step derivation
    1. Applied rewrites100.0%

      \[\leadsto x \cdot {\left(e^{y + y}\right)}^{\left(\frac{y}{2}\right)} \]
    2. Step-by-step derivation
      1. Applied rewrites100.0%

        \[\leadsto x \cdot {\left(\sqrt{e^{y}}\right)}^{\left(y + y\right)} \]
      2. Add Preprocessing

      Alternative 2: 100.0% accurate, 0.6× speedup?

      \[x \cdot {\left(e^{y}\right)}^{y} \]
      (FPCore (x y)
        :precision binary64
        :pre TRUE
        (* x (pow (exp y) y)))
      double code(double x, double y) {
      	return x * pow(exp(y), y);
      }
      
      real(8) function code(x, y)
      use fmin_fmax_functions
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          code = x * (exp(y) ** y)
      end function
      
      public static double code(double x, double y) {
      	return x * Math.pow(Math.exp(y), y);
      }
      
      def code(x, y):
      	return x * math.pow(math.exp(y), y)
      
      function code(x, y)
      	return Float64(x * (exp(y) ^ y))
      end
      
      function tmp = code(x, y)
      	tmp = x * (exp(y) ^ y);
      end
      
      code[x_, y_] := N[(x * N[Power[N[Exp[y], $MachinePrecision], y], $MachinePrecision]), $MachinePrecision]
      
      f(x, y):
      	x in [-inf, +inf],
      	y in [-inf, +inf]
      code: THEORY
      BEGIN
      f(x, y: real): real =
      	x * ((exp(y)) ^ y)
      END code
      x \cdot {\left(e^{y}\right)}^{y}
      
      Derivation
      1. Initial program 100.0%

        \[x \cdot e^{y \cdot y} \]
      2. Step-by-step derivation
        1. Applied rewrites100.0%

          \[\leadsto x \cdot {\left(e^{y}\right)}^{y} \]
        2. Add Preprocessing

        Alternative 3: 89.5% accurate, 1.1× speedup?

        \[\mathsf{fma}\left(\sqrt{\left(y \cdot y\right) \cdot \left(y \cdot y\right)}, x, x\right) \]
        (FPCore (x y)
          :precision binary64
          :pre TRUE
          (fma (sqrt (* (* y y) (* y y))) x x))
        double code(double x, double y) {
        	return fma(sqrt(((y * y) * (y * y))), x, x);
        }
        
        function code(x, y)
        	return fma(sqrt(Float64(Float64(y * y) * Float64(y * y))), x, x)
        end
        
        code[x_, y_] := N[(N[Sqrt[N[(N[(y * y), $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * x + x), $MachinePrecision]
        
        f(x, y):
        	x in [-inf, +inf],
        	y in [-inf, +inf]
        code: THEORY
        BEGIN
        f(x, y: real): real =
        	((sqrt(((y * y) * (y * y)))) * x) + x
        END code
        \mathsf{fma}\left(\sqrt{\left(y \cdot y\right) \cdot \left(y \cdot y\right)}, x, x\right)
        
        Derivation
        1. Initial program 100.0%

          \[x \cdot e^{y \cdot y} \]
        2. Taylor expanded in y around 0

          \[\leadsto x + x \cdot {y}^{2} \]
        3. Step-by-step derivation
          1. Applied rewrites81.8%

            \[\leadsto x + x \cdot {y}^{2} \]
          2. Step-by-step derivation
            1. Applied rewrites81.8%

              \[\leadsto \mathsf{fma}\left(y \cdot y, x, x\right) \]
            2. Step-by-step derivation
              1. rem-square-sqrtN/A

                \[\leadsto \mathsf{fma}\left(\sqrt{\left(\sqrt{y \cdot y} \cdot \sqrt{y \cdot y}\right) \cdot \left(\sqrt{y \cdot y} \cdot \sqrt{y \cdot y}\right)}, x, x\right) \]
              2. sqrt-unprodN/A

                \[\leadsto \mathsf{fma}\left(\sqrt{\sqrt{\left(y \cdot y\right) \cdot \left(y \cdot y\right)} \cdot \sqrt{\left(y \cdot y\right) \cdot \left(y \cdot y\right)}}, x, x\right) \]
              3. lift-*.f64N/A

                \[\leadsto \mathsf{fma}\left(\sqrt{\sqrt{\left(y \cdot y\right) \cdot \left(y \cdot y\right)} \cdot \sqrt{\left(y \cdot y\right) \cdot \left(y \cdot y\right)}}, x, x\right) \]
              4. lift-sqrt.f6489.5%

                \[\leadsto \mathsf{fma}\left(\sqrt{\sqrt{\left(y \cdot y\right) \cdot \left(y \cdot y\right)} \cdot \sqrt{\left(y \cdot y\right) \cdot \left(y \cdot y\right)}}, x, x\right) \]
            3. Applied rewrites89.5%

              \[\leadsto \mathsf{fma}\left(\sqrt{\left(y \cdot y\right) \cdot \left(y \cdot y\right)}, x, x\right) \]
            4. Add Preprocessing

            Alternative 4: 81.8% accurate, 2.0× speedup?

            \[\mathsf{fma}\left(y \cdot y, x, x\right) \]
            (FPCore (x y)
              :precision binary64
              :pre TRUE
              (fma (* y y) x x))
            double code(double x, double y) {
            	return fma((y * y), x, x);
            }
            
            function code(x, y)
            	return fma(Float64(y * y), x, x)
            end
            
            code[x_, y_] := N[(N[(y * y), $MachinePrecision] * x + x), $MachinePrecision]
            
            f(x, y):
            	x in [-inf, +inf],
            	y in [-inf, +inf]
            code: THEORY
            BEGIN
            f(x, y: real): real =
            	((y * y) * x) + x
            END code
            \mathsf{fma}\left(y \cdot y, x, x\right)
            
            Derivation
            1. Initial program 100.0%

              \[x \cdot e^{y \cdot y} \]
            2. Taylor expanded in y around 0

              \[\leadsto x + x \cdot {y}^{2} \]
            3. Step-by-step derivation
              1. Applied rewrites81.8%

                \[\leadsto x + x \cdot {y}^{2} \]
              2. Step-by-step derivation
                1. Applied rewrites81.8%

                  \[\leadsto \mathsf{fma}\left(y \cdot y, x, x\right) \]
                2. Add Preprocessing

                Alternative 5: 51.3% accurate, 4.5× speedup?

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

                  \[x \cdot e^{y \cdot y} \]
                2. Taylor expanded in y around 0

                  \[\leadsto x \cdot 1 \]
                3. Step-by-step derivation
                  1. Applied rewrites51.3%

                    \[\leadsto x \cdot 1 \]
                  2. Add Preprocessing

                  Reproduce

                  ?
                  herbie shell --seed 2026092 
                  (FPCore (x y)
                    :name "Data.Number.Erf:$dmerfcx from erf-2.0.0.0"
                    :precision binary64
                    (* x (exp (* y y))))