
(FPCore (x y z) :precision binary64 (* x (sqrt (- (* y y) (* z z)))))
double code(double x, double y, double z) {
return x * sqrt(((y * y) - (z * z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * sqrt(((y * y) - (z * z)))
end function
public static double code(double x, double y, double z) {
return x * Math.sqrt(((y * y) - (z * z)));
}
def code(x, y, z): return x * math.sqrt(((y * y) - (z * z)))
function code(x, y, z) return Float64(x * sqrt(Float64(Float64(y * y) - Float64(z * z)))) end
function tmp = code(x, y, z) tmp = x * sqrt(((y * y) - (z * z))); end
code[x_, y_, z_] := N[(x * N[Sqrt[N[(N[(y * y), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sqrt{y \cdot y - z \cdot z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (sqrt (- (* y y) (* z z)))))
double code(double x, double y, double z) {
return x * sqrt(((y * y) - (z * z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * sqrt(((y * y) - (z * z)))
end function
public static double code(double x, double y, double z) {
return x * Math.sqrt(((y * y) - (z * z)));
}
def code(x, y, z): return x * math.sqrt(((y * y) - (z * z)))
function code(x, y, z) return Float64(x * sqrt(Float64(Float64(y * y) - Float64(z * z)))) end
function tmp = code(x, y, z) tmp = x * sqrt(((y * y) - (z * z))); end
code[x_, y_, z_] := N[(x * N[Sqrt[N[(N[(y * y), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sqrt{y \cdot y - z \cdot z}
\end{array}
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ z (/ y z)))) (if (<= y -1e-262) (* x (- (* 0.5 t_0) y)) (* x (+ y (* t_0 -0.5))))))
double code(double x, double y, double z) {
double t_0 = z / (y / z);
double tmp;
if (y <= -1e-262) {
tmp = x * ((0.5 * t_0) - y);
} else {
tmp = x * (y + (t_0 * -0.5));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = z / (y / z)
if (y <= (-1d-262)) then
tmp = x * ((0.5d0 * t_0) - y)
else
tmp = x * (y + (t_0 * (-0.5d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z / (y / z);
double tmp;
if (y <= -1e-262) {
tmp = x * ((0.5 * t_0) - y);
} else {
tmp = x * (y + (t_0 * -0.5));
}
return tmp;
}
def code(x, y, z): t_0 = z / (y / z) tmp = 0 if y <= -1e-262: tmp = x * ((0.5 * t_0) - y) else: tmp = x * (y + (t_0 * -0.5)) return tmp
function code(x, y, z) t_0 = Float64(z / Float64(y / z)) tmp = 0.0 if (y <= -1e-262) tmp = Float64(x * Float64(Float64(0.5 * t_0) - y)); else tmp = Float64(x * Float64(y + Float64(t_0 * -0.5))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z / (y / z); tmp = 0.0; if (y <= -1e-262) tmp = x * ((0.5 * t_0) - y); else tmp = x * (y + (t_0 * -0.5)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1e-262], N[(x * N[(N[(0.5 * t$95$0), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + N[(t$95$0 * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{z}{\frac{y}{z}}\\
\mathbf{if}\;y \leq -1 \cdot 10^{-262}:\\
\;\;\;\;x \cdot \left(0.5 \cdot t_0 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + t_0 \cdot -0.5\right)\\
\end{array}
\end{array}
if y < -1.00000000000000001e-262Initial program 67.8%
Taylor expanded in y around -inf 92.8%
mul-1-neg92.8%
unsub-neg92.8%
unpow292.8%
associate-/l*99.8%
Simplified99.8%
if -1.00000000000000001e-262 < y Initial program 63.4%
Taylor expanded in y around inf 92.1%
unpow292.1%
Simplified92.1%
Taylor expanded in z around 0 92.1%
*-commutative92.1%
unpow292.1%
associate-/l*99.5%
Simplified99.5%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (<= y -1e-262) (* y (- x)) (* x (+ y (* (/ z (/ y z)) -0.5)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1e-262) {
tmp = y * -x;
} else {
tmp = x * (y + ((z / (y / z)) * -0.5));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-1d-262)) then
tmp = y * -x
else
tmp = x * (y + ((z / (y / z)) * (-0.5d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1e-262) {
tmp = y * -x;
} else {
tmp = x * (y + ((z / (y / z)) * -0.5));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1e-262: tmp = y * -x else: tmp = x * (y + ((z / (y / z)) * -0.5)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1e-262) tmp = Float64(y * Float64(-x)); else tmp = Float64(x * Float64(y + Float64(Float64(z / Float64(y / z)) * -0.5))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1e-262) tmp = y * -x; else tmp = x * (y + ((z / (y / z)) * -0.5)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1e-262], N[(y * (-x)), $MachinePrecision], N[(x * N[(y + N[(N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-262}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + \frac{z}{\frac{y}{z}} \cdot -0.5\right)\\
\end{array}
\end{array}
if y < -1.00000000000000001e-262Initial program 67.8%
Taylor expanded in y around -inf 99.6%
associate-*r*99.6%
mul-1-neg99.6%
Simplified99.6%
if -1.00000000000000001e-262 < y Initial program 63.4%
Taylor expanded in y around inf 92.1%
unpow292.1%
Simplified92.1%
Taylor expanded in z around 0 92.1%
*-commutative92.1%
unpow292.1%
associate-/l*99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (<= y -1e-262) (* y (- x)) (* y x)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1e-262) {
tmp = y * -x;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-1d-262)) then
tmp = y * -x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1e-262) {
tmp = y * -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1e-262: tmp = y * -x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1e-262) tmp = Float64(y * Float64(-x)); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1e-262) tmp = y * -x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1e-262], N[(y * (-x)), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-262}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.00000000000000001e-262Initial program 67.8%
Taylor expanded in y around -inf 99.6%
associate-*r*99.6%
mul-1-neg99.6%
Simplified99.6%
if -1.00000000000000001e-262 < y Initial program 63.4%
Taylor expanded in y around inf 99.4%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 65.7%
Taylor expanded in y around inf 51.9%
Final simplification51.9%
(FPCore (x y z) :precision binary64 (if (< y 2.5816096488251695e-278) (- (* x y)) (* x (* (sqrt (+ y z)) (sqrt (- y z))))))
double code(double x, double y, double z) {
double tmp;
if (y < 2.5816096488251695e-278) {
tmp = -(x * y);
} else {
tmp = x * (sqrt((y + z)) * sqrt((y - z)));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y < 2.5816096488251695d-278) then
tmp = -(x * y)
else
tmp = x * (sqrt((y + z)) * sqrt((y - z)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y < 2.5816096488251695e-278) {
tmp = -(x * y);
} else {
tmp = x * (Math.sqrt((y + z)) * Math.sqrt((y - z)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y < 2.5816096488251695e-278: tmp = -(x * y) else: tmp = x * (math.sqrt((y + z)) * math.sqrt((y - z))) return tmp
function code(x, y, z) tmp = 0.0 if (y < 2.5816096488251695e-278) tmp = Float64(-Float64(x * y)); else tmp = Float64(x * Float64(sqrt(Float64(y + z)) * sqrt(Float64(y - z)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y < 2.5816096488251695e-278) tmp = -(x * y); else tmp = x * (sqrt((y + z)) * sqrt((y - z))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Less[y, 2.5816096488251695e-278], (-N[(x * y), $MachinePrecision]), N[(x * N[(N[Sqrt[N[(y + z), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(y - z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y < 2.5816096488251695 \cdot 10^{-278}:\\
\;\;\;\;-x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\sqrt{y + z} \cdot \sqrt{y - z}\right)\\
\end{array}
\end{array}
herbie shell --seed 2023196
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, B"
:precision binary64
:herbie-target
(if (< y 2.5816096488251695e-278) (- (* x y)) (* x (* (sqrt (+ y z)) (sqrt (- y z)))))
(* x (sqrt (- (* y y) (* z z)))))