
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * 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 = (x + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * 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 = (x + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma (sin y) (- z) (+ x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x + cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x + cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x + \cos y\right)
\end{array}
Initial program 100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.5e+18) x (if (<= x 6.8e-12) (- (cos y) (* (sin y) z)) (+ x (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e+18) {
tmp = x;
} else if (x <= 6.8e-12) {
tmp = cos(y) - (sin(y) * z);
} else {
tmp = x + 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.5d+18)) then
tmp = x
else if (x <= 6.8d-12) then
tmp = cos(y) - (sin(y) * z)
else
tmp = x + cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.5e+18) {
tmp = x;
} else if (x <= 6.8e-12) {
tmp = Math.cos(y) - (Math.sin(y) * z);
} else {
tmp = x + Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.5e+18: tmp = x elif x <= 6.8e-12: tmp = math.cos(y) - (math.sin(y) * z) else: tmp = x + math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.5e+18) tmp = x; elseif (x <= 6.8e-12) tmp = Float64(cos(y) - Float64(sin(y) * z)); else tmp = Float64(x + cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.5e+18) tmp = x; elseif (x <= 6.8e-12) tmp = cos(y) - (sin(y) * z); else tmp = x + cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.5e+18], x, If[LessEqual[x, 6.8e-12], N[(N[Cos[y], $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+18}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{-12}:\\
\;\;\;\;\cos y - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + \cos y\\
\end{array}
\end{array}
if x < -1.5e18Initial program 99.9%
Taylor expanded in x around inf 87.8%
if -1.5e18 < x < 6.8000000000000001e-12Initial program 99.9%
Taylor expanded in x around 0 98.6%
if 6.8000000000000001e-12 < x Initial program 100.0%
Taylor expanded in z around 0 90.5%
Final simplification94.0%
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x + cos(y)) - (sin(y) * 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 + cos(y)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x + math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - \sin y \cdot z
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.8) (not (<= y 1.75e-19))) (+ x (cos y)) (+ 1.0 (fma (- y) z x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.8) || !(y <= 1.75e-19)) {
tmp = x + cos(y);
} else {
tmp = 1.0 + fma(-y, z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -7.8) || !(y <= 1.75e-19)) tmp = Float64(x + cos(y)); else tmp = Float64(1.0 + fma(Float64(-y), z, x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.8], N[Not[LessEqual[y, 1.75e-19]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[((-y) * z + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \lor \neg \left(y \leq 1.75 \cdot 10^{-19}\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;1 + \mathsf{fma}\left(-y, z, x\right)\\
\end{array}
\end{array}
if y < -7.79999999999999982 or 1.75000000000000008e-19 < y Initial program 99.9%
Taylor expanded in z around 0 68.8%
if -7.79999999999999982 < y < 1.75000000000000008e-19Initial program 100.0%
Taylor expanded in y around 0 98.6%
associate-*r*98.6%
fma-def98.6%
mul-1-neg98.6%
Simplified98.6%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.2) (not (<= y 1.75e-19))) (+ x (cos y)) (+ 1.0 (- x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2) || !(y <= 1.75e-19)) {
tmp = x + cos(y);
} else {
tmp = 1.0 + (x - (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 <= (-7.2d0)) .or. (.not. (y <= 1.75d-19))) then
tmp = x + cos(y)
else
tmp = 1.0d0 + (x - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2) || !(y <= 1.75e-19)) {
tmp = x + Math.cos(y);
} else {
tmp = 1.0 + (x - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.2) or not (y <= 1.75e-19): tmp = x + math.cos(y) else: tmp = 1.0 + (x - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.2) || !(y <= 1.75e-19)) tmp = Float64(x + cos(y)); else tmp = Float64(1.0 + Float64(x - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.2) || ~((y <= 1.75e-19))) tmp = x + cos(y); else tmp = 1.0 + (x - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.2], N[Not[LessEqual[y, 1.75e-19]], $MachinePrecision]], N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \lor \neg \left(y \leq 1.75 \cdot 10^{-19}\right):\\
\;\;\;\;x + \cos y\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\end{array}
\end{array}
if y < -7.20000000000000018 or 1.75000000000000008e-19 < y Initial program 99.9%
Taylor expanded in z around 0 68.8%
if -7.20000000000000018 < y < 1.75000000000000008e-19Initial program 100.0%
Taylor expanded in y around 0 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
Applied egg-rr98.6%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (<= y -6.8e+52) (+ x 1.0) (if (<= y 1.75e-19) (+ 1.0 (- x (* y z))) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e+52) {
tmp = x + 1.0;
} else if (y <= 1.75e-19) {
tmp = 1.0 + (x - (y * z));
} else {
tmp = x + 1.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) :: tmp
if (y <= (-6.8d+52)) then
tmp = x + 1.0d0
else if (y <= 1.75d-19) then
tmp = 1.0d0 + (x - (y * z))
else
tmp = x + 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e+52) {
tmp = x + 1.0;
} else if (y <= 1.75e-19) {
tmp = 1.0 + (x - (y * z));
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.8e+52: tmp = x + 1.0 elif y <= 1.75e-19: tmp = 1.0 + (x - (y * z)) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.8e+52) tmp = Float64(x + 1.0); elseif (y <= 1.75e-19) tmp = Float64(1.0 + Float64(x - Float64(y * z))); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.8e+52) tmp = x + 1.0; elseif (y <= 1.75e-19) tmp = 1.0 + (x - (y * z)); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.8e+52], N[(x + 1.0), $MachinePrecision], If[LessEqual[y, 1.75e-19], N[(1.0 + N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+52}:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{-19}:\\
\;\;\;\;1 + \left(x - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if y < -6.8e52 or 1.75000000000000008e-19 < y Initial program 99.9%
Taylor expanded in y around 0 48.3%
+-commutative48.3%
Simplified48.3%
if -6.8e52 < y < 1.75000000000000008e-19Initial program 100.0%
Taylor expanded in y around 0 95.3%
+-commutative95.3%
mul-1-neg95.3%
unsub-neg95.3%
Applied egg-rr95.3%
Final simplification74.4%
(FPCore (x y z) :precision binary64 (if (<= x -70.0) (+ x 1.0) (if (<= x 6.8e-12) (- 1.0 (* y z)) (+ x 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -70.0) {
tmp = x + 1.0;
} else if (x <= 6.8e-12) {
tmp = 1.0 - (y * z);
} else {
tmp = x + 1.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) :: tmp
if (x <= (-70.0d0)) then
tmp = x + 1.0d0
else if (x <= 6.8d-12) then
tmp = 1.0d0 - (y * z)
else
tmp = x + 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -70.0) {
tmp = x + 1.0;
} else if (x <= 6.8e-12) {
tmp = 1.0 - (y * z);
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -70.0: tmp = x + 1.0 elif x <= 6.8e-12: tmp = 1.0 - (y * z) else: tmp = x + 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (x <= -70.0) tmp = Float64(x + 1.0); elseif (x <= 6.8e-12) tmp = Float64(1.0 - Float64(y * z)); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -70.0) tmp = x + 1.0; elseif (x <= 6.8e-12) tmp = 1.0 - (y * z); else tmp = x + 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -70.0], N[(x + 1.0), $MachinePrecision], If[LessEqual[x, 6.8e-12], N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -70:\\
\;\;\;\;x + 1\\
\mathbf{elif}\;x \leq 6.8 \cdot 10^{-12}:\\
\;\;\;\;1 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if x < -70 or 6.8000000000000001e-12 < x Initial program 100.0%
Taylor expanded in y around 0 85.4%
+-commutative85.4%
Simplified85.4%
if -70 < x < 6.8000000000000001e-12Initial program 99.9%
Taylor expanded in y around 0 58.0%
Taylor expanded in y around inf 57.5%
associate-*r*57.5%
neg-mul-157.5%
Simplified57.5%
Taylor expanded in y around 0 57.5%
mul-1-neg57.5%
sub-neg57.5%
Simplified57.5%
Final simplification72.0%
(FPCore (x y z) :precision binary64 (if (<= x -0.000205) x (if (<= x 3.5e-6) 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -0.000205) {
tmp = x;
} else if (x <= 3.5e-6) {
tmp = 1.0;
} else {
tmp = 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 (x <= (-0.000205d0)) then
tmp = x
else if (x <= 3.5d-6) then
tmp = 1.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -0.000205) {
tmp = x;
} else if (x <= 3.5e-6) {
tmp = 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -0.000205: tmp = x elif x <= 3.5e-6: tmp = 1.0 else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -0.000205) tmp = x; elseif (x <= 3.5e-6) tmp = 1.0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -0.000205) tmp = x; elseif (x <= 3.5e-6) tmp = 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -0.000205], x, If[LessEqual[x, 3.5e-6], 1.0, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.000205:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-6}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.05e-4 or 3.49999999999999995e-6 < x Initial program 100.0%
Taylor expanded in x around inf 84.1%
if -2.05e-4 < x < 3.49999999999999995e-6Initial program 99.9%
Taylor expanded in y around 0 57.5%
Taylor expanded in y around inf 56.3%
associate-*r*56.3%
neg-mul-156.3%
Simplified56.3%
Taylor expanded in y around 0 38.5%
Final simplification62.0%
(FPCore (x y z) :precision binary64 (+ x 1.0))
double code(double x, double y, double z) {
return x + 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + 1.0d0
end function
public static double code(double x, double y, double z) {
return x + 1.0;
}
def code(x, y, z): return x + 1.0
function code(x, y, z) return Float64(x + 1.0) end
function tmp = code(x, y, z) tmp = x + 1.0; end
code[x_, y_, z_] := N[(x + 1.0), $MachinePrecision]
\begin{array}{l}
\\
x + 1
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 62.8%
+-commutative62.8%
Simplified62.8%
Final simplification62.8%
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 68.4%
Taylor expanded in y around inf 31.5%
associate-*r*31.5%
neg-mul-131.5%
Simplified31.5%
Taylor expanded in y around 0 20.4%
Final simplification20.4%
herbie shell --seed 2023268
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, B"
:precision binary64
(- (+ x (cos y)) (* z (sin y))))