
(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 6 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 (+ (* 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}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.6e+91) (not (<= z 5.2e-21))) (* z (cos y)) (+ (* x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.6e+91) || !(z <= 5.2e-21)) {
tmp = z * cos(y);
} else {
tmp = (x * sin(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 ((z <= (-8.6d+91)) .or. (.not. (z <= 5.2d-21))) then
tmp = z * cos(y)
else
tmp = (x * sin(y)) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.6e+91) || !(z <= 5.2e-21)) {
tmp = z * Math.cos(y);
} else {
tmp = (x * Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.6e+91) or not (z <= 5.2e-21): tmp = z * math.cos(y) else: tmp = (x * math.sin(y)) + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.6e+91) || !(z <= 5.2e-21)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(x * sin(y)) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.6e+91) || ~((z <= 5.2e-21))) tmp = z * cos(y); else tmp = (x * sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.6e+91], N[Not[LessEqual[z, 5.2e-21]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.6 \cdot 10^{+91} \lor \neg \left(z \leq 5.2 \cdot 10^{-21}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y + z\\
\end{array}
\end{array}
if z < -8.6000000000000001e91 or 5.20000000000000035e-21 < z Initial program 99.8%
Taylor expanded in x around 0 91.7%
if -8.6000000000000001e91 < z < 5.20000000000000035e-21Initial program 99.8%
Taylor expanded in y around 0 87.0%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.7) (not (<= y 0.0095))) (* x (sin y)) (+ z (* y (+ x (* y (* z -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7) || !(y <= 0.0095)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (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 <= (-3.7d0)) .or. (.not. (y <= 0.0095d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (y * (z * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7) || !(y <= 0.0095)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (y * (z * -0.5))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.7) or not (y <= 0.0095): tmp = x * math.sin(y) else: tmp = z + (y * (x + (y * (z * -0.5)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.7) || !(y <= 0.0095)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(z * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.7) || ~((y <= 0.0095))) tmp = x * sin(y); else tmp = z + (y * (x + (y * (z * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.7], N[Not[LessEqual[y, 0.0095]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \lor \neg \left(y \leq 0.0095\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -3.7000000000000002 or 0.00949999999999999976 < y Initial program 99.5%
Taylor expanded in x around inf 48.3%
if -3.7000000000000002 < y < 0.00949999999999999976Initial program 100.0%
+-commutative100.0%
add-cube-cbrt100.0%
associate-*r*100.0%
fma-def100.0%
pow2100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 98.8%
*-commutative98.8%
unpow298.8%
associate-*l*98.8%
distribute-lft-out98.8%
distribute-rgt-out98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (<= y -3.7) (* x (sin y)) (if (<= y 54000000000.0) (+ z (* y (+ x (* y (* z -0.5))))) (* z (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.7) {
tmp = x * sin(y);
} else if (y <= 54000000000.0) {
tmp = z + (y * (x + (y * (z * -0.5))));
} 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 (y <= (-3.7d0)) then
tmp = x * sin(y)
else if (y <= 54000000000.0d0) then
tmp = z + (y * (x + (y * (z * (-0.5d0)))))
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.7) {
tmp = x * Math.sin(y);
} else if (y <= 54000000000.0) {
tmp = z + (y * (x + (y * (z * -0.5))));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.7: tmp = x * math.sin(y) elif y <= 54000000000.0: tmp = z + (y * (x + (y * (z * -0.5)))) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.7) tmp = Float64(x * sin(y)); elseif (y <= 54000000000.0) tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(z * -0.5))))); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.7) tmp = x * sin(y); elseif (y <= 54000000000.0) tmp = z + (y * (x + (y * (z * -0.5)))); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.7], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 54000000000.0], N[(z + N[(y * N[(x + N[(y * N[(z * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;y \leq 54000000000:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if y < -3.7000000000000002Initial program 99.5%
Taylor expanded in x around inf 52.3%
if -3.7000000000000002 < y < 5.4e10Initial program 100.0%
+-commutative100.0%
add-cube-cbrt100.0%
associate-*r*100.0%
fma-def100.0%
pow2100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 97.6%
*-commutative97.6%
unpow297.6%
associate-*l*97.6%
distribute-lft-out97.6%
distribute-rgt-out97.6%
metadata-eval97.6%
Simplified97.6%
if 5.4e10 < y Initial program 99.5%
Taylor expanded in x around 0 59.3%
Final simplification79.4%
(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.8%
Taylor expanded in y around 0 57.5%
+-commutative57.5%
Simplified57.5%
Final simplification57.5%
(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.8%
+-commutative99.8%
add-cube-cbrt99.4%
associate-*r*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 44.1%
Final simplification44.1%
herbie shell --seed 2023322
(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))))