
(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:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (x y z t) :precision binary64 (* (- (* 0.5 x) y) (sqrt (* (pow (exp t) t) (* 2.0 z)))))
double code(double x, double y, double z, double t) {
return ((0.5 * x) - y) * sqrt((pow(exp(t), t) * (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 = ((0.5d0 * x) - y) * sqrt(((exp(t) ** t) * (2.0d0 * z)))
end function
public static double code(double x, double y, double z, double t) {
return ((0.5 * x) - y) * Math.sqrt((Math.pow(Math.exp(t), t) * (2.0 * z)));
}
def code(x, y, z, t): return ((0.5 * x) - y) * math.sqrt((math.pow(math.exp(t), t) * (2.0 * z)))
function code(x, y, z, t) return Float64(Float64(Float64(0.5 * x) - y) * sqrt(Float64((exp(t) ^ t) * Float64(2.0 * z)))) end
function tmp = code(x, y, z, t) tmp = ((0.5 * x) - y) * sqrt(((exp(t) ^ t) * (2.0 * z))); end
code[x_, y_, z_, t_] := N[(N[(N[(0.5 * x), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(N[Power[N[Exp[t], $MachinePrecision], t], $MachinePrecision] * N[(2.0 * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot x - y\right) \cdot \sqrt{{\left(e^{t}\right)}^{t} \cdot \left(2 \cdot z\right)}
\end{array}
Initial program 99.0%
*-commutative99.0%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
exp-sqrt99.8%
associate-*r*99.0%
*-commutative99.0%
expm1-log1p-u54.1%
expm1-udef42.0%
Applied egg-rr42.4%
expm1-def54.5%
expm1-log1p99.8%
*-commutative99.8%
*-commutative99.8%
*-commutative99.8%
Simplified99.8%
pow299.8%
exp-prod99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z t) :precision binary64 (* (- (* 0.5 x) y) (sqrt (* (* 2.0 z) (exp (* t t))))))
double code(double x, double y, double z, double t) {
return ((0.5 * x) - 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 = ((0.5d0 * x) - y) * sqrt(((2.0d0 * z) * exp((t * t))))
end function
public static double code(double x, double y, double z, double t) {
return ((0.5 * x) - y) * Math.sqrt(((2.0 * z) * Math.exp((t * t))));
}
def code(x, y, z, t): return ((0.5 * x) - y) * math.sqrt(((2.0 * z) * math.exp((t * t))))
function code(x, y, z, t) return Float64(Float64(Float64(0.5 * x) - y) * sqrt(Float64(Float64(2.0 * z) * exp(Float64(t * t))))) end
function tmp = code(x, y, z, t) tmp = ((0.5 * x) - y) * sqrt(((2.0 * z) * exp((t * t)))); end
code[x_, y_, z_, t_] := N[(N[(N[(0.5 * x), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(N[(2.0 * z), $MachinePrecision] * N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot x - y\right) \cdot \sqrt{\left(2 \cdot z\right) \cdot e^{t \cdot t}}
\end{array}
Initial program 99.0%
*-commutative99.0%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
exp-sqrt99.8%
associate-*r*99.0%
*-commutative99.0%
expm1-log1p-u54.1%
expm1-udef42.0%
Applied egg-rr42.4%
expm1-def54.5%
expm1-log1p99.8%
*-commutative99.8%
*-commutative99.8%
*-commutative99.8%
Simplified99.8%
pow287.0%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* 0.5 x) y)))
(if (<= t 155000.0)
(* t_1 (sqrt (* 2.0 z)))
(sqrt (* (* 2.0 z) (* t_1 t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = (0.5 * x) - y;
double tmp;
if (t <= 155000.0) {
tmp = t_1 * sqrt((2.0 * z));
} else {
tmp = sqrt(((2.0 * z) * (t_1 * t_1)));
}
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 = (0.5d0 * x) - y
if (t <= 155000.0d0) then
tmp = t_1 * sqrt((2.0d0 * z))
else
tmp = sqrt(((2.0d0 * z) * (t_1 * t_1)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (0.5 * x) - y;
double tmp;
if (t <= 155000.0) {
tmp = t_1 * Math.sqrt((2.0 * z));
} else {
tmp = Math.sqrt(((2.0 * z) * (t_1 * t_1)));
}
return tmp;
}
def code(x, y, z, t): t_1 = (0.5 * x) - y tmp = 0 if t <= 155000.0: tmp = t_1 * math.sqrt((2.0 * z)) else: tmp = math.sqrt(((2.0 * z) * (t_1 * t_1))) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(0.5 * x) - y) tmp = 0.0 if (t <= 155000.0) tmp = Float64(t_1 * sqrt(Float64(2.0 * z))); else tmp = sqrt(Float64(Float64(2.0 * z) * Float64(t_1 * t_1))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (0.5 * x) - y; tmp = 0.0; if (t <= 155000.0) tmp = t_1 * sqrt((2.0 * z)); else tmp = sqrt(((2.0 * z) * (t_1 * t_1))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(0.5 * x), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[t, 155000.0], N[(t$95$1 * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[(2.0 * z), $MachinePrecision] * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := 0.5 \cdot x - y\\
\mathbf{if}\;t \leq 155000:\\
\;\;\;\;t_1 \cdot \sqrt{2 \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(2 \cdot z\right) \cdot \left(t_1 \cdot t_1\right)}\\
\end{array}
\end{array}
if t < 155000Initial program 99.2%
*-commutative99.2%
associate-*l*99.7%
exp-sqrt99.7%
Simplified99.7%
Taylor expanded in t around 0 74.8%
if 155000 < t Initial program 98.3%
*-commutative98.3%
associate-*l*100.0%
exp-sqrt100.0%
Simplified100.0%
Taylor expanded in t around 0 17.0%
sub-neg17.0%
*-commutative17.0%
sub-neg17.0%
add-sqr-sqrt6.5%
sqrt-unprod19.3%
swap-sqr24.1%
add-sqr-sqrt24.1%
*-commutative24.1%
pow224.1%
*-commutative24.1%
Applied egg-rr24.1%
unpow224.1%
Applied egg-rr24.1%
Final simplification62.9%
(FPCore (x y z t) :precision binary64 (* (sqrt (* 2.0 z)) (* (- (* 0.5 x) y) (+ 1.0 (* 0.5 (* t t))))))
double code(double x, double y, double z, double t) {
return sqrt((2.0 * z)) * (((0.5 * x) - y) * (1.0 + (0.5 * (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 = sqrt((2.0d0 * z)) * (((0.5d0 * x) - y) * (1.0d0 + (0.5d0 * (t * t))))
end function
public static double code(double x, double y, double z, double t) {
return Math.sqrt((2.0 * z)) * (((0.5 * x) - y) * (1.0 + (0.5 * (t * t))));
}
def code(x, y, z, t): return math.sqrt((2.0 * z)) * (((0.5 * x) - y) * (1.0 + (0.5 * (t * t))))
function code(x, y, z, t) return Float64(sqrt(Float64(2.0 * z)) * Float64(Float64(Float64(0.5 * x) - y) * Float64(1.0 + Float64(0.5 * Float64(t * t))))) end
function tmp = code(x, y, z, t) tmp = sqrt((2.0 * z)) * (((0.5 * x) - y) * (1.0 + (0.5 * (t * t)))); end
code[x_, y_, z_, t_] := N[(N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision] * N[(N[(N[(0.5 * x), $MachinePrecision] - y), $MachinePrecision] * N[(1.0 + N[(0.5 * N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{2 \cdot z} \cdot \left(\left(0.5 \cdot x - y\right) \cdot \left(1 + 0.5 \cdot \left(t \cdot t\right)\right)\right)
\end{array}
Initial program 99.0%
*-commutative99.0%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
Taylor expanded in t around 0 87.0%
*-commutative87.0%
Simplified87.0%
pow287.0%
Applied egg-rr87.0%
Final simplification87.0%
(FPCore (x y z t) :precision binary64 (* (- (* 0.5 x) y) (sqrt (* 2.0 z))))
double code(double x, double y, double z, double t) {
return ((0.5 * x) - 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 = ((0.5d0 * x) - y) * sqrt((2.0d0 * z))
end function
public static double code(double x, double y, double z, double t) {
return ((0.5 * x) - y) * Math.sqrt((2.0 * z));
}
def code(x, y, z, t): return ((0.5 * x) - y) * math.sqrt((2.0 * z))
function code(x, y, z, t) return Float64(Float64(Float64(0.5 * x) - y) * sqrt(Float64(2.0 * z))) end
function tmp = code(x, y, z, t) tmp = ((0.5 * x) - y) * sqrt((2.0 * z)); end
code[x_, y_, z_, t_] := N[(N[(N[(0.5 * x), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot x - y\right) \cdot \sqrt{2 \cdot z}
\end{array}
Initial program 99.0%
*-commutative99.0%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
Taylor expanded in t around 0 61.3%
Final simplification61.3%
(FPCore (x y z t) :precision binary64 (* 0.5 (* x (sqrt (* 2.0 z)))))
double code(double x, double y, double z, double t) {
return 0.5 * (x * 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 = 0.5d0 * (x * sqrt((2.0d0 * z)))
end function
public static double code(double x, double y, double z, double t) {
return 0.5 * (x * Math.sqrt((2.0 * z)));
}
def code(x, y, z, t): return 0.5 * (x * math.sqrt((2.0 * z)))
function code(x, y, z, t) return Float64(0.5 * Float64(x * sqrt(Float64(2.0 * z)))) end
function tmp = code(x, y, z, t) tmp = 0.5 * (x * sqrt((2.0 * z))); end
code[x_, y_, z_, t_] := N[(0.5 * N[(x * N[Sqrt[N[(2.0 * z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot \sqrt{2 \cdot z}\right)
\end{array}
Initial program 99.0%
*-commutative99.0%
associate-*l*99.8%
exp-sqrt99.8%
Simplified99.8%
Taylor expanded in t around 0 61.3%
Taylor expanded in x around inf 33.4%
associate-*l*33.4%
Simplified33.4%
expm1-log1p-u22.0%
expm1-udef15.9%
sqrt-prod15.9%
Applied egg-rr15.9%
expm1-def22.0%
expm1-log1p33.5%
Simplified33.5%
Final simplification33.5%
(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}
herbie shell --seed 2024021
(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))))