
(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 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
+-commutative98.8%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -6.2e+160)
(* x z)
(if (<= x -2.1e+143)
(* x y)
(if (<= x -1.3e+91)
(* x z)
(if (<= x -7.8e-69)
(* x y)
(if (<= x 1.2e-23) (- z) (if (<= x 7.2e+43) (* x y) (* x z))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e+160) {
tmp = x * z;
} else if (x <= -2.1e+143) {
tmp = x * y;
} else if (x <= -1.3e+91) {
tmp = x * z;
} else if (x <= -7.8e-69) {
tmp = x * y;
} else if (x <= 1.2e-23) {
tmp = -z;
} else if (x <= 7.2e+43) {
tmp = x * y;
} else {
tmp = 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 <= (-6.2d+160)) then
tmp = x * z
else if (x <= (-2.1d+143)) then
tmp = x * y
else if (x <= (-1.3d+91)) then
tmp = x * z
else if (x <= (-7.8d-69)) then
tmp = x * y
else if (x <= 1.2d-23) then
tmp = -z
else if (x <= 7.2d+43) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e+160) {
tmp = x * z;
} else if (x <= -2.1e+143) {
tmp = x * y;
} else if (x <= -1.3e+91) {
tmp = x * z;
} else if (x <= -7.8e-69) {
tmp = x * y;
} else if (x <= 1.2e-23) {
tmp = -z;
} else if (x <= 7.2e+43) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.2e+160: tmp = x * z elif x <= -2.1e+143: tmp = x * y elif x <= -1.3e+91: tmp = x * z elif x <= -7.8e-69: tmp = x * y elif x <= 1.2e-23: tmp = -z elif x <= 7.2e+43: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.2e+160) tmp = Float64(x * z); elseif (x <= -2.1e+143) tmp = Float64(x * y); elseif (x <= -1.3e+91) tmp = Float64(x * z); elseif (x <= -7.8e-69) tmp = Float64(x * y); elseif (x <= 1.2e-23) tmp = Float64(-z); elseif (x <= 7.2e+43) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.2e+160) tmp = x * z; elseif (x <= -2.1e+143) tmp = x * y; elseif (x <= -1.3e+91) tmp = x * z; elseif (x <= -7.8e-69) tmp = x * y; elseif (x <= 1.2e-23) tmp = -z; elseif (x <= 7.2e+43) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.2e+160], N[(x * z), $MachinePrecision], If[LessEqual[x, -2.1e+143], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.3e+91], N[(x * z), $MachinePrecision], If[LessEqual[x, -7.8e-69], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.2e-23], (-z), If[LessEqual[x, 7.2e+43], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{+160}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -2.1 \cdot 10^{+143}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{+91}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -7.8 \cdot 10^{-69}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-23}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{+43}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -6.1999999999999996e160 or -2.09999999999999988e143 < x < -1.3e91 or 7.2000000000000002e43 < x Initial program 97.2%
*-commutative97.2%
sub-neg97.2%
distribute-rgt-in97.2%
metadata-eval97.2%
neg-mul-197.2%
associate-+r+97.2%
unsub-neg97.2%
+-commutative97.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around 0 63.8%
if -6.1999999999999996e160 < x < -2.09999999999999988e143 or -1.3e91 < x < -7.79999999999999961e-69 or 1.19999999999999998e-23 < x < 7.2000000000000002e43Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 99.9%
mul-1-neg99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in x around inf 89.0%
Taylor expanded in y around inf 67.1%
if -7.79999999999999961e-69 < x < 1.19999999999999998e-23Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 75.9%
neg-mul-175.9%
Simplified75.9%
Final simplification69.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.7e-68) (not (<= x 1.2e-24))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-68) || !(x <= 1.2e-24)) {
tmp = x * (z + y);
} 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.7d-68)) .or. (.not. (x <= 1.2d-24))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-68) || !(x <= 1.2e-24)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.7e-68) or not (x <= 1.2e-24): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.7e-68) || !(x <= 1.2e-24)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.7e-68) || ~((x <= 1.2e-24))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.7e-68], N[Not[LessEqual[x, 1.2e-24]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-68} \lor \neg \left(x \leq 1.2 \cdot 10^{-24}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.70000000000000009e-68 or 1.1999999999999999e-24 < x Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 96.5%
if -1.70000000000000009e-68 < x < 1.1999999999999999e-24Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 75.9%
neg-mul-175.9%
Simplified75.9%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e+15) (not (<= x 4.2e-7))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e+15) || !(x <= 4.2e-7)) {
tmp = x * (z + y);
} else {
tmp = (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 ((x <= (-9d+15)) .or. (.not. (x <= 4.2d-7))) then
tmp = x * (z + y)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9e+15) || !(x <= 4.2e-7)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e+15) or not (x <= 4.2e-7): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e+15) || !(x <= 4.2e-7)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9e+15) || ~((x <= 4.2e-7))) tmp = x * (z + y); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e+15], N[Not[LessEqual[x, 4.2e-7]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+15} \lor \neg \left(x \leq 4.2 \cdot 10^{-7}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -9e15 or 4.2e-7 < x Initial program 97.8%
*-commutative97.8%
sub-neg97.8%
distribute-rgt-in97.8%
metadata-eval97.8%
neg-mul-197.8%
associate-+r+97.8%
unsub-neg97.8%
+-commutative97.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -9e15 < x < 4.2e-7Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 99.5%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.7e-68) (not (<= x 7.6e-24))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-68) || !(x <= 7.6e-24)) {
tmp = x * y;
} 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.7d-68)) .or. (.not. (x <= 7.6d-24))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-68) || !(x <= 7.6e-24)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.7e-68) or not (x <= 7.6e-24): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.7e-68) || !(x <= 7.6e-24)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.7e-68) || ~((x <= 7.6e-24))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.7e-68], N[Not[LessEqual[x, 7.6e-24]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-68} \lor \neg \left(x \leq 7.6 \cdot 10^{-24}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.70000000000000009e-68 or 7.60000000000000052e-24 < x Initial program 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 96.5%
Taylor expanded in y around inf 52.7%
if -1.70000000000000009e-68 < x < 7.60000000000000052e-24Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 75.9%
neg-mul-175.9%
Simplified75.9%
Final simplification61.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 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%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
+-commutative98.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 32.9%
neg-mul-132.9%
Simplified32.9%
Final simplification32.9%
herbie shell --seed 2024071
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))