
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ z y) x (- z)))
double code(double x, double y, double z) {
return fma((z + y), x, -z);
}
function code(x, y, z) return fma(Float64(z + y), x, Float64(-z)) end
code[x_, y_, z_] := N[(N[(z + y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + y, x, -z\right)
\end{array}
Initial program 96.4%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.3) (not (<= x 7.8e-11))) (* (+ z y) x) (* (- x 1.0) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3) || !(x <= 7.8e-11)) {
tmp = (z + y) * x;
} else {
tmp = (x - 1.0) * 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 ((x <= (-2.3d0)) .or. (.not. (x <= 7.8d-11))) then
tmp = (z + y) * x
else
tmp = (x - 1.0d0) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3) || !(x <= 7.8e-11)) {
tmp = (z + y) * x;
} else {
tmp = (x - 1.0) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.3) or not (x <= 7.8e-11): tmp = (z + y) * x else: tmp = (x - 1.0) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.3) || !(x <= 7.8e-11)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(x - 1.0) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.3) || ~((x <= 7.8e-11))) tmp = (z + y) * x; else tmp = (x - 1.0) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.3], N[Not[LessEqual[x, 7.8e-11]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \lor \neg \left(x \leq 7.8 \cdot 10^{-11}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(x - 1\right) \cdot z\\
\end{array}
\end{array}
if x < -2.2999999999999998 or 7.80000000000000021e-11 < x Initial program 93.5%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.9
Applied rewrites98.9%
if -2.2999999999999998 < x < 7.80000000000000021e-11Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.6
Applied rewrites75.6%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.5e-40) (not (<= x 6.8e-12))) (* (+ z y) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e-40) || !(x <= 6.8e-12)) {
tmp = (z + y) * x;
} 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 ((x <= (-9.5d-40)) .or. (.not. (x <= 6.8d-12))) then
tmp = (z + y) * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.5e-40) || !(x <= 6.8e-12)) {
tmp = (z + y) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.5e-40) or not (x <= 6.8e-12): tmp = (z + y) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.5e-40) || !(x <= 6.8e-12)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.5e-40) || ~((x <= 6.8e-12))) tmp = (z + y) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.5e-40], N[Not[LessEqual[x, 6.8e-12]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-40} \lor \neg \left(x \leq 6.8 \cdot 10^{-12}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -9.5000000000000006e-40 or 6.8000000000000001e-12 < x Initial program 93.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6496.0
Applied rewrites96.0%
if -9.5000000000000006e-40 < x < 6.8000000000000001e-12Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6476.5
Applied rewrites76.5%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.46) (not (<= x 6.8e-12))) (* y x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.46) || !(x <= 6.8e-12)) {
tmp = y * x;
} 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 ((x <= (-0.46d0)) .or. (.not. (x <= 6.8d-12))) then
tmp = y * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -0.46) || !(x <= 6.8e-12)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.46) or not (x <= 6.8e-12): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.46) || !(x <= 6.8e-12)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.46) || ~((x <= 6.8e-12))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.46], N[Not[LessEqual[x, 6.8e-12]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.46 \lor \neg \left(x \leq 6.8 \cdot 10^{-12}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -0.46000000000000002 or 6.8000000000000001e-12 < x Initial program 93.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6458.6
Applied rewrites58.6%
if -0.46000000000000002 < x < 6.8000000000000001e-12Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6473.9
Applied rewrites73.9%
Final simplification65.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -72000.0) (not (<= x 1.0))) (* z x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -72000.0) || !(x <= 1.0)) {
tmp = z * x;
} 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 ((x <= (-72000.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = z * x
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -72000.0) || !(x <= 1.0)) {
tmp = z * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -72000.0) or not (x <= 1.0): tmp = z * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -72000.0) || !(x <= 1.0)) tmp = Float64(z * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -72000.0) || ~((x <= 1.0))) tmp = z * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -72000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -72000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -72000 or 1 < x Initial program 93.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6444.9
Applied rewrites44.9%
Taylor expanded in x around inf
Applied rewrites44.5%
if -72000 < x < 1Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6471.1
Applied rewrites71.1%
Final simplification57.1%
(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 Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 96.4%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6435.1
Applied rewrites35.1%
(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 96.4%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6435.1
Applied rewrites35.1%
Applied rewrites2.6%
herbie shell --seed 2024313
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))