
(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 8 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 98.8%
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 (<= x -3.3e+16) (* z x) (if (or (<= x -3.2e-23) (not (<= x 2.9e-50))) (* y x) (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.3e+16) {
tmp = z * x;
} else if ((x <= -3.2e-23) || !(x <= 2.9e-50)) {
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 <= (-3.3d+16)) then
tmp = z * x
else if ((x <= (-3.2d-23)) .or. (.not. (x <= 2.9d-50))) 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 <= -3.3e+16) {
tmp = z * x;
} else if ((x <= -3.2e-23) || !(x <= 2.9e-50)) {
tmp = y * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.3e+16: tmp = z * x elif (x <= -3.2e-23) or not (x <= 2.9e-50): tmp = y * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.3e+16) tmp = Float64(z * x); elseif ((x <= -3.2e-23) || !(x <= 2.9e-50)) tmp = Float64(y * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.3e+16) tmp = z * x; elseif ((x <= -3.2e-23) || ~((x <= 2.9e-50))) tmp = y * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.3e+16], N[(z * x), $MachinePrecision], If[Or[LessEqual[x, -3.2e-23], N[Not[LessEqual[x, 2.9e-50]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-z)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{+16}:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 2.9 \cdot 10^{-50}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.3e16Initial program 98.5%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6464.4
Applied rewrites64.4%
Taylor expanded in x around inf
Applied rewrites64.4%
if -3.3e16 < x < -3.19999999999999976e-23 or 2.90000000000000008e-50 < x Initial program 97.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f648.3
Applied rewrites8.3%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6462.0
Applied rewrites62.0%
if -3.19999999999999976e-23 < x < 2.90000000000000008e-50Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6477.6
Applied rewrites77.6%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.2e-23) (not (<= x 1.28e-5))) (* (+ z y) x) (- (* z x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e-23) || !(x <= 1.28e-5)) {
tmp = (z + y) * x;
} else {
tmp = (z * x) - 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 <= (-3.2d-23)) .or. (.not. (x <= 1.28d-5))) then
tmp = (z + y) * x
else
tmp = (z * x) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e-23) || !(x <= 1.28e-5)) {
tmp = (z + y) * x;
} else {
tmp = (z * x) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.2e-23) or not (x <= 1.28e-5): tmp = (z + y) * x else: tmp = (z * x) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.2e-23) || !(x <= 1.28e-5)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(z * x) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.2e-23) || ~((x <= 1.28e-5))) tmp = (z + y) * x; else tmp = (z * x) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.2e-23], N[Not[LessEqual[x, 1.28e-5]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(z * x), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 1.28 \cdot 10^{-5}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot x - z\\
\end{array}
\end{array}
if x < -3.19999999999999976e-23 or 1.2799999999999999e-5 < x Initial program 97.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.9
Applied rewrites98.9%
if -3.19999999999999976e-23 < x < 1.2799999999999999e-5Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.5
Applied rewrites75.5%
Applied rewrites75.5%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.2e-23) (not (<= x 5e-10))) (* (+ z y) x) (* (- x 1.0) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e-23) || !(x <= 5e-10)) {
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 <= (-3.2d-23)) .or. (.not. (x <= 5d-10))) 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 <= -3.2e-23) || !(x <= 5e-10)) {
tmp = (z + y) * x;
} else {
tmp = (x - 1.0) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.2e-23) or not (x <= 5e-10): tmp = (z + y) * x else: tmp = (x - 1.0) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.2e-23) || !(x <= 5e-10)) 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 <= -3.2e-23) || ~((x <= 5e-10))) tmp = (z + y) * x; else tmp = (x - 1.0) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.2e-23], N[Not[LessEqual[x, 5e-10]], $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 -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 5 \cdot 10^{-10}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(x - 1\right) \cdot z\\
\end{array}
\end{array}
if x < -3.19999999999999976e-23 or 5.00000000000000031e-10 < x Initial program 97.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.2
Applied rewrites98.2%
if -3.19999999999999976e-23 < x < 5.00000000000000031e-10Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6475.9
Applied rewrites75.9%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.2e-23) (not (<= x 1.42e-29))) (* (+ z y) x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.2e-23) || !(x <= 1.42e-29)) {
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 <= (-3.2d-23)) .or. (.not. (x <= 1.42d-29))) 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 <= -3.2e-23) || !(x <= 1.42e-29)) {
tmp = (z + y) * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.2e-23) or not (x <= 1.42e-29): tmp = (z + y) * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.2e-23) || !(x <= 1.42e-29)) 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 <= -3.2e-23) || ~((x <= 1.42e-29))) tmp = (z + y) * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.2e-23], N[Not[LessEqual[x, 1.42e-29]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 1.42 \cdot 10^{-29}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -3.19999999999999976e-23 or 1.4200000000000001e-29 < x Initial program 97.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6496.9
Applied rewrites96.9%
if -3.19999999999999976e-23 < x < 1.4200000000000001e-29Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6476.7
Applied rewrites76.7%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.011))) (* z x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.0) || !(x <= 0.011)) {
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 <= (-1.0d0)) .or. (.not. (x <= 0.011d0))) 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 <= -1.0) || !(x <= 0.011)) {
tmp = z * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.0) or not (x <= 0.011): tmp = z * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.011)) tmp = Float64(z * x); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.0) || ~((x <= 0.011))) tmp = z * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.011]], $MachinePrecision]], N[(z * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.011\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1 or 0.010999999999999999 < x Initial program 97.6%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6455.5
Applied rewrites55.5%
Taylor expanded in x around inf
Applied rewrites55.2%
if -1 < x < 0.010999999999999999Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6470.9
Applied rewrites70.9%
Final simplification63.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 98.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6437.7
Applied rewrites37.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 98.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6437.7
Applied rewrites37.7%
Applied rewrites2.6%
herbie shell --seed 2024324
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))