Data.Number.Erf:$cinvnormcdf from erf-2.0.0.0, A

Percentage Accurate: 99.4% → 99.8%
Time: 9.9s
Alternatives: 4
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))
double code(double x, double y, double z, double t) {
	return (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (((x * 0.5d0) - y) * sqrt((z * 2.0d0))) * exp(((t * t) / 2.0d0))
end function
public static double code(double x, double y, double z, double t) {
	return (((x * 0.5) - y) * Math.sqrt((z * 2.0))) * Math.exp(((t * t) / 2.0));
}
def code(x, y, z, t):
	return (((x * 0.5) - y) * math.sqrt((z * 2.0))) * math.exp(((t * t) / 2.0))
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))) * exp(Float64(Float64(t * t) / 2.0)))
end
function tmp = code(x, y, z, t)
	tmp = (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0));
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}}
\end{array}

Sampling outcomes in binary64 precision:

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

\[\begin{array}{l} \\ \left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))
double code(double x, double y, double z, double t) {
	return (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (((x * 0.5d0) - y) * sqrt((z * 2.0d0))) * exp(((t * t) / 2.0d0))
end function
public static double code(double x, double y, double z, double t) {
	return (((x * 0.5) - y) * Math.sqrt((z * 2.0))) * Math.exp(((t * t) / 2.0));
}
def code(x, y, z, t):
	return (((x * 0.5) - y) * math.sqrt((z * 2.0))) * math.exp(((t * t) / 2.0))
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))) * exp(Float64(Float64(t * t) / 2.0)))
end
function tmp = code(x, y, z, t)
	tmp = (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0));
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}}
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z \cdot e^{t \cdot t}\right)} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (* (- (* x 0.5) y) (sqrt (* 2.0 (* z (exp (* t t)))))))
double code(double x, double y, double z, double t) {
	return ((x * 0.5) - y) * sqrt((2.0 * (z * exp((t * t)))));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = ((x * 0.5d0) - y) * sqrt((2.0d0 * (z * exp((t * t)))))
end function
public static double code(double x, double y, double z, double t) {
	return ((x * 0.5) - y) * Math.sqrt((2.0 * (z * Math.exp((t * t)))));
}
def code(x, y, z, t):
	return ((x * 0.5) - y) * math.sqrt((2.0 * (z * math.exp((t * t)))))
function code(x, y, z, t)
	return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * Float64(z * exp(Float64(t * t))))))
end
function tmp = code(x, y, z, t)
	tmp = ((x * 0.5) - y) * sqrt((2.0 * (z * exp((t * t)))));
end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * N[(z * N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z \cdot e^{t \cdot t}\right)}
\end{array}
Derivation
  1. Initial program 99.0%

    \[\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}} \]
  2. Step-by-step derivation
    1. associate-*l*99.8%

      \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot e^{\frac{t \cdot t}{2}}\right)} \]
    2. exp-sqrt99.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \color{blue}{\sqrt{e^{t \cdot t}}}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)} \]
  4. Step-by-step derivation
    1. expm1-log1p-u98.6%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)\right)} \]
    2. expm1-udef76.5%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)} - 1\right)} \]
    3. sqrt-unprod76.5%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\left(z \cdot 2\right) \cdot e^{t \cdot t}}}\right)} - 1\right) \]
    4. associate-*l*76.5%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{z \cdot \left(2 \cdot e^{t \cdot t}\right)}}\right)} - 1\right) \]
    5. exp-prod76.5%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\sqrt{z \cdot \left(2 \cdot \color{blue}{{\left(e^{t}\right)}^{t}}\right)}\right)} - 1\right) \]
  5. Applied egg-rr76.5%

    \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{z \cdot \left(2 \cdot {\left(e^{t}\right)}^{t}\right)}\right)} - 1\right)} \]
  6. Step-by-step derivation
    1. expm1-def98.6%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{z \cdot \left(2 \cdot {\left(e^{t}\right)}^{t}\right)}\right)\right)} \]
    2. expm1-log1p99.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{z \cdot \left(2 \cdot {\left(e^{t}\right)}^{t}\right)}} \]
    3. *-commutative99.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \sqrt{\color{blue}{\left(2 \cdot {\left(e^{t}\right)}^{t}\right) \cdot z}} \]
    4. associate-*l*99.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \sqrt{\color{blue}{2 \cdot \left({\left(e^{t}\right)}^{t} \cdot z\right)}} \]
    5. *-commutative99.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \color{blue}{\left(z \cdot {\left(e^{t}\right)}^{t}\right)}} \]
    6. exp-prod99.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z \cdot \color{blue}{e^{t \cdot t}}\right)} \]
  7. Simplified99.8%

    \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{2 \cdot \left(z \cdot e^{t \cdot t}\right)}} \]
  8. Final simplification99.8%

    \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z \cdot e^{t \cdot t}\right)} \]

