
(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 6 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 97.6%
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 -5.5e+217) (* y x) (if (<= x -14000000.0) (* z x) (if (<= x 7.8e-79) (- z) (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e+217) {
tmp = y * x;
} else if (x <= -14000000.0) {
tmp = z * x;
} else if (x <= 7.8e-79) {
tmp = -z;
} else {
tmp = y * 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 <= (-5.5d+217)) then
tmp = y * x
else if (x <= (-14000000.0d0)) then
tmp = z * x
else if (x <= 7.8d-79) then
tmp = -z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.5e+217) {
tmp = y * x;
} else if (x <= -14000000.0) {
tmp = z * x;
} else if (x <= 7.8e-79) {
tmp = -z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.5e+217: tmp = y * x elif x <= -14000000.0: tmp = z * x elif x <= 7.8e-79: tmp = -z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.5e+217) tmp = Float64(y * x); elseif (x <= -14000000.0) tmp = Float64(z * x); elseif (x <= 7.8e-79) tmp = Float64(-z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.5e+217) tmp = y * x; elseif (x <= -14000000.0) tmp = z * x; elseif (x <= 7.8e-79) tmp = -z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.5e+217], N[(y * x), $MachinePrecision], If[LessEqual[x, -14000000.0], N[(z * x), $MachinePrecision], If[LessEqual[x, 7.8e-79], (-z), N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+217}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -14000000:\\
\;\;\;\;z \cdot x\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{-79}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -5.5e217 or 7.80000000000000011e-79 < x Initial program 96.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f646.9
Applied rewrites6.9%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6459.3
Applied rewrites59.3%
if -5.5e217 < x < -1.4e7Initial program 93.9%
Taylor expanded in y around 0
distribute-rgt-out--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6467.4
Applied rewrites67.4%
Taylor expanded in x around inf
Applied rewrites67.4%
if -1.4e7 < x < 7.80000000000000011e-79Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6479.8
Applied rewrites79.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.8e-29) (not (<= x 7.8e-79))) (* (+ z y) x) (* (+ -1.0 x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e-29) || !(x <= 7.8e-79)) {
tmp = (z + y) * x;
} else {
tmp = (-1.0 + 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 <= (-9.8d-29)) .or. (.not. (x <= 7.8d-79))) then
tmp = (z + y) * x
else
tmp = ((-1.0d0) + x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e-29) || !(x <= 7.8e-79)) {
tmp = (z + y) * x;
} else {
tmp = (-1.0 + x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.8e-29) or not (x <= 7.8e-79): tmp = (z + y) * x else: tmp = (-1.0 + x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.8e-29) || !(x <= 7.8e-79)) tmp = Float64(Float64(z + y) * x); else tmp = Float64(Float64(-1.0 + x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.8e-29) || ~((x <= 7.8e-79))) tmp = (z + y) * x; else tmp = (-1.0 + x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.8e-29], N[Not[LessEqual[x, 7.8e-79]], $MachinePrecision]], N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{-29} \lor \neg \left(x \leq 7.8 \cdot 10^{-79}\right):\\
\;\;\;\;\left(z + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\end{array}
\end{array}
if x < -9.7999999999999997e-29 or 7.80000000000000011e-79 < x Initial program 95.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6494.0
Applied rewrites94.0%
if -9.7999999999999997e-29 < x < 7.80000000000000011e-79Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6484.0
Applied rewrites84.0%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.5e-142) (not (<= z 1.75e-113))) (* (+ -1.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e-142) || !(z <= 1.75e-113)) {
tmp = (-1.0 + x) * z;
} else {
tmp = y * 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 ((z <= (-3.5d-142)) .or. (.not. (z <= 1.75d-113))) then
tmp = ((-1.0d0) + x) * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e-142) || !(z <= 1.75e-113)) {
tmp = (-1.0 + x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.5e-142) or not (z <= 1.75e-113): tmp = (-1.0 + x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.5e-142) || !(z <= 1.75e-113)) tmp = Float64(Float64(-1.0 + x) * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.5e-142) || ~((z <= 1.75e-113))) tmp = (-1.0 + x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.5e-142], N[Not[LessEqual[z, 1.75e-113]], $MachinePrecision]], N[(N[(-1.0 + x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{-142} \lor \neg \left(z \leq 1.75 \cdot 10^{-113}\right):\\
\;\;\;\;\left(-1 + x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -3.50000000000000015e-142 or 1.75000000000000014e-113 < z Initial program 96.6%
Taylor expanded in y around 0
distribute-rgt-out--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6484.0
Applied rewrites84.0%
if -3.50000000000000015e-142 < z < 1.75000000000000014e-113Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6420.6
Applied rewrites20.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6474.8
Applied rewrites74.8%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -14000000.0) (not (<= x 1.0))) (* z x) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -14000000.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 <= (-14000000.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 <= -14000000.0) || !(x <= 1.0)) {
tmp = z * x;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -14000000.0) or not (x <= 1.0): tmp = z * x else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -14000000.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 <= -14000000.0) || ~((x <= 1.0))) tmp = z * x; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -14000000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -14000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.4e7 or 1 < x Initial program 95.1%
Taylor expanded in y around 0
distribute-rgt-out--N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
distribute-rgt-outN/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6453.5
Applied rewrites53.5%
Taylor expanded in x around inf
Applied rewrites52.9%
if -1.4e7 < x < 1Initial program 100.0%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6477.1
Applied rewrites77.1%
Final simplification65.6%
(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 97.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6441.7
Applied rewrites41.7%
herbie shell --seed 2024339
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))