
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (z * cos(y)) + (x * sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x * Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x * math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x * sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x * sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + x \cdot \sin y
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))) (t_1 (* x (sin y))))
(if (<= y -2.6e+243)
t_0
(if (<= y -0.25)
t_1
(if (<= y 30500.0)
(+ (* -0.5 (* y (* y z))) (+ z (* x y)))
(if (or (<= y 3e+209) (not (<= y 1.8e+233))) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double t_1 = x * sin(y);
double tmp;
if (y <= -2.6e+243) {
tmp = t_0;
} else if (y <= -0.25) {
tmp = t_1;
} else if (y <= 30500.0) {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
} else if ((y <= 3e+209) || !(y <= 1.8e+233)) {
tmp = t_1;
} else {
tmp = t_0;
}
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) :: t_1
real(8) :: tmp
t_0 = z * cos(y)
t_1 = x * sin(y)
if (y <= (-2.6d+243)) then
tmp = t_0
else if (y <= (-0.25d0)) then
tmp = t_1
else if (y <= 30500.0d0) then
tmp = ((-0.5d0) * (y * (y * z))) + (z + (x * y))
else if ((y <= 3d+209) .or. (.not. (y <= 1.8d+233))) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double t_1 = x * Math.sin(y);
double tmp;
if (y <= -2.6e+243) {
tmp = t_0;
} else if (y <= -0.25) {
tmp = t_1;
} else if (y <= 30500.0) {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
} else if ((y <= 3e+209) || !(y <= 1.8e+233)) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) t_1 = x * math.sin(y) tmp = 0 if y <= -2.6e+243: tmp = t_0 elif y <= -0.25: tmp = t_1 elif y <= 30500.0: tmp = (-0.5 * (y * (y * z))) + (z + (x * y)) elif (y <= 3e+209) or not (y <= 1.8e+233): tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) t_1 = Float64(x * sin(y)) tmp = 0.0 if (y <= -2.6e+243) tmp = t_0; elseif (y <= -0.25) tmp = t_1; elseif (y <= 30500.0) tmp = Float64(Float64(-0.5 * Float64(y * Float64(y * z))) + Float64(z + Float64(x * y))); elseif ((y <= 3e+209) || !(y <= 1.8e+233)) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); t_1 = x * sin(y); tmp = 0.0; if (y <= -2.6e+243) tmp = t_0; elseif (y <= -0.25) tmp = t_1; elseif (y <= 30500.0) tmp = (-0.5 * (y * (y * z))) + (z + (x * y)); elseif ((y <= 3e+209) || ~((y <= 1.8e+233))) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.6e+243], t$95$0, If[LessEqual[y, -0.25], t$95$1, If[LessEqual[y, 30500.0], N[(N[(-0.5 * N[(y * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 3e+209], N[Not[LessEqual[y, 1.8e+233]], $MachinePrecision]], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -2.6 \cdot 10^{+243}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.25:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 30500:\\
\;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot z\right)\right) + \left(z + x \cdot y\right)\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+209} \lor \neg \left(y \leq 1.8 \cdot 10^{+233}\right):\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.59999999999999997e243 or 2.99999999999999985e209 < y < 1.7999999999999999e233Initial program 99.7%
*-commutative99.7%
add-cube-cbrt99.2%
associate-*l*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in x around 0 75.1%
if -2.59999999999999997e243 < y < -0.25 or 30500 < y < 2.99999999999999985e209 or 1.7999999999999999e233 < y Initial program 99.7%
*-commutative99.7%
add-cube-cbrt98.6%
associate-*l*98.6%
fma-def98.6%
pow298.6%
Applied egg-rr98.6%
Taylor expanded in x around inf 64.0%
pow-base-164.0%
*-lft-identity64.0%
Simplified64.0%
if -0.25 < y < 30500Initial program 100.0%
Taylor expanded in y around 0 98.0%
expm1-log1p-u90.4%
expm1-udef90.1%
unpow290.1%
associate-*l*90.1%
Applied egg-rr90.1%
expm1-def90.4%
expm1-log1p98.0%
Simplified98.0%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.1e+39) (not (<= x 1e-19))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e+39) || !(x <= 1e-19)) {
tmp = z + (x * sin(y));
} else {
tmp = z * cos(y);
}
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 ((x <= (-1.1d+39)) .or. (.not. (x <= 1d-19))) then
tmp = z + (x * sin(y))
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e+39) || !(x <= 1e-19)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.1e+39) or not (x <= 1e-19): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e+39) || !(x <= 1e-19)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.1e+39) || ~((x <= 1e-19))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e+39], N[Not[LessEqual[x, 1e-19]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+39} \lor \neg \left(x \leq 10^{-19}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -1.1000000000000001e39 or 9.9999999999999998e-20 < x Initial program 99.8%
Taylor expanded in y around 0 93.2%
if -1.1000000000000001e39 < x < 9.9999999999999998e-20Initial program 99.9%
*-commutative99.9%
add-cube-cbrt99.7%
associate-*l*99.7%
fma-def99.7%
pow299.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 88.0%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.06) (not (<= y 0.0078))) (* z (cos y)) (+ (* -0.5 (* y (* y z))) (+ z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.06) || !(y <= 0.0078)) {
tmp = z * cos(y);
} else {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
}
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 <= (-0.06d0)) .or. (.not. (y <= 0.0078d0))) then
tmp = z * cos(y)
else
tmp = ((-0.5d0) * (y * (y * z))) + (z + (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.06) || !(y <= 0.0078)) {
tmp = z * Math.cos(y);
} else {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.06) or not (y <= 0.0078): tmp = z * math.cos(y) else: tmp = (-0.5 * (y * (y * z))) + (z + (x * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.06) || !(y <= 0.0078)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(-0.5 * Float64(y * Float64(y * z))) + Float64(z + Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.06) || ~((y <= 0.0078))) tmp = z * cos(y); else tmp = (-0.5 * (y * (y * z))) + (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.06], N[Not[LessEqual[y, 0.0078]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(y * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.06 \lor \neg \left(y \leq 0.0078\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot z\right)\right) + \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if y < -0.059999999999999998 or 0.0077999999999999996 < y Initial program 99.7%
*-commutative99.7%
add-cube-cbrt98.8%
associate-*l*98.8%
fma-def98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in x around 0 47.3%
if -0.059999999999999998 < y < 0.0077999999999999996Initial program 100.0%
Taylor expanded in y around 0 99.9%
expm1-log1p-u92.0%
expm1-udef92.0%
unpow292.0%
associate-*l*92.0%
Applied egg-rr92.0%
expm1-def92.0%
expm1-log1p99.9%
Simplified99.9%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.15e-112) z (if (<= z 4.3e-193) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.15e-112) {
tmp = z;
} else if (z <= 4.3e-193) {
tmp = x * y;
} else {
tmp = 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 (z <= (-1.15d-112)) then
tmp = z
else if (z <= 4.3d-193) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.15e-112) {
tmp = z;
} else if (z <= 4.3e-193) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.15e-112: tmp = z elif z <= 4.3e-193: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.15e-112) tmp = z; elseif (z <= 4.3e-193) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.15e-112) tmp = z; elseif (z <= 4.3e-193) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.15e-112], z, If[LessEqual[z, 4.3e-193], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-112}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{-193}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.14999999999999995e-112 or 4.3000000000000002e-193 < z Initial program 99.9%
*-commutative99.9%
add-cube-cbrt99.3%
associate-*l*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 52.2%
if -1.14999999999999995e-112 < z < 4.3000000000000002e-193Initial program 99.9%
Taylor expanded in y around 0 49.3%
Taylor expanded in y around inf 33.2%
Final simplification47.6%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 57.7%
Final simplification57.7%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
*-commutative99.9%
add-cube-cbrt99.1%
associate-*l*99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in y around 0 44.0%
Final simplification44.0%
herbie shell --seed 2023268
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))