Alternative 2: 59.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot 0.5 - y\\ \mathbf{if}\;t \leq 33 \lor \neg \left(t \leq 1.05 \cdot 10^{+233}\right) \land t \leq 1.32 \cdot 10^{+250}:\\ \;\;\;\;t_1 \cdot \sqrt{2 \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(2 \cdot z\right) \cdot {t_1}^{2}}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- (* x 0.5) y)))
   (if (or (<= t 33.0) (and (not (<= t 1.05e+233)) (<= t 1.32e+250)))
     (* t_1 (sqrt (* 2.0 z)))
     (sqrt (* (* 2.0 z) (pow t_1 2.0))))))
double code(double x, double y, double z, double t) {
	double t_1 = (x * 0.5) - y;
	double tmp;
	if ((t <= 33.0) || (!(t <= 1.05e+233) && (t <= 1.32e+250))) {
		tmp = t_1 * sqrt((2.0 * z));
	} else {
		tmp = sqrt(((2.0 * z) * pow(t_1, 2.0)));
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (x * 0.5d0) - y
    if ((t <= 33.0d0) .or. (.not. (t <= 1.05d+233)) .and. (t <= 1.32d+250)) then
        tmp = t_1 * sqrt((2.0d0 * z))
    else
        tmp = sqrt(((2.0d0 * z) * (t_1 ** 2.0d0)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = (x * 0.5) - y;
	double tmp;
	if ((t <= 33.0) || (!(t <= 1.05e+233) && (t <= 1.32e+250))) {
		tmp = t_1 * Math.sqrt((2.0 * z));
	} else {
		tmp = Math.sqrt(((2.0 * z) * Math.pow(t_1, 2.0)));
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = (x * 0.5) - y
	tmp = 0
	if (t <= 33.0) or (not (t <= 1.05e+233) and (t <= 1.32e+250)):
		tmp = t_1 * math.sqrt((2.0 * z))
	else:
		tmp = math.sqrt(((2.0 * z) * math.pow(t_1, 2.0)))
	return tmp
function code(x, y, z, t)
	t_1 = Float64(Float64(x * 0.5) - y)
	tmp = 0.0
	if ((t <= 33.0) || (!(t <= 1.05e+233) && (t <= 1.32e+250)))
		tmp = Float64(t_1 * sqrt(Float64(2.0 * z)));
	else
		tmp = sqrt(Float64(Float64(2.0 * z) * (t_1 ^ 2.0)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = (x * 0.5) - y;
	tmp = 0.0;
	if ((t <= 33.0) || (~((t <= 1.05e+233)) && (t <= 1.32e+250)))
		tmp = t_1 * sqrt((2.0 * z));
	else
		tmp = sqrt(((2.0 * z) * (t_1 ^ 2.0)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision]}, If[Or[LessEqual[t, 33.0], And[N[Not[LessEqual[t, 1.05e+233]], $MachinePrecision], LessEqual[t, 1.32e+250]]], N[(t$95$1 * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[(2.0 * z), $MachinePrecision] * N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := x \cdot 0.5 - y\\
\mathbf{if}\;t \leq 33 \lor \neg \left(t \leq 1.05 \cdot 10^{+233}\right) \land t \leq 1.32 \cdot 10^{+250}:\\
\;\;\;\;t_1 \cdot \sqrt{2 \cdot z}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\left(2 \cdot z\right) \cdot {t_1}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < 33 or 1.04999999999999998e233 < t < 1.32000000000000005e250

    1. Initial program 99.8%

      \[\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}} \]
    2. Step-by-step derivation
      1. associate-*l*99.7%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot e^{\frac{t \cdot t}{2}}\right)} \]
      2. exp-sqrt99.7%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \color{blue}{\sqrt{e^{t \cdot t}}}\right) \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)} \]
    4. Taylor expanded in t around 0 69.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{z}\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u68.4%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{z}\right)\right)} \]
      2. expm1-udef39.6%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{z}\right)} - 1\right)} \]
      3. sqrt-unprod39.6%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2 \cdot z}}\right)} - 1\right) \]
    6. Applied egg-rr39.6%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{2 \cdot z}\right)} - 1\right)} \]
    7. Step-by-step derivation
      1. expm1-def68.4%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2 \cdot z}\right)\right)} \]
      2. expm1-log1p70.0%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{2 \cdot z}} \]
    8. Simplified70.0%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{2 \cdot z}} \]

    if 33 < t < 1.04999999999999998e233 or 1.32000000000000005e250 < t

    1. Initial program 96.6%

      \[\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}} \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot e^{\frac{t \cdot t}{2}}\right)} \]
      2. exp-sqrt100.0%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \color{blue}{\sqrt{e^{t \cdot t}}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)} \]
    4. Taylor expanded in t around 0 16.1%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{z}\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u16.1%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{z}\right)\right)} \]
      2. expm1-udef14.9%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{z}\right)} - 1\right)} \]
      3. sqrt-unprod14.9%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2 \cdot z}}\right)} - 1\right) \]
    6. Applied egg-rr14.9%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{2 \cdot z}\right)} - 1\right)} \]
    7. Step-by-step derivation
      1. expm1-def16.1%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2 \cdot z}\right)\right)} \]
      2. expm1-log1p16.1%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{2 \cdot z}} \]
    8. Simplified16.1%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{2 \cdot z}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt8.7%

        \[\leadsto \color{blue}{\sqrt{\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}} \cdot \sqrt{\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}}} \]
      2. sqrt-unprod20.1%

        \[\leadsto \color{blue}{\sqrt{\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}\right) \cdot \left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}\right)}} \]
      3. *-commutative20.1%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot z} \cdot \left(x \cdot 0.5 - y\right)\right)} \cdot \left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}\right)} \]
      4. *-commutative20.1%

        \[\leadsto \sqrt{\left(\sqrt{2 \cdot z} \cdot \left(x \cdot 0.5 - y\right)\right) \cdot \color{blue}{\left(\sqrt{2 \cdot z} \cdot \left(x \cdot 0.5 - y\right)\right)}} \]
      5. swap-sqr25.0%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{2 \cdot z} \cdot \sqrt{2 \cdot z}\right) \cdot \left(\left(x \cdot 0.5 - y\right) \cdot \left(x \cdot 0.5 - y\right)\right)}} \]
      6. add-sqr-sqrt25.0%

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot z\right)} \cdot \left(\left(x \cdot 0.5 - y\right) \cdot \left(x \cdot 0.5 - y\right)\right)} \]
      7. pow225.0%

        \[\leadsto \sqrt{\left(2 \cdot z\right) \cdot \color{blue}{{\left(x \cdot 0.5 - y\right)}^{2}}} \]
    10. Applied egg-rr25.0%

      \[\leadsto \color{blue}{\sqrt{\left(2 \cdot z\right) \cdot {\left(x \cdot 0.5 - y\right)}^{2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification59.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq 33 \lor \neg \left(t \leq 1.05 \cdot 10^{+233}\right) \land t \leq 1.32 \cdot 10^{+250}:\\ \;\;\;\;\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(2 \cdot z\right) \cdot {\left(x \cdot 0.5 - y\right)}^{2}}\\ \end{array} \]

Alternative 3: 66.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;t \cdot t \leq 2.5:\\ \;\;\;\;\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{e^{t \cdot t} \cdot \left(2 \cdot \left(z \cdot \left(y \cdot y\right)\right)\right)}\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= (* t t) 2.5)
   (* (- (* x 0.5) y) (sqrt (* 2.0 z)))
   (sqrt (* (exp (* t t)) (* 2.0 (* z (* y y)))))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((t * t) <= 2.5) {
		tmp = ((x * 0.5) - y) * sqrt((2.0 * z));
	} else {
		tmp = sqrt((exp((t * t)) * (2.0 * (z * (y * y)))));
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((t * t) <= 2.5d0) then
        tmp = ((x * 0.5d0) - y) * sqrt((2.0d0 * z))
    else
        tmp = sqrt((exp((t * t)) * (2.0d0 * (z * (y * y)))))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((t * t) <= 2.5) {
		tmp = ((x * 0.5) - y) * Math.sqrt((2.0 * z));
	} else {
		tmp = Math.sqrt((Math.exp((t * t)) * (2.0 * (z * (y * y)))));
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (t * t) <= 2.5:
		tmp = ((x * 0.5) - y) * math.sqrt((2.0 * z))
	else:
		tmp = math.sqrt((math.exp((t * t)) * (2.0 * (z * (y * y)))))
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(t * t) <= 2.5)
		tmp = Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * z)));
	else
		tmp = sqrt(Float64(exp(Float64(t * t)) * Float64(2.0 * Float64(z * Float64(y * y)))));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((t * t) <= 2.5)
		tmp = ((x * 0.5) - y) * sqrt((2.0 * z));
	else
		tmp = sqrt((exp((t * t)) * (2.0 * (z * (y * y)))));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[N[(t * t), $MachinePrecision], 2.5], N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision] * N[(2.0 * N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;t \cdot t \leq 2.5:\\
\;\;\;\;\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{e^{t \cdot t} \cdot \left(2 \cdot \left(z \cdot \left(y \cdot y\right)\right)\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 t t) < 2.5

    1. Initial program 99.6%

      \[\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}} \]
    2. Step-by-step derivation
      1. associate-*l*99.6%

        \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot e^{\frac{t \cdot t}{2}}\right)} \]
      2. exp-sqrt99.6%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \color{blue}{\sqrt{e^{t \cdot t}}}\right) \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)} \]
    4. Taylor expanded in t around 0 98.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{z}\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u96.5%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{z}\right)\right)} \]
      2. expm1-udef52.5%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{z}\right)} - 1\right)} \]
      3. sqrt-unprod52.5%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2 \cdot z}}\right)} - 1\right) \]
    6. Applied egg-rr52.5%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{2 \cdot z}\right)} - 1\right)} \]
    7. Step-by-step derivation
      1. expm1-def96.6%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2 \cdot z}\right)\right)} \]
      2. expm1-log1p99.1%

        \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{2 \cdot z}} \]
    8. Simplified99.1%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{2 \cdot z}} \]

    if 2.5 < (*.f64 t t)

    1. Initial program 98.4%

      \[\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}} \]
    2. Step-by-step derivation
      1. add-sqr-sqrt50.0%

        \[\leadsto \color{blue}{\left(\sqrt{\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}} \cdot \sqrt{\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}}\right)} \cdot e^{\frac{t \cdot t}{2}} \]
      2. sqrt-unprod45.3%

        \[\leadsto \color{blue}{\sqrt{\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot \left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right)}} \cdot e^{\frac{t \cdot t}{2}} \]
      3. *-commutative45.3%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{z \cdot 2} \cdot \left(x \cdot 0.5 - y\right)\right)} \cdot \left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right)} \cdot e^{\frac{t \cdot t}{2}} \]
      4. *-commutative45.3%

        \[\leadsto \sqrt{\left(\sqrt{z \cdot 2} \cdot \left(x \cdot 0.5 - y\right)\right) \cdot \color{blue}{\left(\sqrt{z \cdot 2} \cdot \left(x \cdot 0.5 - y\right)\right)}} \cdot e^{\frac{t \cdot t}{2}} \]
      5. swap-sqr45.3%

        \[\leadsto \sqrt{\color{blue}{\left(\sqrt{z \cdot 2} \cdot \sqrt{z \cdot 2}\right) \cdot \left(\left(x \cdot 0.5 - y\right) \cdot \left(x \cdot 0.5 - y\right)\right)}} \cdot e^{\frac{t \cdot t}{2}} \]
      6. add-sqr-sqrt45.3%

        \[\leadsto \sqrt{\color{blue}{\left(z \cdot 2\right)} \cdot \left(\left(x \cdot 0.5 - y\right) \cdot \left(x \cdot 0.5 - y\right)\right)} \cdot e^{\frac{t \cdot t}{2}} \]
      7. pow245.3%

        \[\leadsto \sqrt{\left(z \cdot 2\right) \cdot \color{blue}{{\left(x \cdot 0.5 - y\right)}^{2}}} \cdot e^{\frac{t \cdot t}{2}} \]
    3. Applied egg-rr45.3%

      \[\leadsto \color{blue}{\sqrt{\left(z \cdot 2\right) \cdot {\left(x \cdot 0.5 - y\right)}^{2}}} \cdot e^{\frac{t \cdot t}{2}} \]
    4. Taylor expanded in x around 0 36.7%

      \[\leadsto \sqrt{\color{blue}{2 \cdot \left({y}^{2} \cdot z\right)}} \cdot e^{\frac{t \cdot t}{2}} \]
    5. Step-by-step derivation
      1. associate-*r*36.7%

        \[\leadsto \sqrt{\color{blue}{\left(2 \cdot {y}^{2}\right) \cdot z}} \cdot e^{\frac{t \cdot t}{2}} \]
      2. unpow236.7%

        \[\leadsto \sqrt{\left(2 \cdot \color{blue}{\left(y \cdot y\right)}\right) \cdot z} \cdot e^{\frac{t \cdot t}{2}} \]
    6. Simplified36.7%

      \[\leadsto \sqrt{\color{blue}{\left(2 \cdot \left(y \cdot y\right)\right) \cdot z}} \cdot e^{\frac{t \cdot t}{2}} \]
    7. Step-by-step derivation
      1. *-commutative36.7%

        \[\leadsto \color{blue}{e^{\frac{t \cdot t}{2}} \cdot \sqrt{\left(2 \cdot \left(y \cdot y\right)\right) \cdot z}} \]
      2. exp-sqrt36.7%

        \[\leadsto \color{blue}{\sqrt{e^{t \cdot t}}} \cdot \sqrt{\left(2 \cdot \left(y \cdot y\right)\right) \cdot z} \]
      3. pow-exp36.7%

        \[\leadsto \sqrt{\color{blue}{{\left(e^{t}\right)}^{t}}} \cdot \sqrt{\left(2 \cdot \left(y \cdot y\right)\right) \cdot z} \]
      4. sqrt-unprod36.7%

        \[\leadsto \color{blue}{\sqrt{{\left(e^{t}\right)}^{t} \cdot \left(\left(2 \cdot \left(y \cdot y\right)\right) \cdot z\right)}} \]
      5. pow-exp36.7%

        \[\leadsto \sqrt{\color{blue}{e^{t \cdot t}} \cdot \left(\left(2 \cdot \left(y \cdot y\right)\right) \cdot z\right)} \]
      6. associate-*l*36.7%

        \[\leadsto \sqrt{e^{t \cdot t} \cdot \color{blue}{\left(2 \cdot \left(\left(y \cdot y\right) \cdot z\right)\right)}} \]
    8. Applied egg-rr36.7%

      \[\leadsto \color{blue}{\sqrt{e^{t \cdot t} \cdot \left(2 \cdot \left(\left(y \cdot y\right) \cdot z\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification67.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \cdot t \leq 2.5:\\ \;\;\;\;\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{e^{t \cdot t} \cdot \left(2 \cdot \left(z \cdot \left(y \cdot y\right)\right)\right)}\\ \end{array} \]

Alternative 4: 57.2% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z} \end{array} \]
(FPCore (x y z t) :precision binary64 (* (- (* x 0.5) y) (sqrt (* 2.0 z))))
double code(double x, double y, double z, double t) {
	return ((x * 0.5) - y) * sqrt((2.0 * z));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = ((x * 0.5d0) - y) * sqrt((2.0d0 * z))
end function
public static double code(double x, double y, double z, double t) {
	return ((x * 0.5) - y) * Math.sqrt((2.0 * z));
}
def code(x, y, z, t):
	return ((x * 0.5) - y) * math.sqrt((2.0 * z))
function code(x, y, z, t)
	return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * z)))
end
function tmp = code(x, y, z, t)
	tmp = ((x * 0.5) - y) * sqrt((2.0 * z));
end
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z}
\end{array}
Derivation
  1. Initial program 99.0%

    \[\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}} \]
  2. Step-by-step derivation
    1. associate-*l*99.8%

      \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot e^{\frac{t \cdot t}{2}}\right)} \]
    2. exp-sqrt99.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \color{blue}{\sqrt{e^{t \cdot t}}}\right) \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)} \]
  4. Taylor expanded in t around 0 57.7%

    \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(\sqrt{2} \cdot \sqrt{z}\right)} \]
  5. Step-by-step derivation
    1. expm1-log1p-u56.5%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{z}\right)\right)} \]
    2. expm1-udef34.0%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{2} \cdot \sqrt{z}\right)} - 1\right)} \]
    3. sqrt-unprod34.0%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{2 \cdot z}}\right)} - 1\right) \]
  6. Applied egg-rr34.0%

    \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{2 \cdot z}\right)} - 1\right)} \]
  7. Step-by-step derivation
    1. expm1-def56.6%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{2 \cdot z}\right)\right)} \]
    2. expm1-log1p57.8%

      \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{2 \cdot z}} \]
  8. Simplified57.8%

    \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{2 \cdot z}} \]
  9. Final simplification57.8%

    \[\leadsto \left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot z} \]

Developer target: 99.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot {\left(e^{1}\right)}^{\left(\frac{t \cdot t}{2}\right)} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (pow (exp 1.0) (/ (* t t) 2.0))))
double code(double x, double y, double z, double t) {
	return (((x * 0.5) - y) * sqrt((z * 2.0))) * pow(exp(1.0), ((t * t) / 2.0));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (((x * 0.5d0) - y) * sqrt((z * 2.0d0))) * (exp(1.0d0) ** ((t * t) / 2.0d0))
end function
public static double code(double x, double y, double z, double t) {
	return (((x * 0.5) - y) * Math.sqrt((z * 2.0))) * Math.pow(Math.exp(1.0), ((t * t) / 2.0));
}
def code(x, y, z, t):
	return (((x * 0.5) - y) * math.sqrt((z * 2.0))) * math.pow(math.exp(1.0), ((t * t) / 2.0))
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))) * (exp(1.0) ^ Float64(Float64(t * t) / 2.0)))
end
function tmp = code(x, y, z, t)
	tmp = (((x * 0.5) - y) * sqrt((z * 2.0))) * (exp(1.0) ^ ((t * t) / 2.0));
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Power[N[Exp[1.0], $MachinePrecision], N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot {\left(e^{1}\right)}^{\left(\frac{t \cdot t}{2}\right)}
\end{array}

Reproduce

?
herbie shell --seed 2023228 
(FPCore (x y z t)
  :name "Data.Number.Erf:$cinvnormcdf from erf-2.0.0.0, A"
  :precision binary64

  :herbie-target
  (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (pow (exp 1.0) (/ (* t t) 2.0)))

  (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))